From 05b795450062bc2c8fe9b08b5e0ec73d0597847f Mon Sep 17 00:00:00 2001 From: Manan Jadhav Date: Fri, 31 May 2024 18:18:43 +0530 Subject: [PATCH 1/3] fix: simplify modal state --- .../workspace/WorkspaceMoreFeaturesPage.tsx | 68 ++++++------------- 1 file changed, 22 insertions(+), 46 deletions(-) diff --git a/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx b/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx index 699ba9a14564..968b9540d412 100644 --- a/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx +++ b/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx @@ -31,12 +31,6 @@ import type {WithPolicyAndFullscreenLoadingProps} from './withPolicyAndFullscree import withPolicyAndFullscreenLoading from './withPolicyAndFullscreenLoading'; import ToggleSettingOptionRow from './workflows/ToggleSettingsOptionRow'; -type ItemType = 'organize' | 'integrate'; -type ConnectionWarningModalState = { - isOpen: boolean; - itemType?: ItemType; -}; - type WorkspaceMoreFeaturesPageProps = WithPolicyAndFullscreenLoadingProps & StackScreenProps; type Item = { @@ -66,7 +60,8 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro const isSyncTaxEnabled = !!policy?.connections?.quickbooksOnline?.config.syncTax || !!policy?.connections?.xero?.config.importTaxRates; const policyID = policy?.id ?? ''; - const [connectionWarningModalState, setConnectionWarningModalState] = useState({isOpen: false}); + const [isOrganizeWarningModalOpen, setIsOrganizeWarningModalOpen] = useState(false); + const [isIntegrateWarningModalOpen, setIsIntegrateWarningModalOpen] = useState(false); const spendItems: Item[] = [ { @@ -101,10 +96,7 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro pendingAction: policy?.pendingFields?.areCategoriesEnabled, action: (isEnabled: boolean) => { if (hasAccountingConnection) { - setConnectionWarningModalState({ - isOpen: true, - itemType: 'organize', - }); + setIsOrganizeWarningModalOpen(true); return; } Category.enablePolicyCategories(policy?.id ?? '', isEnabled); @@ -119,10 +111,7 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro pendingAction: policy?.pendingFields?.areTagsEnabled, action: (isEnabled: boolean) => { if (hasAccountingConnection) { - setConnectionWarningModalState({ - isOpen: true, - itemType: 'organize', - }); + setIsOrganizeWarningModalOpen(true); return; } Tag.enablePolicyTags(policy?.id ?? '', isEnabled); @@ -137,10 +126,7 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro pendingAction: policy?.pendingFields?.tax, action: (isEnabled: boolean) => { if (hasAccountingConnection) { - setConnectionWarningModalState({ - isOpen: true, - itemType: 'organize', - }); + setIsOrganizeWarningModalOpen(true); return; } Policy.enablePolicyTaxes(policy?.id ?? '', isEnabled); @@ -157,10 +143,7 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro pendingAction: policy?.pendingFields?.areConnectionsEnabled, action: (isEnabled: boolean) => { if (hasAccountingConnection) { - setConnectionWarningModalState({ - isOpen: true, - itemType: 'integrate', - }); + setIsIntegrateWarningModalOpen(false); return; } Policy.enablePolicyConnections(policy?.id ?? '', isEnabled); @@ -247,17 +230,6 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro }, [fetchFeatures]), ); - const getConnectionWarningPrompt = useCallback(() => { - switch (connectionWarningModalState.itemType) { - case 'organize': - return translate('workspace.moreFeatures.connectionsWarningModal.featureEnabledText'); - case 'integrate': - return translate('workspace.moreFeatures.connectionsWarningModal.disconnectText'); - default: - return undefined; - } - }, [connectionWarningModalState.itemType, translate]); - return ( { - setConnectionWarningModalState({ - isOpen: false, - itemType: undefined, - }); + setIsOrganizeWarningModalOpen(false); + Navigation.navigate(ROUTES.POLICY_ACCOUNTING.getRoute(policyID)); + }} + onCancel={() =>setIsOrganizeWarningModalOpen(false)} + isVisible={isOrganizeWarningModalOpen} + prompt={translate('workspace.moreFeatures.connectionsWarningModal.featureEnabledText')} + confirmText={translate('workspace.moreFeatures.connectionsWarningModal.manageSettings')} + cancelText={translate('common.cancel')} + /> + { + setIsIntegrateWarningModalOpen(false); Navigation.navigate(ROUTES.POLICY_ACCOUNTING.getRoute(policyID)); }} - onCancel={() => - setConnectionWarningModalState({ - isOpen: false, - itemType: undefined, - }) - } - isVisible={connectionWarningModalState.isOpen} - prompt={getConnectionWarningPrompt()} + onCancel={() => setIsIntegrateWarningModalOpen(false)} + isVisible={isIntegrateWarningModalOpen} + prompt={translate('workspace.moreFeatures.connectionsWarningModal.disconnectText')} confirmText={translate('workspace.moreFeatures.connectionsWarningModal.manageSettings')} cancelText={translate('common.cancel')} /> From a57e8c3aa31fb991c03a13da3908f55715c5decd Mon Sep 17 00:00:00 2001 From: Manan Jadhav Date: Fri, 31 May 2024 18:21:35 +0530 Subject: [PATCH 2/3] fix: flag condition --- src/pages/workspace/WorkspaceMoreFeaturesPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx b/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx index 968b9540d412..6479bf0537d0 100644 --- a/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx +++ b/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx @@ -143,7 +143,7 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro pendingAction: policy?.pendingFields?.areConnectionsEnabled, action: (isEnabled: boolean) => { if (hasAccountingConnection) { - setIsIntegrateWarningModalOpen(false); + setIsIntegrateWarningModalOpen(true); return; } Policy.enablePolicyConnections(policy?.id ?? '', isEnabled); From 32110d92ddc5da811be96ed7c47dfe9291272da6 Mon Sep 17 00:00:00 2001 From: Manan Jadhav Date: Fri, 31 May 2024 18:33:33 +0530 Subject: [PATCH 3/3] fix: prettier fix --- src/pages/workspace/WorkspaceMoreFeaturesPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx b/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx index 6479bf0537d0..245b4e4a291d 100644 --- a/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx +++ b/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx @@ -255,7 +255,7 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro setIsOrganizeWarningModalOpen(false); Navigation.navigate(ROUTES.POLICY_ACCOUNTING.getRoute(policyID)); }} - onCancel={() =>setIsOrganizeWarningModalOpen(false)} + onCancel={() => setIsOrganizeWarningModalOpen(false)} isVisible={isOrganizeWarningModalOpen} prompt={translate('workspace.moreFeatures.connectionsWarningModal.featureEnabledText')} confirmText={translate('workspace.moreFeatures.connectionsWarningModal.manageSettings')}