Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 6 additions & 16 deletions src/pages/workspace/WorkspaceOverviewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -567,15 +566,6 @@ function WorkspaceOverviewPage({policyDraft, policy: policyProp, route}: Workspa
shouldShowCancelButton={false}
success={false}
/>
<ConfirmModal
title={translate('common.youAppearToBeOffline')}
isVisible={shouldShowOfflineModal}
onConfirm={() => setShouldShowOfflineModal(false)}
onCancel={() => setShouldShowOfflineModal(false)}
confirmText={translate('common.buttonConfirm')}
prompt={translate('common.offlinePrompt')}
shouldShowCancelButton={false}
/>
</View>
)}
</WorkspacePageWithSections>
Expand Down
31 changes: 10 additions & 21 deletions src/pages/workspace/WorkspacesListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>();
// The workspace was deleted in this page
const [policyNameToDelete, setPolicyNameToDelete] = useState<string>();
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);
Expand Down Expand Up @@ -206,6 +198,11 @@ function WorkspacesListPage() {
reimbursementAccountError,
lastPaymentMethod,
);
if (isOffline) {
setIsDeleteModalOpen(false);
setPolicyIDToDelete(undefined);
setPolicyNameToDelete(undefined);
}
};

const hideDeleteWorkspaceErrorModal = () => {
Expand Down Expand Up @@ -244,15 +241,15 @@ function WorkspacesListPage() {
);

useEffect(() => {
if (!prevIsPendingDelete || isPendingDelete) {
if (!prevIsPendingDelete || isPendingDelete || !policyIDToDelete) {
return;
}
setIsDeleteModalOpen(false);
if (!isFocused || !policyToDeleteLatestErrorMessage) {
return;
}
setIsDeleteWorkspaceErrorModalOpen(true);
}, [isPendingDelete, prevIsPendingDelete, isFocused, policyToDeleteLatestErrorMessage]);
}, [isPendingDelete, prevIsPendingDelete, isFocused, policyToDeleteLatestErrorMessage, policyIDToDelete]);

/**
* Gets the menu item for each workspace
Expand Down Expand Up @@ -344,7 +341,7 @@ function WorkspacesListPage() {
onClose={item.dismissError}
errors={item.errors}
style={styles.mb2}
shouldShowErrorMessages={false}
shouldShowErrorMessages={item.policyID !== policyIDToDelete}
shouldHideOnDelete={false}
>
<PressableWithoutFeedback
Expand Down Expand Up @@ -397,6 +394,7 @@ function WorkspacesListPage() {
resetLoadingSpinnerIconIndex,
continueDeleteWorkspace,
isRestrictedToPreferredPolicy,
policyIDToDelete,
preferredPolicyID,
],
);
Expand Down Expand Up @@ -750,15 +748,6 @@ function WorkspacesListPage() {
shouldShowCancelButton={false}
success={false}
/>
<ConfirmModal
title={translate('common.youAppearToBeOffline')}
isVisible={shouldShowOfflineModal}
onConfirm={() => setShouldShowOfflineModal(false)}
onCancel={() => setShouldShowOfflineModal(false)}
confirmText={translate('common.buttonConfirm')}
prompt={translate('common.offlinePrompt')}
shouldShowCancelButton={false}
/>
{shouldDisplayLHB && <NavigationTabBar selectedTab={NAVIGATION_TABS.WORKSPACES} />}
</ScreenWrapper>
);
Expand Down