From e421eae43d98742beacfe1f0929f787eb5336a06 Mon Sep 17 00:00:00 2001 From: Heri Setiawan Date: Tue, 10 Oct 2023 16:36:15 +0700 Subject: [PATCH 1/4] fix-27526: Web - Fix bank account start over with google login --- .../resetFreePlanBankAccount.js | 8 ++++---- .../workspace/WorkspaceResetBankAccountModal.js | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.js b/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.js index edb169fc96aa..75683e59e3a1 100644 --- a/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.js +++ b/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.js @@ -1,7 +1,6 @@ import Onyx from 'react-native-onyx'; import CONST from '../../../CONST'; import ONYXKEYS from '../../../ONYXKEYS'; -import * as store from './store'; import * as API from '../../API'; import * as PlaidDataProps from '../../../pages/ReimbursementAccount/plaidDataPropTypes'; import * as ReimbursementAccountProps from '../../../pages/ReimbursementAccount/reimbursementAccountPropTypes'; @@ -9,12 +8,13 @@ import * as ReimbursementAccountProps from '../../../pages/ReimbursementAccount/ /** * Reset user's reimbursement account. This will delete the bank account. * @param {number} bankAccountID + * @param {object} session */ -function resetFreePlanBankAccount(bankAccountID) { +function resetFreePlanBankAccount(bankAccountID, session) { if (!bankAccountID) { throw new Error('Missing bankAccountID when attempting to reset free plan bank account'); } - if (!store.getCredentials() || !store.getCredentials().login) { + if (!session.email) { throw new Error('Missing credentials when attempting to reset free plan bank account'); } @@ -22,7 +22,7 @@ function resetFreePlanBankAccount(bankAccountID) { 'RestartBankAccountSetup', { bankAccountID, - ownerEmail: store.getCredentials().login, + ownerEmail: session.email, }, { optimisticData: [ diff --git a/src/pages/workspace/WorkspaceResetBankAccountModal.js b/src/pages/workspace/WorkspaceResetBankAccountModal.js index d790a2503185..f2c786e16024 100644 --- a/src/pages/workspace/WorkspaceResetBankAccountModal.js +++ b/src/pages/workspace/WorkspaceResetBankAccountModal.js @@ -1,5 +1,6 @@ import lodashGet from 'lodash/get'; import React from 'react'; +import {withOnyx} from 'react-native-onyx'; import ConfirmModal from '../../components/ConfirmModal'; import * as BankAccounts from '../../libs/actions/BankAccounts'; import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize'; @@ -7,6 +8,8 @@ import * as ReimbursementAccountProps from '../ReimbursementAccount/reimbursemen import Text from '../../components/Text'; import styles from '../../styles/styles'; import BankAccount from '../../libs/models/BankAccount'; +import compose from '../../libs/compose'; +import ONYXKEYS from '../../ONYXKEYS'; const propTypes = { /** Reimbursement account data */ @@ -39,7 +42,7 @@ function WorkspaceResetBankAccountModal(props) { } danger onCancel={BankAccounts.cancelResetFreePlanBankAccount} - onConfirm={() => BankAccounts.resetFreePlanBankAccount(bankAccountID)} + onConfirm={() => BankAccounts.resetFreePlanBankAccount(bankAccountID, props.session)} shouldShowCancelButton isVisible /> @@ -49,4 +52,11 @@ function WorkspaceResetBankAccountModal(props) { WorkspaceResetBankAccountModal.displayName = 'WorkspaceResetBankAccountModal'; WorkspaceResetBankAccountModal.propTypes = propTypes; -export default withLocalize(WorkspaceResetBankAccountModal); +export default compose( + withLocalize, + withOnyx({ + session: { + key: ONYXKEYS.SESSION, + }, + }), +)(WorkspaceResetBankAccountModal); From 5829acb4ed51ff2f75ea9cc45329635b44ba2ce1 Mon Sep 17 00:00:00 2001 From: Heri Setiawan Date: Wed, 11 Oct 2023 05:35:24 +0700 Subject: [PATCH 2/4] Replace withTranslate with useTranslate --- .../WorkspaceResetBankAccountModal.js | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/pages/workspace/WorkspaceResetBankAccountModal.js b/src/pages/workspace/WorkspaceResetBankAccountModal.js index f2c786e16024..89c914ab667b 100644 --- a/src/pages/workspace/WorkspaceResetBankAccountModal.js +++ b/src/pages/workspace/WorkspaceResetBankAccountModal.js @@ -1,24 +1,29 @@ import lodashGet from 'lodash/get'; import React from 'react'; +import PropTypes from 'prop-types'; import {withOnyx} from 'react-native-onyx'; import ConfirmModal from '../../components/ConfirmModal'; import * as BankAccounts from '../../libs/actions/BankAccounts'; -import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize'; import * as ReimbursementAccountProps from '../ReimbursementAccount/reimbursementAccountPropTypes'; import Text from '../../components/Text'; import styles from '../../styles/styles'; import BankAccount from '../../libs/models/BankAccount'; -import compose from '../../libs/compose'; import ONYXKEYS from '../../ONYXKEYS'; +import useLocalize from '../../hooks/useLocalize'; const propTypes = { /** Reimbursement account data */ reimbursementAccount: ReimbursementAccountProps.reimbursementAccountPropTypes.isRequired, - ...withLocalizePropTypes, + /** Session info for the currently logged in user. */ + session: PropTypes.shape({ + /** Currently logged in user email */ + email: PropTypes.string, + }).isRequired, }; function WorkspaceResetBankAccountModal(props) { + const {translate} = useLocalize(); const achData = lodashGet(props.reimbursementAccount, 'achData') || {}; const isInOpenState = achData.state === BankAccount.STATE.OPEN; const bankAccountID = achData.bankAccountID; @@ -26,18 +31,18 @@ function WorkspaceResetBankAccountModal(props) { return ( - {props.translate('workspace.bankAccount.disconnectYour')} + {translate('workspace.bankAccount.disconnectYour')} {bankShortName} - {props.translate('workspace.bankAccount.bankAccountAnyTransactions')} + {translate('workspace.bankAccount.bankAccountAnyTransactions')} ) : ( - props.translate('workspace.bankAccount.clearProgress') + translate('workspace.bankAccount.clearProgress') ) } danger @@ -52,11 +57,8 @@ function WorkspaceResetBankAccountModal(props) { WorkspaceResetBankAccountModal.displayName = 'WorkspaceResetBankAccountModal'; WorkspaceResetBankAccountModal.propTypes = propTypes; -export default compose( - withLocalize, - withOnyx({ - session: { - key: ONYXKEYS.SESSION, - }, - }), -)(WorkspaceResetBankAccountModal); +export default withOnyx({ + session: { + key: ONYXKEYS.SESSION, + }, +})(WorkspaceResetBankAccountModal); From 0e10b8590d2b2db087d49e7380006a816116809f Mon Sep 17 00:00:00 2001 From: Heri Setiawan Date: Wed, 11 Oct 2023 13:49:26 +0700 Subject: [PATCH 3/4] Destructure props --- src/pages/workspace/WorkspaceResetBankAccountModal.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/workspace/WorkspaceResetBankAccountModal.js b/src/pages/workspace/WorkspaceResetBankAccountModal.js index 89c914ab667b..ff7bcb51e939 100644 --- a/src/pages/workspace/WorkspaceResetBankAccountModal.js +++ b/src/pages/workspace/WorkspaceResetBankAccountModal.js @@ -22,9 +22,9 @@ const propTypes = { }).isRequired, }; -function WorkspaceResetBankAccountModal(props) { +function WorkspaceResetBankAccountModal({reimbursementAccount, session}) { const {translate} = useLocalize(); - const achData = lodashGet(props.reimbursementAccount, 'achData') || {}; + const achData = lodashGet(reimbursementAccount, 'achData') || {}; const isInOpenState = achData.state === BankAccount.STATE.OPEN; const bankAccountID = achData.bankAccountID; const bankShortName = `${achData.addressName || ''} ${(achData.accountNumber || '').slice(-4)}`; @@ -47,7 +47,7 @@ function WorkspaceResetBankAccountModal(props) { } danger onCancel={BankAccounts.cancelResetFreePlanBankAccount} - onConfirm={() => BankAccounts.resetFreePlanBankAccount(bankAccountID, props.session)} + onConfirm={() => BankAccounts.resetFreePlanBankAccount(bankAccountID, session)} shouldShowCancelButton isVisible /> From 00206263b26019d081a5cabb570e8b633b67959c Mon Sep 17 00:00:00 2001 From: Heri Setiawan Date: Wed, 11 Oct 2023 14:29:46 +0700 Subject: [PATCH 4/4] Fix param typo --- .../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 75683e59e3a1..388010e99569 100644 --- a/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.js +++ b/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.js @@ -7,8 +7,8 @@ import * as ReimbursementAccountProps from '../../../pages/ReimbursementAccount/ /** * Reset user's reimbursement account. This will delete the bank account. - * @param {number} bankAccountID - * @param {object} session + * @param {Number} bankAccountID + * @param {Object} session */ function resetFreePlanBankAccount(bankAccountID, session) { if (!bankAccountID) {