Skip to content
19 changes: 19 additions & 0 deletions src/hooks/useDismissModalForUSD.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type {Dispatch, SetStateAction} from 'react';
import {useEffect, useState} from 'react';
import CONST from '@src/CONST';

function useDismissModalForUSD(workspaceCurrency: string | undefined): [isCurrencyModalOpen: boolean, setIsCurrencyModalOpen: Dispatch<SetStateAction<boolean>>] {
const [isCurrencyModalOpen, setIsCurrencyModalOpen] = useState(false);

useEffect(() => {
Comment thread
FitseTLT marked this conversation as resolved.
Resolved
if (!isCurrencyModalOpen || workspaceCurrency !== CONST.CURRENCY.USD) {
return;
}

setIsCurrencyModalOpen(false);
}, [workspaceCurrency, isCurrencyModalOpen, setIsCurrencyModalOpen]);

return [isCurrencyModalOpen, setIsCurrencyModalOpen];
}

export default useDismissModalForUSD;
28 changes: 1 addition & 27 deletions src/pages/workspace/WorkspaceInitialPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView';
import ConfirmModal from '@components/ConfirmModal';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import HighlightableMenuItem from '@components/HighlightableMenuItem';
import {
Expand Down Expand Up @@ -41,8 +40,7 @@ import useThemeStyles from '@hooks/useThemeStyles';
import useWaitForNavigation from '@hooks/useWaitForNavigation';
import {confirmReadyToOpenApp} from '@libs/actions/App';
import {isConnectionInProgress} from '@libs/actions/connections';
import {clearErrors, openPolicyInitialPage, removeWorkspace, updateGeneralSettings} from '@libs/actions/Policy/Policy';
import {navigateToBankAccountRoute} from '@libs/actions/ReimbursementAccount';
import {clearErrors, openPolicyInitialPage, removeWorkspace} from '@libs/actions/Policy/Policy';
import {checkIfFeedConnectionIsBroken, flatAllCardsList} from '@libs/CardUtils';
import {convertToDisplayString} from '@libs/CurrencyUtils';
import Navigation from '@libs/Navigation/Navigation';
Expand Down Expand Up @@ -106,7 +104,6 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, route}: Workspac
const styles = useThemeStyles();
const policy = policyDraft?.id ? policyDraft : policyProp;
const workspaceAccountID = getWorkspaceAccountID(policy?.id);
const [isCurrencyModalOpen, setIsCurrencyModalOpen] = useState(false);
const hasPolicyCreationError = policy?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD && !isEmptyObject(policy.errors);
const [allFeedsCards] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}`);
const [connectionSyncProgress] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}${policy?.id}`);
Expand Down Expand Up @@ -161,19 +158,6 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, route}: Workspac

const policyID = policy?.id;
const policyName = policy?.name ?? '';
useEffect(() => {
if (!isCurrencyModalOpen || policy?.outputCurrency !== CONST.CURRENCY.USD) {
return;
}
setIsCurrencyModalOpen(false);
}, [policy?.outputCurrency, isCurrencyModalOpen]);

/** Call update workspace currency and hide the modal */
const confirmCurrencyChangeAndHideModal = useCallback(() => {
updateGeneralSettings(policyID, policyName, CONST.CURRENCY.USD);
setIsCurrencyModalOpen(false);
navigateToBankAccountRoute(policyID);
}, [policyID, policyName]);

const hasMembersError = shouldShowEmployeeListError(policy);
const hasPolicyCategoryError = hasPolicyCategoriesError(policyCategories);
Expand Down Expand Up @@ -503,16 +487,6 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, route}: Workspac
</View>
)}
</ScrollView>
<ConfirmModal
title={translate('workspace.bankAccount.workspaceCurrency')}
isVisible={isCurrencyModalOpen}
onConfirm={confirmCurrencyChangeAndHideModal}
onCancel={() => setIsCurrencyModalOpen(false)}
prompt={translate('workspace.bankAccount.updateCurrencyPrompt')}
confirmText={translate('workspace.bankAccount.updateToUSD')}
cancelText={translate('common.cancel')}
danger
/>
</FullPageNotFoundView>
</ScreenWrapper>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import FeatureList from '@components/FeatureList';
import type {FeatureListItem} from '@components/FeatureList';
import * as Illustrations from '@components/Icon/Illustrations';
import Text from '@components/Text';
import useDismissModalForUSD from '@hooks/useDismissModalForUSD';
import useLocalize from '@hooks/useLocalize';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useTheme from '@hooks/useTheme';
Expand Down Expand Up @@ -52,7 +53,7 @@ function WorkspaceExpensifyCardPageEmptyState({route, policy}: WorkspaceExpensif
const {shouldUseNarrowLayout} = useResponsiveLayout();
const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST);
const [reimbursementAccount] = useOnyx(ONYXKEYS.REIMBURSEMENT_ACCOUNT);
const [isCurrencyModalOpen, setIsCurrencyModalOpen] = useState(false);
const [isCurrencyModalOpen, setIsCurrencyModalOpen] = useDismissModalForUSD(policy?.outputCurrency);

const [isActingAsDelegate] = useOnyx(ONYXKEYS.ACCOUNT, {selector: (account) => !!account?.delegatedAccess?.delegate});
const [isNoDelegateAccessMenuVisible, setIsNoDelegateAccessMenuVisible] = useState(false);
Expand All @@ -77,7 +78,7 @@ function WorkspaceExpensifyCardPageEmptyState({route, policy}: WorkspaceExpensif
updatePolicyGeneralSettings(policy.id, policy.name, CONST.CURRENCY.USD);
setIsCurrencyModalOpen(false);
startFlow();
}, [policy, startFlow]);
}, [policy, startFlow, setIsCurrencyModalOpen]);

return (
<WorkspacePageWithSections
Expand Down
Loading