import React, { PropsWithChildren } from "react"; import { AccommodationCalendarURL } from "../../../api/accommodations/AccommodationsCalendarURLApi"; import { InstallCalendarDialog } from "../../../dialogs/accommodations/InstallCalendarDialog"; type DialogContext = (cal: AccommodationCalendarURL) => Promise; const DialogContextK = React.createContext(null); export function InstallCalendarDialogProvider( p: PropsWithChildren ): React.ReactElement { const [cal, setCal] = React.useState(); const cb = React.useRef void)>(null); const handleClose = () => { setCal(undefined); if (cb.current !== null) cb.current(); cb.current = null; }; const hook: DialogContext = (c) => { setCal(c); return new Promise((res) => { cb.current = res; }); }; return ( <> {p.children} {cal && } ); } export function useInstallCalendarDialog(): DialogContext { return React.useContext(DialogContextK)!; }