integratedhub/islands/dialogs/PopAddObligationDialog.tsx
2026-01-20 09:02:26 -06:00

43 lines
1.1 KiB
TypeScript

import { useState } from "preact/hooks";
import AddObligationDialog from "./AddObligationDialog.tsx";
interface PopAddObligationDialogOptions {
userId?: string;
defaultOpen?: boolean;
}
interface PopupController {
resolve?: (value: boolean) => void;
}
export function PopAddObligationDialog(
options: PopAddObligationDialogOptions = {},
) {
const [popup, setPopup] = useState<PopupController | null>(() => {
return options.defaultOpen ? { resolve: () => {} } : null;
});
// Show the popup and return a Promise for the answer
const popAddObligation = (): Promise<boolean> => {
return new Promise((resolve) => {
setPopup({ resolve });
});
};
// Render the popup if needed
const popupAddObligationDialog = popup
? (
<AddObligationDialog
onClose={() => {
globalThis.location.href = "/calendar/budget-obligations?modal=off";
// popup?.resolve?.(false);
// setPopup(null);
}}
userId={options.userId}
/>
)
: null;
return [popAddObligation, popupAddObligationDialog] as const;
}