Skip to content

Commit 83944b6

Browse files
authored
Merge pull request Expensify#63755 from bernhardoj/fix/63669-currency-can-be-changed-after-add-ba
Fix user can change currency after adding a bank account
2 parents f16f529 + 7619d21 commit 83944b6

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

src/libs/actions/ReimbursementAccount/navigation.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Onyx from 'react-native-onyx';
2+
import type {LinkToOptions} from '@libs/Navigation/helpers/linkTo/types';
23
import Navigation from '@libs/Navigation/Navigation';
34
import ONYXKEYS from '@src/ONYXKEYS';
45
import ROUTES from '@src/ROUTES';
@@ -17,8 +18,8 @@ function goToWithdrawalAccountSetupStep(stepID: BankAccountStep) {
1718
* @param policyID - The policy ID associated with the bank account.
1819
* @param [backTo] - An optional return path. If provided, it will be URL-encoded and appended to the resulting URL.
1920
*/
20-
function navigateToBankAccountRoute(policyID: string | undefined, backTo?: string) {
21-
Navigation.navigate(ROUTES.BANK_ACCOUNT_WITH_STEP_TO_OPEN.getRoute(policyID, '', backTo));
21+
function navigateToBankAccountRoute(policyID: string | undefined, backTo?: string, navigationOptions?: LinkToOptions) {
22+
Navigation.navigate(ROUTES.BANK_ACCOUNT_WITH_STEP_TO_OPEN.getRoute(policyID, '', backTo), navigationOptions);
2223
}
2324

2425
export {goToWithdrawalAccountSetupStep, navigateToBankAccountRoute};

src/pages/workspace/WorkspaceOverviewCurrencyPage.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import ScreenWrapper from '@components/ScreenWrapper';
77
import useLocalize from '@hooks/useLocalize';
88
import useOnyx from '@hooks/useOnyx';
99
import usePermissions from '@hooks/usePermissions';
10+
import BankAccount from '@libs/models/BankAccount';
1011
import Navigation from '@libs/Navigation/Navigation';
1112
import {goBackFromInvalidPolicy} from '@libs/PolicyUtils';
1213
import mapCurrencyToCountry from '@pages/ReimbursementAccount/utils/mapCurrencyToCountry';
@@ -32,7 +33,7 @@ function WorkspaceOverviewCurrencyPage({policy}: WorkspaceOverviewCurrencyPagePr
3233
const {translate} = useLocalize();
3334
const {isBetaEnabled} = usePermissions();
3435
const [isForcedToChangeCurrency] = useOnyx(ONYXKEYS.IS_FORCED_TO_CHANGE_CURRENCY, {canBeMissing: true});
35-
36+
const [hasVBA = false] = useOnyx(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {selector: (value) => value?.achData?.state === BankAccount.STATE.OPEN, canBeMissing: true});
3637
const onSelectCurrency = (item: CurrencyListItem) => {
3738
if (!policy) {
3839
return;
@@ -46,7 +47,7 @@ function WorkspaceOverviewCurrencyPage({policy}: WorkspaceOverviewCurrencyPagePr
4647
setIsForcedToChangeCurrency(false);
4748

4849
if (isCurrencySupportedForGlobalReimbursement(item.currencyCode as CurrencyType, isBetaEnabled(CONST.BETAS.GLOBAL_REIMBURSEMENTS_ON_ND) ?? false)) {
49-
navigateToBankAccountRoute(policy.id, ROUTES.WORKSPACE_WORKFLOWS.getRoute(policy.id));
50+
navigateToBankAccountRoute(policy.id, ROUTES.WORKSPACE_WORKFLOWS.getRoute(policy.id), {forceReplace: true});
5051
return;
5152
}
5253
}
@@ -57,7 +58,11 @@ function WorkspaceOverviewCurrencyPage({policy}: WorkspaceOverviewCurrencyPagePr
5758
<AccessOrNotFoundWrapper
5859
policyID={policy?.id}
5960
accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN]}
60-
fullPageNotFoundViewProps={{onLinkPress: goBackFromInvalidPolicy, subtitleKey: isEmptyObject(policy) ? undefined : 'workspace.common.notAuthorized'}}
61+
shouldBeBlocked={hasVBA}
62+
fullPageNotFoundViewProps={{
63+
onLinkPress: hasVBA ? () => Navigation.goBack() : goBackFromInvalidPolicy,
64+
subtitleKey: hasVBA || isEmptyObject(policy) ? undefined : 'workspace.common.notAuthorized',
65+
}}
6166
>
6267
<ScreenWrapper
6368
enableEdgeToEdgeBottomSafeAreaPadding

0 commit comments

Comments
 (0)