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 { useState } from "preact/hooks";
|
||||||
import AddLeaseDialog from "./AddLeaseDialog.tsx";
|
import AddLeaseDialog from "./AddLeaseDialog.tsx";
|
||||||
import { Lease, Property } from "../../db/interfaces.ts";
|
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[]) {
|
export function PopAddLeaseDialog(leases: Lease[], properties: Property[]) {
|
||||||
const [popup, setPopup] = useState<
|
const [popup, setPopup] = useState<
|
||||||
{
|
{
|
||||||
propertyId: string;
|
propertyId: string | null;
|
||||||
popupKey: number;
|
popupKey: number;
|
||||||
resolve: (value: boolean) => void;
|
resolve: (value: boolean) => void;
|
||||||
} | null
|
} | null
|
||||||
@ -25,7 +24,7 @@ export function PopAddLeaseDialog(leases: Lease[], properties: Property[]) {
|
|||||||
|
|
||||||
// Show the popup and return a Promise for the answer
|
// Show the popup and return a Promise for the answer
|
||||||
const popAddLease = (
|
const popAddLease = (
|
||||||
propertyId: string,
|
propertyId?: string,
|
||||||
popupKey: number,
|
popupKey: number,
|
||||||
): Promise<boolean> => {
|
): Promise<boolean> => {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
@ -36,7 +35,7 @@ export function PopAddLeaseDialog(leases: Lease[], properties: Property[]) {
|
|||||||
// Render the popup if needed
|
// Render the popup if needed
|
||||||
const popupAddLeaseDialog = popup
|
const popupAddLeaseDialog = popup
|
||||||
? (() => {
|
? (() => {
|
||||||
const { title, address, price } = getPropertyInfo(popup.propertyId);
|
const { title, address, price } = getPropertyInfo(popup.propertyId || "");
|
||||||
return (
|
return (
|
||||||
<AddLeaseDialog
|
<AddLeaseDialog
|
||||||
leases={leases}
|
leases={leases}
|
||||||
@ -54,5 +53,55 @@ export function PopAddLeaseDialog(leases: Lease[], properties: Property[]) {
|
|||||||
})()
|
})()
|
||||||
: null;
|
: 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