import { useState } from "preact/hooks"; import AddPaymentMethodDialog from "./AddPaymentMethodDialog.tsx"; interface PopAddPaymentMethodDialogOptions { userId?: string; defaultOpen?: boolean; } interface PopupController { resolve?: (value: boolean) => void; } export function PopAddPaymentMethodDialog( options: PopAddPaymentMethodDialogOptions = {}, ) { const [popup, setPopup] = useState(() => { return options.defaultOpen ? { resolve: () => {} } : null; }); // Show the popup and return a Promise for the answer const popAddPaymentMethod = (): Promise => { return new Promise((resolve) => { setPopup({ resolve }); }); }; // Render the popup if needed const popupAddPaymentMethodDialog = popup ? ( { globalThis.location.href = "/tenant/payment-methods?modal=off"; }} userId={options.userId} /> ) : null; return [popAddPaymentMethod, popupAddPaymentMethodDialog] as const; }