Path: blob/master/src/packages/frontend/app/popconfirm-modal.tsx
1496 views
/*1Easily show a global popconfirm modal at any point in cocalc by doing23await redux.getActions("page").popconfirm(...open, title, cancelText, okText, description )45It will return true on OK and false on Cancel.67One twist is that the OK button is focused automatically, so the user can8just hit enter to select OK, without having to use the mouse.9*/1011import { Modal } from "antd";12import {13useActions,14useEffect,15useRedux,16useRef,17} from "@cocalc/frontend/app-framework";1819// Ensure the billing Actions and Store are created, which are needed for purchases, etc., to work...20import "@cocalc/frontend/billing/actions";2122export default function PopconfirmModal({}) {23const actions = useActions("page");24const popconfirm = useRedux("page", "popconfirm")?.toJS() ?? {};2526const handleCancel = () => {27actions.setState({ popconfirm: { open: false, ok: false } });28};29const handleOk = () => {30actions.setState({ popconfirm: { open: false, ok: true } });31};3233const okButtonRef = useRef(undefined);34useEffect(() => {35if (popconfirm.open) {36// @ts-ignore37setTimeout(() => okButtonRef.current?.focus(), 1);38}39}, [popconfirm.open]);4041// destroyOnHidden so values in quota input, etc. get updated42return (43<Modal44key="app-modal"45width={"600px"}46destroyOnHidden47open={popconfirm.open}48title={popconfirm.title}49onCancel={handleCancel}50onOk={handleOk}51cancelText={popconfirm.cancelText ?? "No"}52okText={popconfirm.okText ?? "Yes"}53okButtonProps={{54// @ts-ignore55ref: okButtonRef,56}}57>58{popconfirm.description}59</Modal>60);61}626364