Skip to content

Commit

Permalink
Merge pull request #36495 from software-mansion-labs/ts/migrate-reimb…
Browse files Browse the repository at this point in the history
…ursement-account

[TS migration] Migrate 'ReimbursementAccount' to TypeScript
  • Loading branch information
mountiny authored Mar 15, 2024
2 parents 15124d7 + 5d792b7 commit 62b1b35
Show file tree
Hide file tree
Showing 16 changed files with 207 additions and 245 deletions.
7 changes: 7 additions & 0 deletions src/libs/API/parameters/RestartBankAccountSetupParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type RestartBankAccountSetupParams = {
bankAccountID: number;
ownerEmail: string;
policyID: string;
};

export default RestartBankAccountSetupParams;
1 change: 1 addition & 0 deletions src/libs/API/parameters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export type {default as ActivatePhysicalExpensifyCardParams} from './ActivatePhy
export type {default as AddNewContactMethodParams} from './AddNewContactMethodParams';
export type {default as AddPaymentCardParams} from './AddPaymentCardParams';
export type {default as AddPersonalBankAccountParams} from './AddPersonalBankAccountParams';
export type {default as RestartBankAccountSetupParams} from './RestartBankAccountSetupParams';
export type {default as AddSchoolPrincipalParams} from './AddSchoolPrincipalParams';
export type {default as AuthenticatePusherParams} from './AuthenticatePusherParams';
export type {default as BankAccountHandlePlaidErrorParams} from './BankAccountHandlePlaidErrorParams';
Expand Down
2 changes: 2 additions & 0 deletions src/libs/API/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const WRITE_COMMANDS = {
ADD_ATTACHMENT: 'AddAttachment',
CONNECT_BANK_ACCOUNT_WITH_PLAID: 'ConnectBankAccountWithPlaid',
ADD_PERSONAL_BANK_ACCOUNT: 'AddPersonalBankAccount',
RESTART_BANK_ACCOUNT_SETUP: 'RestartBankAccountSetup',
OPT_IN_TO_PUSH_NOTIFICATIONS: 'OptInToPushNotifications',
OPT_OUT_OF_PUSH_NOTIFICATIONS: 'OptOutOfPushNotifications',
RECONNECT_TO_REPORT: 'ReconnectToReport',
Expand Down Expand Up @@ -246,6 +247,7 @@ type WriteCommandParameters = {
[WRITE_COMMANDS.ADD_ATTACHMENT]: Parameters.AddCommentOrAttachementParams;
[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.OPT_IN_TO_PUSH_NOTIFICATIONS]: Parameters.OptInOutToPushNotificationsParams;
[WRITE_COMMANDS.OPT_OUT_OF_PUSH_NOTIFICATIONS]: Parameters.OptInOutToPushNotificationsParams;
[WRITE_COMMANDS.RECONNECT_TO_REPORT]: Parameters.ReconnectToReportParams;
Expand Down
1 change: 0 additions & 1 deletion src/libs/actions/BankAccounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export {
resetReimbursementAccount,
resetFreePlanBankAccount,
hideBankAccountErrors,
setWorkspaceIDForReimbursementAccount,
setBankAccountSubStep,
updateReimbursementAccountDraft,
requestResetFreePlanBankAccount,
Expand Down
18 changes: 0 additions & 18 deletions src/libs/actions/ReimbursementAccount/deleteFromBankAccountList.js

This file was deleted.

47 changes: 0 additions & 47 deletions src/libs/actions/ReimbursementAccount/errors.js

This file was deleted.

24 changes: 24 additions & 0 deletions src/libs/actions/ReimbursementAccount/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Onyx from 'react-native-onyx';
import ONYXKEYS from '@src/ONYXKEYS';
import type {ErrorFields} from '@src/types/onyx/OnyxCommon';

/**
* Set the current fields with errors.
*/
function setBankAccountFormValidationErrors(errorFields: ErrorFields) {
Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {errorFields: null});
Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {errorFields});
}

/**
* Clear validation messages from reimbursement account
*/
function resetReimbursementAccount() {
setBankAccountFormValidationErrors({});
Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {
errors: null,
pendingAction: null,
});
}

export {setBankAccountFormValidationErrors, resetReimbursementAccount};
Original file line number Diff line number Diff line change
@@ -1,36 +1,27 @@
import Onyx from 'react-native-onyx';
import ONYXKEYS from '@src/ONYXKEYS';
import deleteFromBankAccountList from './deleteFromBankAccountList';
import type {ReimbursementAccountForm} from '@src/types/form';
import type {BankAccountSubStep} from '@src/types/onyx/ReimbursementAccount';
import resetFreePlanBankAccount from './resetFreePlanBankAccount';

export {goToWithdrawalAccountSetupStep, navigateToBankAccountRoute} from './navigation';
export {setBankAccountFormValidationErrors, setPersonalBankAccountFormValidationErrorFields, resetReimbursementAccount, showBankAccountFormValidationError} from './errors';
export {setBankAccountFormValidationErrors, resetReimbursementAccount} from './errors';

/**
* Set the current sub step in first step of adding withdrawal bank account:
* - `null` if we want to go back to the view where the user selects between connecting via Plaid or connecting manually
* - CONST.BANK_ACCOUNT.SETUP_TYPE.MANUAL to ask them to enter their accountNumber and routingNumber
* - CONST.BANK_ACCOUNT.SETUP_TYPE.PLAID to ask them to login to their bank via Plaid
*
* @param {String | null} subStep
* @returns {Promise<void>}
*/
function setBankAccountSubStep(subStep) {
function setBankAccountSubStep(subStep: BankAccountSubStep | null): Promise<void> {
return Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {achData: {subStep}});
}

function hideBankAccountErrors() {
Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {error: '', errors: null});
}

function setWorkspaceIDForReimbursementAccount(workspaceID) {
Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT_WORKSPACE_ID, workspaceID);
}

/**
* @param {Object} bankAccountData
*/
function updateReimbursementAccountDraft(bankAccountData) {
function updateReimbursementAccountDraft(bankAccountData: Partial<ReimbursementAccountForm>) {
Onyx.merge(ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM_DRAFT, bankAccountData);
Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {draftStep: undefined});
}
Expand All @@ -49,13 +40,4 @@ function cancelResetFreePlanBankAccount() {
Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {shouldShowResetModal: false});
}

export {
resetFreePlanBankAccount,
setBankAccountSubStep,
hideBankAccountErrors,
setWorkspaceIDForReimbursementAccount,
updateReimbursementAccountDraft,
requestResetFreePlanBankAccount,
cancelResetFreePlanBankAccount,
deleteFromBankAccountList,
};
export {resetFreePlanBankAccount, setBankAccountSubStep, hideBankAccountErrors, updateReimbursementAccountDraft, requestResetFreePlanBankAccount, cancelResetFreePlanBankAccount};
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,22 @@ import Onyx from 'react-native-onyx';
import Navigation from '@libs/Navigation/Navigation';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {BankAccountStep} from '@src/types/onyx/ReimbursementAccount';

/**
* Navigate to a specific step in the VBA flow
*
* @param {String} stepID
*/
function goToWithdrawalAccountSetupStep(stepID) {
function goToWithdrawalAccountSetupStep(stepID: BankAccountStep) {
Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {achData: {currentStep: stepID}});
}

/**
* Navigate to the correct bank account route based on the bank account state and type
*
* @param {string} policyID - The policy ID associated with the bank account.
* @param {string} [backTo=''] - An optional return path. If provided, it will be URL-encoded and appended to the resulting URL.
* @param policyID - The policy ID associated with the bank account.
* @param [backTo] - An optional return path. If provided, it will be URL-encoded and appended to the resulting URL.
*/
function navigateToBankAccountRoute(policyID, backTo) {
function navigateToBankAccountRoute(policyID: string, backTo?: string) {
Navigation.navigate(ROUTES.BANK_ACCOUNT_WITH_STEP_TO_OPEN.getRoute('', policyID, backTo));
}

Expand Down
85 changes: 0 additions & 85 deletions src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.js

This file was deleted.

Loading

0 comments on commit 62b1b35

Please sign in to comment.