import { useState } from "preact/hooks"; import AddIncomeDialog from "./AddIncomeDialog.tsx"; interface PopAddIncomeDialogOptions { userId?: string; defaultOpen?: boolean; } interface PopupController { resolve?: (value: boolean) => void; } export function PopAddIncomeDialog(options: PopAddIncomeDialogOptions = {}) { const [popup, setPopup] = useState(() => { return options.defaultOpen ? { resolve: () => {} } : null; }); // Show the popup and return a Promise for the answer const popAddIncome = (): Promise => { return new Promise((resolve) => { setPopup({ resolve }); }); }; // Render the popup if needed const popupAddIncomeDialog = popup ? ( { globalThis.location.href = "/calendar/every-income?modal=off"; // popup?.resolve?.(false); // setPopup(null); }} userId={options.userId} /> ) : null; return [popAddIncome, popupAddIncomeDialog] as const; }