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

41 lines
1.0 KiB
TypeScript

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<PopupController | null>(() => {
return options.defaultOpen ? { resolve: () => {} } : null;
});
// Show the popup and return a Promise for the answer
const popAddIncome = (): Promise<boolean> => {
return new Promise((resolve) => {
setPopup({ resolve });
});
};
// Render the popup if needed
const popupAddIncomeDialog = popup
? (
<AddIncomeDialog
onClose={() => {
globalThis.location.href = "/calendar/every-income?modal=off";
// popup?.resolve?.(false);
// setPopup(null);
}}
userId={options.userId}
/>
)
: null;
return [popAddIncome, popupAddIncomeDialog] as const;
}