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

32 lines
810 B
TypeScript

import { useState } from "preact/hooks";
import AddRentalDialog from "./AddRentalDialog.tsx";
import { Property } from "../../db/interfaces.ts";
export function PopAddRentalDialog(properties: Property[]) {
const [popup, setPopup] = useState<
{
question: string;
resolve: (value: boolean) => void;
} | null
>(null);
// Show the popup and return a Promise for the answer
const popAddRental = (question: string): Promise<boolean> => {
return new Promise((resolve) => {
setPopup({ question, resolve });
});
};
// Render the popup if needed
const popupAddRentalDialog = popup
? (
<AddRentalDialog
properties={properties}
onClose={() => setPopup(null)}
/>
)
: null;
return [popAddRental, popupAddRentalDialog] as const;
}