From 6541812346d844977d245d1578c4e4338d67259d Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Sat, 25 Oct 2025 12:18:21 +0530 Subject: [PATCH] Migrated workspace deletion flow to offline pattern B --- src/pages/workspace/WorkspaceOverviewPage.tsx | 22 ++++--------- src/pages/workspace/WorkspacesListPage.tsx | 31 ++++++------------- 2 files changed, 16 insertions(+), 37 deletions(-) diff --git a/src/pages/workspace/WorkspaceOverviewPage.tsx b/src/pages/workspace/WorkspaceOverviewPage.tsx index 32f721083be9..1f69814ecb21 100644 --- a/src/pages/workspace/WorkspaceOverviewPage.tsx +++ b/src/pages/workspace/WorkspaceOverviewPage.tsx @@ -168,7 +168,6 @@ function WorkspaceOverviewPage({policyDraft, policy: policyProp, route}: Workspa const prevIsPendingDelete = usePrevious(isPendingDelete); const [isDeleteWorkspaceErrorModalOpen, setIsDeleteWorkspaceErrorModalOpen] = useState(false); const policyLastErrorMessage = getLatestErrorMessage(policy); - const [shouldShowOfflineModal, setShouldShowOfflineModal] = useState(false); const fetchPolicyData = useCallback(() => { if (policyDraft?.id) { @@ -206,12 +205,8 @@ function WorkspaceOverviewPage({policyDraft, policy: policyProp, route}: Workspa const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false); const continueDeleteWorkspace = useCallback(() => { - if (isOffline) { - setShouldShowOfflineModal(true); - return; - } setIsDeleteModalOpen(true); - }, [isOffline]); + }, []); const {setIsDeletingPaidWorkspace, isLoadingBill}: {setIsDeletingPaidWorkspace: (value: boolean) => void; isLoadingBill: boolean | undefined} = usePayAndDowngrade(continueDeleteWorkspace); @@ -224,7 +219,11 @@ function WorkspaceOverviewPage({policyDraft, policy: policyProp, route}: Workspa } deleteWorkspace(policy.id, policyName, lastAccessedWorkspacePolicyID, defaultCardFeeds, reportsToArchive, transactionViolations, reimbursementAccountError, lastPaymentMethod); - }, [policy?.id, policyName, lastAccessedWorkspacePolicyID, defaultCardFeeds, reportsToArchive, transactionViolations, reimbursementAccountError, lastPaymentMethod]); + if (isOffline) { + setIsDeleteModalOpen(false); + goBackFromInvalidPolicy(); + } + }, [policy?.id, policyName, lastAccessedWorkspacePolicyID, defaultCardFeeds, reportsToArchive, transactionViolations, reimbursementAccountError, lastPaymentMethod, isOffline]); const hideDeleteWorkspaceErrorModal = () => { setIsDeleteWorkspaceErrorModalOpen(false); @@ -567,15 +566,6 @@ function WorkspaceOverviewPage({policyDraft, policy: policyProp, route}: Workspa shouldShowCancelButton={false} success={false} /> - setShouldShowOfflineModal(false)} - onCancel={() => setShouldShowOfflineModal(false)} - confirmText={translate('common.buttonConfirm')} - prompt={translate('common.offlinePrompt')} - shouldShowCancelButton={false} - /> )} diff --git a/src/pages/workspace/WorkspacesListPage.tsx b/src/pages/workspace/WorkspacesListPage.tsx index a9aa479662b8..63f0240222c8 100755 --- a/src/pages/workspace/WorkspacesListPage.tsx +++ b/src/pages/workspace/WorkspacesListPage.tsx @@ -144,20 +144,12 @@ function WorkspacesListPage() { const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false); const [isDeleteWorkspaceErrorModalOpen, setIsDeleteWorkspaceErrorModalOpen] = useState(false); - const [shouldShowOfflineModal, setShouldShowOfflineModal] = useState(false); const [policyIDToDelete, setPolicyIDToDelete] = useState(); // The workspace was deleted in this page const [policyNameToDelete, setPolicyNameToDelete] = useState(); const continueDeleteWorkspace = useCallback(() => { - if (isOffline) { - setPolicyIDToDelete(undefined); - setPolicyNameToDelete(undefined); - setShouldShowOfflineModal(true); - return; - } - setIsDeleteModalOpen(true); - }, [isOffline]); + }, []); const {reportsToArchive, transactionViolations} = useTransactionViolationOfWorkspace(policyIDToDelete); const {setIsDeletingPaidWorkspace, isLoadingBill}: {setIsDeletingPaidWorkspace: (value: boolean) => void; isLoadingBill: boolean | undefined} = usePayAndDowngrade(continueDeleteWorkspace); @@ -206,6 +198,11 @@ function WorkspacesListPage() { reimbursementAccountError, lastPaymentMethod, ); + if (isOffline) { + setIsDeleteModalOpen(false); + setPolicyIDToDelete(undefined); + setPolicyNameToDelete(undefined); + } }; const hideDeleteWorkspaceErrorModal = () => { @@ -244,7 +241,7 @@ function WorkspacesListPage() { ); useEffect(() => { - if (!prevIsPendingDelete || isPendingDelete) { + if (!prevIsPendingDelete || isPendingDelete || !policyIDToDelete) { return; } setIsDeleteModalOpen(false); @@ -252,7 +249,7 @@ function WorkspacesListPage() { return; } setIsDeleteWorkspaceErrorModalOpen(true); - }, [isPendingDelete, prevIsPendingDelete, isFocused, policyToDeleteLatestErrorMessage]); + }, [isPendingDelete, prevIsPendingDelete, isFocused, policyToDeleteLatestErrorMessage, policyIDToDelete]); /** * Gets the menu item for each workspace @@ -344,7 +341,7 @@ function WorkspacesListPage() { onClose={item.dismissError} errors={item.errors} style={styles.mb2} - shouldShowErrorMessages={false} + shouldShowErrorMessages={item.policyID !== policyIDToDelete} shouldHideOnDelete={false} > - setShouldShowOfflineModal(false)} - onCancel={() => setShouldShowOfflineModal(false)} - confirmText={translate('common.buttonConfirm')} - prompt={translate('common.offlinePrompt')} - shouldShowCancelButton={false} - /> {shouldDisplayLHB && } );