From de66ccd0a8c1357226ca2806ba24a82ec0e950ca Mon Sep 17 00:00:00 2001 From: madmax330 Date: Mon, 11 Jul 2022 20:48:12 +0200 Subject: [PATCH 1/3] Refactor RestartBankAccountSetup --- .../resetFreePlanBankAccount.js | 56 +++++++++---------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.js b/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.js index 4f54352169ff..a2c49a735448 100644 --- a/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.js +++ b/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.js @@ -1,12 +1,10 @@ -import Onyx from 'react-native-onyx'; import lodashGet from 'lodash/get'; import ONYXKEYS from '../../../ONYXKEYS'; -import * as DeprecatedAPI from '../../deprecatedAPI'; import CONST from '../../../CONST'; import * as store from './store'; -import Growl from '../../Growl'; import Navigation from '../../Navigation/Navigation'; import ROUTES from '../../../ROUTES'; +import API from '../../API'; /** * Reset user's reimbursement account. This will delete the bank account. @@ -20,35 +18,33 @@ function resetFreePlanBankAccount() { throw new Error('Missing credentials when attempting to reset free plan bank account'); } - // Create a copy of the reimbursementAccount data since we are going to optimistically wipe it so the UI changes quickly. - // If the API request fails we will set this data back into Onyx. - const previousACHData = {...store.getReimbursementAccountInSetup()}; - Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {achData: null, shouldShowResetModal: false}); - DeprecatedAPI.DeleteBankAccount({bankAccountID, ownerEmail: store.getCredentials().login}) - .then((response) => { - if (response.jsonCode !== 200) { - // Unable to delete bank account so we restore the bank account details - Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {achData: previousACHData}); - Growl.error('Sorry we were unable to delete this bank account. Please try again later'); - return; - } + const achData = { + useOnfido: true, + policyID: '', + isInSetup: true, + domainLimit: 0, + currentStep: CONST.BANK_ACCOUNT.STEP.BANK_ACCOUNT, + }; - // Reset reimbursement account, and clear draft user input - const achData = { - useOnfido: true, - policyID: '', - isInSetup: true, - domainLimit: 0, - currentStep: CONST.BANK_ACCOUNT.STEP.BANK_ACCOUNT, - }; - - Onyx.set(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {achData}); - Onyx.set(ONYXKEYS.REIMBURSEMENT_ACCOUNT_DRAFT, null); - - // Clear the NVP for the bank account so the user can add a new one and navigate back to bank account page - DeprecatedAPI.SetNameValuePair({name: CONST.NVP.FREE_PLAN_BANK_ACCOUNT_ID, value: ''}); - Navigation.navigate(ROUTES.getBankAccountRoute()); + API.write('RestartBankAccountSetup', + { + bankAccountID, + ownerEmail: store.getCredentials().login, + }, + { + optimisticData: [{ + onyxMethod: 'merge', + key: ONYXKEYS.REIMBURSEMENT_ACCOUNT, + value: {achData: achData, shouldShowResetModal: false}, + }, + { + onyxMethod: 'set', + key: ONYXKEYS.REIMBURSEMENT_ACCOUNT_DRAFT, + value: null, + }], }); + + Navigation.navigate(ROUTES.getBankAccountRoute()); } export default resetFreePlanBankAccount; From af321b2a0449df00fe424e6c21d578ce582d788f Mon Sep 17 00:00:00 2001 From: madmax330 Date: Mon, 11 Jul 2022 22:04:36 +0200 Subject: [PATCH 2/3] small fixes --- .../actions/ReimbursementAccount/resetFreePlanBankAccount.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.js b/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.js index a2c49a735448..3ef61cef0885 100644 --- a/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.js +++ b/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.js @@ -4,7 +4,7 @@ import CONST from '../../../CONST'; import * as store from './store'; import Navigation from '../../Navigation/Navigation'; import ROUTES from '../../../ROUTES'; -import API from '../../API'; +import * as API from '../../API'; /** * Reset user's reimbursement account. This will delete the bank account. @@ -26,7 +26,7 @@ function resetFreePlanBankAccount() { currentStep: CONST.BANK_ACCOUNT.STEP.BANK_ACCOUNT, }; - API.write('RestartBankAccountSetup', + API.write('RestartBankAccountSetup', { bankAccountID, ownerEmail: store.getCredentials().login, From aa1590729fba2d9db071ee5f26cd758ab02c5c7c Mon Sep 17 00:00:00 2001 From: madmax330 Date: Mon, 11 Jul 2022 22:15:24 +0200 Subject: [PATCH 3/3] style --- .../actions/ReimbursementAccount/resetFreePlanBankAccount.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.js b/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.js index 3ef61cef0885..3ef49fbc854f 100644 --- a/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.js +++ b/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.js @@ -35,7 +35,7 @@ function resetFreePlanBankAccount() { optimisticData: [{ onyxMethod: 'merge', key: ONYXKEYS.REIMBURSEMENT_ACCOUNT, - value: {achData: achData, shouldShowResetModal: false}, + value: {achData, shouldShowResetModal: false}, }, { onyxMethod: 'set',