Apply patch [skip ci]
This commit is contained in:
parent
c7d960d364
commit
0c1242ffeb
@ -1,4 +1,3 @@
|
||||
// islands/AsyncYesNoPop.ts
|
||||
import { useState } from "preact/hooks";
|
||||
import AddLeaseDialog from "./AddLeaseDialog.tsx";
|
||||
import { Lease, Property } from "../../db/interfaces.ts";
|
||||
@ -6,7 +5,7 @@ import { Lease, Property } from "../../db/interfaces.ts";
|
||||
export function PopAddLeaseDialog(leases: Lease[], properties: Property[]) {
|
||||
const [popup, setPopup] = useState<
|
||||
{
|
||||
propertyId: string;
|
||||
propertyId: string | null;
|
||||
popupKey: number;
|
||||
resolve: (value: boolean) => void;
|
||||
} | null
|
||||
@ -25,7 +24,7 @@ export function PopAddLeaseDialog(leases: Lease[], properties: Property[]) {
|
||||
|
||||
// Show the popup and return a Promise for the answer
|
||||
const popAddLease = (
|
||||
propertyId: string,
|
||||
propertyId?: string,
|
||||
popupKey: number,
|
||||
): Promise<boolean> => {
|
||||
return new Promise((resolve) => {
|
||||
@ -36,7 +35,7 @@ export function PopAddLeaseDialog(leases: Lease[], properties: Property[]) {
|
||||
// Render the popup if needed
|
||||
const popupAddLeaseDialog = popup
|
||||
? (() => {
|
||||
const { title, address, price } = getPropertyInfo(popup.propertyId);
|
||||
const { title, address, price } = getPropertyInfo(popup.propertyId || "");
|
||||
return (
|
||||
<AddLeaseDialog
|
||||
leases={leases}
|
||||
@ -54,5 +53,55 @@ export function PopAddLeaseDialog(leases: Lease[], properties: Property[]) {
|
||||
})()
|
||||
: null;
|
||||
|
||||
return [popAddLease, popupAddLeaseDialog] as const;
|
||||
// Render property selection dialog if no propertyId provided
|
||||
const propertySelectionDialog = popup && !popup.propertyId
|
||||
? (() => {
|
||||
const [selectedPropertyId, setSelectedPropertyId] = useState("");
|
||||
|
||||
return (
|
||||
<div class="fixed inset-0 flex items-center justify-center bg-black bg-opacity-30 z-50">
|
||||
<div class="bg-white p-6 rounded shadow-lg w-full max-w-md space-y-4">
|
||||
<h3 class="text-xl font-bold mb-2">Select Property</h3>
|
||||
<select
|
||||
class="border p-2 rounded w-full"
|
||||
value={selectedPropertyId}
|
||||
onInput={(e) => setSelectedPropertyId(e.currentTarget.value)}
|
||||
>
|
||||
<option value="">-- Select a property --</option>
|
||||
{properties.map((p) => (
|
||||
<option key={p.id} value={p.id}>
|
||||
{p.title} - {p.address_1}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<div class="flex justify-end gap-2 mt-4">
|
||||
<button
|
||||
type="button"
|
||||
class="px-4 py-2 rounded border"
|
||||
onClick={() => {
|
||||
popup.resolve(false);
|
||||
setPopup(null);
|
||||
}}
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="px-4 py-2 rounded bg-blue-600 text-white"
|
||||
disabled={!selectedPropertyId}
|
||||
onClick={() => {
|
||||
setPopup({ ...popup, propertyId: selectedPropertyId });
|
||||
}}
|
||||
>
|
||||
Continue
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})()
|
||||
: null;
|
||||
|
||||
return [popAddLease, popupAddLeaseDialog || propertySelectionDialog] as const;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user