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 => { return new Promise((resolve) => { setPopup({ question, resolve }); }); }; // Render the popup if needed const popupAddRentalDialog = popup ? ( setPopup(null)} /> ) : null; return [popAddRental, popupAddRentalDialog] as const; }