From 1dc4e08b80f9fac0441cdf598fb5b9d33293ee13 Mon Sep 17 00:00:00 2001 From: Alfredo Bonilla Date: Sun, 23 Feb 2025 14:05:54 -0600 Subject: [PATCH] feat: refactor escrow dialog hooks --- .../ui/dialogs/EditMilestonesDialog.tsx | 9 +- .../escrow/ui/dialogs/EscrowDetailDialog.tsx | 294 ++++++++---------- .../hooks/escrow-detail-dialog.hook.ts | 76 +++-- .../dialogs/hooks/use-escrow-dialogs.hook.ts | 66 ++++ src/components/ui/breadcrumb.tsx | 6 +- 5 files changed, 247 insertions(+), 204 deletions(-) create mode 100644 src/components/modules/escrow/ui/dialogs/hooks/use-escrow-dialogs.hook.ts diff --git a/src/components/modules/escrow/ui/dialogs/EditMilestonesDialog.tsx b/src/components/modules/escrow/ui/dialogs/EditMilestonesDialog.tsx index 0c4a9d7b..10e1d36b 100644 --- a/src/components/modules/escrow/ui/dialogs/EditMilestonesDialog.tsx +++ b/src/components/modules/escrow/ui/dialogs/EditMilestonesDialog.tsx @@ -68,8 +68,11 @@ const EditMilestonesDialog = ({ {milestones.map((milestone, index) => ( - <> -
+
+
{milestone.flag ? ( Approved ) : ( @@ -117,7 +120,7 @@ const EditMilestonesDialog = ({ Add Item )} - +
))}
diff --git a/src/components/modules/escrow/ui/dialogs/EscrowDetailDialog.tsx b/src/components/modules/escrow/ui/dialogs/EscrowDetailDialog.tsx index c2760009..bd30235f 100644 --- a/src/components/modules/escrow/ui/dialogs/EscrowDetailDialog.tsx +++ b/src/components/modules/escrow/ui/dialogs/EscrowDetailDialog.tsx @@ -10,7 +10,7 @@ import { } from "@/components/ui/dialog"; import { Input } from "@/components/ui/input"; import useEscrowDetailDialog from "./hooks/escrow-detail-dialog.hook"; -import { Escrow } from "@/@types/escrow.entity"; +import type { Escrow } from "@/@types/escrow.entity"; import { Card, CardContent } from "@/components/ui/card"; import { cn } from "@/lib/utils"; import { useFormatUtils } from "@/utils/hook/format.hook"; @@ -38,13 +38,13 @@ import { Handshake, Wallet, } from "lucide-react"; -import SkeletonMilestones from "./utils/SkeletonMilestones"; import EditMilestonesDialog from "./EditMilestonesDialog"; import { SuccessReleaseDialog, SuccessResolveDisputeDialog, } from "./SuccessDialog"; import { toast } from "@/hooks/toast.hook"; +import { useEscrowDialogs } from "./hooks/use-escrow-dialogs.hook"; interface EscrowDetailDialogProps { isDialogOpen: boolean; @@ -58,6 +58,8 @@ const EscrowDetailDialog = ({ setSelectedEscrow, }: EscrowDetailDialogProps) => { const selectedEscrow = useGlobalBoundedStore((state) => state.selectedEscrow); + const dialogStates = useEscrowDialogs(); + const activeTab = useEscrowBoundedStore((state) => state.activeTab); const { handleClose, @@ -72,64 +74,13 @@ const EscrowDetailDialog = ({ const { distributeEscrowEarningsSubmit } = useDistributeEarningsEscrowDialogHook(); - - const setIsResolveDisputeDialogOpen = useEscrowBoundedStore( - (state) => state.setIsResolveDisputeDialogOpen, - ); - const { handleOpen } = useResolveDisputeEscrowDialogHook({ - setIsResolveDisputeDialogOpen, + setIsResolveDisputeDialogOpen: dialogStates.resolveDispute.setIsOpen, }); - const { changeMilestoneStatusSubmit } = useChangeStatusEscrowDialogHook(); const { startDisputeSubmit } = useStartDisputeEscrowDialogHook(); const { changeMilestoneFlagSubmit } = useChangeFlagEscrowDialogHook(); - const isSecondDialogOpen = useEscrowBoundedStore( - (state) => state.isSecondDialogOpen, - ); - const setIsSecondDialogOpen = useEscrowBoundedStore( - (state) => state.setIsSecondDialogOpen, - ); - const setIsQRDialogOpen = useEscrowBoundedStore( - (state) => state.setIsQRDialogOpen, - ); - const isQRDialogOpen = useEscrowBoundedStore((state) => state.isQRDialogOpen); - - const isChangingStatus = useEscrowBoundedStore( - (state) => state.isChangingStatus, - ); - - const isStartingDispute = useEscrowBoundedStore( - (state) => state.isStartingDispute, - ); - - const isResolveDisputeDialogOpen = useEscrowBoundedStore( - (state) => state.isResolveDisputeDialogOpen, - ); - - const setIsEditMilestoneDialogOpen = useEscrowBoundedStore( - (state) => state.setIsEditMilestoneDialogOpen, - ); - const isEditMilestoneDialogOpen = useEscrowBoundedStore( - (state) => state.isEditMilestoneDialogOpen, - ); - const isSuccessReleaseDialogOpen = useEscrowBoundedStore( - (state) => state.isSuccessReleaseDialogOpen, - ); - const setIsSuccessReleaseDialogOpen = useEscrowBoundedStore( - (state) => state.setIsSuccessReleaseDialogOpen, - ); - - const isSuccessResolveDisputeDialogOpen = useEscrowBoundedStore( - (state) => state.isSuccessResolveDisputeDialogOpen, - ); - const setIsSuccessResolveDisputeDialogOpen = useEscrowBoundedStore( - (state) => state.setIsSuccessResolveDisputeDialogOpen, - ); - - const activeTab = useEscrowBoundedStore((state) => state.activeTab); - const { formatAddress, formatText, formatDollar, formatDateFromFirebase } = useFormatUtils(); const { copyText, copiedKeyId } = useCopyUtils(); @@ -196,7 +147,9 @@ const EscrowDetailDialog = ({ -

+
+ {formatAddress(selectedEscrow.contractId)} + +
- + )} {userRolesInEscrow.includes("disputeResolver") && @@ -395,79 +365,73 @@ const EscrowDetailDialog = ({ {/* Milestones */}
- {isChangingStatus || isStartingDispute ? ( - - ) : ( -
- - {selectedEscrow.milestones.map((milestone, index) => ( -
- {milestone.flag ? ( - - Approved - - ) : ( - + Milestones + + + {selectedEscrow.milestones.map( + (milestone, milestoneIndex) => ( +
+ {milestone.flag ? ( + Approved + ) : ( + + {milestone.status} + + )} + + + + {userRolesInEscrow.includes("serviceProvider") && + activeTab === "serviceProvider" && + milestone.status !== "completed" && + !milestone.flag && ( + )} - - - {userRolesInEscrow.includes("serviceProvider") && - activeTab === "serviceProvider" && - milestone.status !== "completed" && - !milestone.flag && ( - - )} - - {userRolesInEscrow.includes("approver") && - activeTab === "approver" && - milestone.status === "completed" && - !milestone.flag && ( - - )} -
- ))} - - -
+ {userRolesInEscrow.includes("approver") && + activeTab === "approver" && + milestone.status === "completed" && + !milestone.flag && ( + + )} +
+ ), )} + +
@@ -499,7 +463,7 @@ const EscrowDetailDialog = ({