Skip to content

feat: Reset non USD flow #58100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
5 changes: 5 additions & 0 deletions src/libs/API/parameters/ResetBankAccountSetupParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type ResetBankAccountSetupParams = {
policyID: string | undefined;
};

export default ResetBankAccountSetupParams;
1 change: 1 addition & 0 deletions src/libs/API/parameters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,3 +381,4 @@ export type {SaveCorpayOnboardingCompanyDetailsParams} from './SaveCorpayOnboard
export type {default as AcceptSpotnanaTermsParams} from './AcceptSpotnanaTermsParams';
export type {default as SaveCorpayOnboardingBeneficialOwnerParams} from './SaveCorpayOnboardingBeneficialOwnerParams';
export type {default as ChangeReportPolicyParams} from './ChangeReportPolicyParams';
export type {default as ResetBankAccountSetupParams} from './ResetBankAccountSetupParams';
2 changes: 2 additions & 0 deletions src/libs/API/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ const WRITE_COMMANDS = {
CONNECT_BANK_ACCOUNT_WITH_PLAID: 'ConnectBankAccountWithPlaid',
ADD_PERSONAL_BANK_ACCOUNT: 'AddPersonalBankAccount',
RESTART_BANK_ACCOUNT_SETUP: 'RestartBankAccountSetup',
RESET_BANK_ACCOUNT_SETUP: 'ResetBankAccountSetup',
RESEND_VALIDATE_CODE: 'ResendValidateCode',
READ_NEWEST_ACTION: 'ReadNewestAction',
MARK_AS_UNREAD: 'MarkAsUnread',
Expand Down Expand Up @@ -552,6 +553,7 @@ type WriteCommandParameters = {
[WRITE_COMMANDS.CONNECT_BANK_ACCOUNT_WITH_PLAID]: Parameters.ConnectBankAccountParams;
[WRITE_COMMANDS.ADD_PERSONAL_BANK_ACCOUNT]: Parameters.AddPersonalBankAccountParams;
[WRITE_COMMANDS.RESTART_BANK_ACCOUNT_SETUP]: Parameters.RestartBankAccountSetupParams;
[WRITE_COMMANDS.RESET_BANK_ACCOUNT_SETUP]: Parameters.ResetBankAccountSetupParams;
[WRITE_COMMANDS.RESEND_VALIDATE_CODE]: null;
[WRITE_COMMANDS.READ_NEWEST_ACTION]: Parameters.ReadNewestActionParams;
[WRITE_COMMANDS.MARK_AS_UNREAD]: Parameters.MarkAsUnreadParams;
Expand Down
7 changes: 4 additions & 3 deletions src/libs/actions/BankAccounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ export {
goToWithdrawalAccountSetupStep,
setBankAccountFormValidationErrors,
resetReimbursementAccount,
resetFreePlanBankAccount,
resetUSDBankAccount,
resetNonUSDBankAccount,
hideBankAccountErrors,
setBankAccountSubStep,
updateReimbursementAccountDraft,
requestResetFreePlanBankAccount,
cancelResetFreePlanBankAccount,
requestResetBankAccount,
cancelResetBankAccount,
} from './ReimbursementAccount';
export {openPlaidBankAccountSelector, openPlaidBankLogin} from './Plaid';
export {openOnfidoFlow, answerQuestionsForWallet, verifyIdentity, acceptWalletTerms} from './Wallet';
Expand Down
14 changes: 8 additions & 6 deletions src/libs/actions/ReimbursementAccount/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import Onyx from 'react-native-onyx';
import ONYXKEYS from '@src/ONYXKEYS';
import type {ReimbursementAccountForm} from '@src/types/form';
import type {BankAccountSubStep} from '@src/types/onyx/ReimbursementAccount';
import resetFreePlanBankAccount from './resetFreePlanBankAccount';
import resetNonUSDBankAccount from './resetNonUSDBankAccount';
import resetUSDBankAccount from './resetUSDBankAccount';

export {goToWithdrawalAccountSetupStep, navigateToBankAccountRoute} from './navigation';
export {setBankAccountFormValidationErrors, resetReimbursementAccount} from './errors';
Expand Down Expand Up @@ -33,23 +34,24 @@ function clearReimbursementAccountDraft() {
/**
* Triggers a modal to open allowing the user to reset their bank account
*/
function requestResetFreePlanBankAccount() {
function requestResetBankAccount() {
Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {shouldShowResetModal: true});
}

/**
* Hides modal allowing the user to reset their bank account
*/
function cancelResetFreePlanBankAccount() {
function cancelResetBankAccount() {
Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {shouldShowResetModal: false});
}

export {
resetFreePlanBankAccount,
resetUSDBankAccount,
resetNonUSDBankAccount,
setBankAccountSubStep,
hideBankAccountErrors,
updateReimbursementAccountDraft,
requestResetFreePlanBankAccount,
cancelResetFreePlanBankAccount,
requestResetBankAccount,
cancelResetBankAccount,
clearReimbursementAccountDraft,
};
76 changes: 76 additions & 0 deletions src/libs/actions/ReimbursementAccount/resetNonUSDBankAccount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import Onyx from 'react-native-onyx';
import type {OnyxCollection} from 'react-native-onyx';
import * as API from '@libs/API';
import {WRITE_COMMANDS} from '@libs/API/types';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type * as OnyxTypes from '@src/types/onyx';

let allPolicies: OnyxCollection<OnyxTypes.Policy>;
Onyx.connect({
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (value) => (allPolicies = value),
});

function resetNonUSDBankAccount(policyID: string | undefined) {
if (!policyID) {
throw new Error('Missing Policy ID when attempting to reset');
}

const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`] ?? ({} as OnyxTypes.Policy);

API.write(
WRITE_COMMANDS.RESET_BANK_ACCOUNT_SETUP,
{policyID},
{
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
value: {
shouldShowResetModal: false,
isLoading: true,
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
achData: null,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
achAccount: null,
},
},
],
successData: [
{
onyxMethod: Onyx.METHOD.SET,
key: ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM_DRAFT,
value: null,
},
{
onyxMethod: Onyx.METHOD.SET,
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
value: CONST.REIMBURSEMENT_ACCOUNT.DEFAULT_DATA,
},
],
failureData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
value: {isLoading: false, pendingAction: null},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
achAccount: policy?.achAccount,
},
},
],
},
);
}

export default resetNonUSDBankAccount;
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ Onyx.connect({
});

/**
* Reset user's reimbursement account. This will delete the bank account.
* Reset user's USD reimbursement account. This will delete the bank account
*/
function resetFreePlanBankAccount(bankAccountID: number | undefined, session: OnyxEntry<OnyxTypes.Session>, policyID: string | undefined) {
function resetUSDBankAccount(bankAccountID: number | undefined, session: OnyxEntry<OnyxTypes.Session>, policyID: string | undefined) {
if (!bankAccountID) {
throw new Error('Missing bankAccountID when attempting to reset free plan bank account');
}
Expand Down Expand Up @@ -143,4 +143,4 @@ function resetFreePlanBankAccount(bankAccountID: number | undefined, session: On
);
}

export default resetFreePlanBankAccount;
export default resetUSDBankAccount;
23 changes: 19 additions & 4 deletions src/pages/ReimbursementAccount/ConnectedVerifiedBankAccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import WorkspaceResetBankAccountModal from '@pages/workspace/WorkspaceResetBankAccountModal';
import {requestResetFreePlanBankAccount, resetReimbursementAccount} from '@userActions/ReimbursementAccount';
import {requestResetBankAccount, resetReimbursementAccount} from '@userActions/ReimbursementAccount';
import type {ReimbursementAccount} from '@src/types/onyx';
import {isEmptyObject} from '@src/types/utils/EmptyObject';

Expand All @@ -27,11 +27,24 @@ type ConnectedVerifiedBankAccountProps = {
/** Method to set the state of shouldShowConnectedVerifiedBankAccount */
setShouldShowConnectedVerifiedBankAccount: (shouldShowConnectedVerifiedBankAccount: boolean) => void;

/** Method to set the state of shouldShowConnectedVerifiedBankAccount */
/** Method to set the state of USD bank account step */
setUSDBankAccountStep: (step: string | null) => void;

/** Method to set the state of setNonUSDBankAccountStep */
setNonUSDBankAccountStep?: (step: string | null) => void;

/** Whether the workspace currency is set to non USD currency */
isNonUSDWorkspace: boolean;
};

function ConnectedVerifiedBankAccount({reimbursementAccount, onBackButtonPress, setShouldShowConnectedVerifiedBankAccount, setUSDBankAccountStep}: ConnectedVerifiedBankAccountProps) {
function ConnectedVerifiedBankAccount({
reimbursementAccount,
onBackButtonPress,
setShouldShowConnectedVerifiedBankAccount,
setUSDBankAccountStep,
setNonUSDBankAccountStep,
isNonUSDWorkspace,
}: ConnectedVerifiedBankAccountProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();

Expand Down Expand Up @@ -83,7 +96,7 @@ function ConnectedVerifiedBankAccount({reimbursementAccount, onBackButtonPress,
<MenuItem
title={translate('workspace.bankAccount.disconnectBankAccount')}
icon={Close}
onPress={requestResetFreePlanBankAccount}
onPress={requestResetBankAccount}
wrapperStyle={[styles.cardMenuItem, styles.mv3]}
disabled={!!pendingAction || !isEmptyObject(errors)}
/>
Expand All @@ -94,7 +107,9 @@ function ConnectedVerifiedBankAccount({reimbursementAccount, onBackButtonPress,
<WorkspaceResetBankAccountModal
reimbursementAccount={reimbursementAccount}
setShouldShowConnectedVerifiedBankAccount={setShouldShowConnectedVerifiedBankAccount}
isNonUSDWorkspace={isNonUSDWorkspace}
setUSDBankAccountStep={setUSDBankAccountStep}
setNonUSDBankAccountStep={setNonUSDBankAccountStep}
/>
)}
</ScreenWrapper>
Expand Down
23 changes: 20 additions & 3 deletions src/pages/ReimbursementAccount/NonUSD/Country/Country.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,34 @@ type CountryProps = {

/** Handles submit button press */
onSubmit: () => void;

/** ID of current policy */
policyID: string | undefined;
};

const bodyContent: Array<ComponentType<SubStepProps>> = [Confirmation];
type CountryStepProps = {
/** ID of current policy */
policyID: string | undefined;
} & SubStepProps;

const bodyContent: Array<ComponentType<CountryStepProps>> = [Confirmation];

function Country({onBackButtonPress, onSubmit}: CountryProps) {
function Country({onBackButtonPress, onSubmit, policyID}: CountryProps) {
const {translate} = useLocalize();

const submit = () => {
onSubmit();
};

const {componentToRender: SubStep, isEditing, screenIndex, nextScreen, prevScreen, moveTo, goToTheLastStep} = useSubStep({bodyContent, startFrom: 0, onFinished: submit});
const {
componentToRender: SubStep,
isEditing,
screenIndex,
nextScreen,
prevScreen,
moveTo,
goToTheLastStep,
} = useSubStep<CountryStepProps>({bodyContent, startFrom: 0, onFinished: submit});

const handleBackButtonPress = () => {
if (isEditing) {
Expand All @@ -51,6 +67,7 @@ function Country({onBackButtonPress, onSubmit}: CountryProps) {
isEditing={isEditing}
onNext={nextScreen}
onMove={moveTo}
policyID={policyID}
/>
</InteractiveStepWrapper>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@ import INPUT_IDS from '@src/types/form/ReimbursementAccountForm';

const {COUNTRY} = INPUT_IDS.ADDITIONAL_DATA;

function Confirmation({onNext}: SubStepProps) {
type ConfirmationStepProps = {
/** ID of current policy */
policyID: string | undefined;
} & SubStepProps;

function Confirmation({onNext, policyID}: ConfirmationStepProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const [reimbursementAccount] = useOnyx(ONYXKEYS.REIMBURSEMENT_ACCOUNT);
const [reimbursementAccountDraft] = useOnyx(ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM_DRAFT);

const policyID = reimbursementAccount?.achData?.policyID;
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`);
const currency = policy?.outputCurrency ?? '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,17 @@ type NonUSDVerifiedBankAccountFlowProps = {
nonUSDBankAccountStep: string;
setNonUSDBankAccountStep: (step: string | null) => void;
setShouldShowContinueSetupButton: (shouldShowConnectedVerifiedBankAccount: boolean) => void;
policyID: string | undefined;
shouldShowContinueSetupButtonValue: boolean;
};

function NonUSDVerifiedBankAccountFlow({nonUSDBankAccountStep, setNonUSDBankAccountStep, setShouldShowContinueSetupButton}: NonUSDVerifiedBankAccountFlowProps) {
function NonUSDVerifiedBankAccountFlow({
nonUSDBankAccountStep,
setNonUSDBankAccountStep,
setShouldShowContinueSetupButton,
policyID,
shouldShowContinueSetupButtonValue,
}: NonUSDVerifiedBankAccountFlowProps) {
const handleNextNonUSDBankAccountStep = () => {
switch (nonUSDBankAccountStep) {
case CONST.NON_USD_BANK_ACCOUNT.STEP.COUNTRY:
Expand Down Expand Up @@ -43,8 +51,8 @@ function NonUSDVerifiedBankAccountFlow({nonUSDBankAccountStep, setNonUSDBankAcco
const nonUSDBankAccountsGoBack = () => {
switch (nonUSDBankAccountStep) {
case CONST.NON_USD_BANK_ACCOUNT.STEP.COUNTRY:
setShouldShowContinueSetupButton(true);
setNonUSDBankAccountStep(null);
setShouldShowContinueSetupButton(shouldShowContinueSetupButtonValue);
break;
case CONST.NON_USD_BANK_ACCOUNT.STEP.BANK_INFO:
setNonUSDBankAccountStep(CONST.NON_USD_BANK_ACCOUNT.STEP.COUNTRY);
Expand Down Expand Up @@ -72,6 +80,7 @@ function NonUSDVerifiedBankAccountFlow({nonUSDBankAccountStep, setNonUSDBankAcco
<Country
onBackButtonPress={nonUSDBankAccountsGoBack}
onSubmit={handleNextNonUSDBankAccountStep}
policyID={policyID}
/>
);
case CONST.NON_USD_BANK_ACCOUNT.STEP.BANK_INFO:
Expand Down
Loading