Apply patch [skip ci]
This commit is contained in:
parent
34c04a4ef4
commit
e1c3a82672
@ -11,6 +11,7 @@ export function PopAddLeaseDialog(leases: Lease[], properties: Property[]) {
|
|||||||
} | null
|
} | null
|
||||||
>(null);
|
>(null);
|
||||||
const [selectedPropertyId, setSelectedPropertyId] = useState("");
|
const [selectedPropertyId, setSelectedPropertyId] = useState("");
|
||||||
|
const [showPropertySelection, setShowPropertySelection] = useState(false);
|
||||||
|
|
||||||
function getPropertyInfo(propertyId: string) {
|
function getPropertyInfo(propertyId: string) {
|
||||||
const property = properties.find((p) => p.id === propertyId);
|
const property = properties.find((p) => p.id === propertyId);
|
||||||
@ -26,17 +27,22 @@ 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) => {
|
||||||
setPopup({ propertyId, popupKey, resolve });
|
if (propertyId) {
|
||||||
|
setPopup({ propertyId, popupKey: popupKey || 0, resolve });
|
||||||
|
} else {
|
||||||
|
setShowPropertySelection(true);
|
||||||
|
setPopup({ propertyId: null, popupKey: popupKey || 0, resolve });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Render the popup if needed
|
// Render the popup if needed
|
||||||
const popupAddLeaseDialog = popup
|
const popupAddLeaseDialog = popup && popup.propertyId
|
||||||
? (() => {
|
? (() => {
|
||||||
const { title, address, price } = getPropertyInfo(popup.propertyId || "");
|
const { title, address, price } = getPropertyInfo(popup.propertyId);
|
||||||
return (
|
return (
|
||||||
<AddLeaseDialog
|
<AddLeaseDialog
|
||||||
leases={leases}
|
leases={leases}
|
||||||
@ -48,6 +54,8 @@ export function PopAddLeaseDialog(leases: Lease[], properties: Property[]) {
|
|||||||
onClose={() => {
|
onClose={() => {
|
||||||
popup.resolve(false);
|
popup.resolve(false);
|
||||||
setPopup(null);
|
setPopup(null);
|
||||||
|
setShowPropertySelection(false);
|
||||||
|
setSelectedPropertyId("");
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
@ -55,7 +63,7 @@ export function PopAddLeaseDialog(leases: Lease[], properties: Property[]) {
|
|||||||
: null;
|
: null;
|
||||||
|
|
||||||
// Render property selection dialog if no propertyId provided
|
// Render property selection dialog if no propertyId provided
|
||||||
const propertySelectionDialog = popup && !popup.propertyId
|
const propertySelectionDialog = showPropertySelection
|
||||||
? (() => {
|
? (() => {
|
||||||
return (
|
return (
|
||||||
<div class="fixed inset-0 flex items-center justify-center bg-black bg-opacity-30 z-50">
|
<div class="fixed inset-0 flex items-center justify-center bg-black bg-opacity-30 z-50">
|
||||||
@ -78,8 +86,10 @@ export function PopAddLeaseDialog(leases: Lease[], properties: Property[]) {
|
|||||||
type="button"
|
type="button"
|
||||||
class="px-4 py-2 rounded border"
|
class="px-4 py-2 rounded border"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
popup.resolve(false);
|
if (popup) popup.resolve(false);
|
||||||
setPopup(null);
|
setPopup(null);
|
||||||
|
setShowPropertySelection(false);
|
||||||
|
setSelectedPropertyId("");
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Cancel
|
Cancel
|
||||||
@ -89,7 +99,8 @@ export function PopAddLeaseDialog(leases: Lease[], properties: Property[]) {
|
|||||||
class="px-4 py-2 rounded bg-blue-600 text-white"
|
class="px-4 py-2 rounded bg-blue-600 text-white"
|
||||||
disabled={!selectedPropertyId}
|
disabled={!selectedPropertyId}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setPopup({ ...popup, propertyId: selectedPropertyId });
|
setPopup({ ...popup!, propertyId: selectedPropertyId });
|
||||||
|
setShowPropertySelection(false);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Continue
|
Continue
|
||||||
@ -103,5 +114,3 @@ export function PopAddLeaseDialog(leases: Lease[], properties: Property[]) {
|
|||||||
|
|
||||||
return [popAddLease, popupAddLeaseDialog || propertySelectionDialog] as const;
|
return [popAddLease, popupAddLeaseDialog || propertySelectionDialog] as const;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user