Skip to content

Commit

Permalink
Merge pull request #29167 from zukilover/webf/27526-bank-account
Browse files Browse the repository at this point in the history
fix-27526: Web - Fix bank account start over with google login
  • Loading branch information
marcochavezf committed Oct 11, 2023
2 parents 3400bc1 + 0020626 commit fa34d33
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
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';

/**
* Reset user's reimbursement account. This will delete the bank account.
* @param {number} bankAccountID
* @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');
}

API.write(
'RestartBankAccountSetup',
{
bankAccountID,
ownerEmail: store.getCredentials().login,
ownerEmail: session.email,
},
{
optimisticData: [
Expand Down
36 changes: 24 additions & 12 deletions src/pages/workspace/WorkspaceResetBankAccountModal.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,53 @@
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 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 achData = lodashGet(props.reimbursementAccount, 'achData') || {};
function WorkspaceResetBankAccountModal({reimbursementAccount, session}) {
const {translate} = useLocalize();
const achData = lodashGet(reimbursementAccount, 'achData') || {};
const isInOpenState = achData.state === BankAccount.STATE.OPEN;
const bankAccountID = achData.bankAccountID;
const bankShortName = `${achData.addressName || ''} ${(achData.accountNumber || '').slice(-4)}`;

return (
<ConfirmModal
title={props.translate('workspace.bankAccount.areYouSure')}
confirmText={isInOpenState ? props.translate('workspace.bankAccount.yesDisconnectMyBankAccount') : props.translate('workspace.bankAccount.yesStartOver')}
cancelText={props.translate('common.cancel')}
title={translate('workspace.bankAccount.areYouSure')}
confirmText={isInOpenState ? translate('workspace.bankAccount.yesDisconnectMyBankAccount') : translate('workspace.bankAccount.yesStartOver')}
cancelText={translate('common.cancel')}
prompt={
isInOpenState ? (
<Text>
<Text>{props.translate('workspace.bankAccount.disconnectYour')}</Text>
<Text>{translate('workspace.bankAccount.disconnectYour')}</Text>
<Text style={styles.textStrong}>{bankShortName}</Text>
<Text>{props.translate('workspace.bankAccount.bankAccountAnyTransactions')}</Text>
<Text>{translate('workspace.bankAccount.bankAccountAnyTransactions')}</Text>
</Text>
) : (
props.translate('workspace.bankAccount.clearProgress')
translate('workspace.bankAccount.clearProgress')
)
}
danger
onCancel={BankAccounts.cancelResetFreePlanBankAccount}
onConfirm={() => BankAccounts.resetFreePlanBankAccount(bankAccountID)}
onConfirm={() => BankAccounts.resetFreePlanBankAccount(bankAccountID, session)}
shouldShowCancelButton
isVisible
/>
Expand All @@ -49,4 +57,8 @@ function WorkspaceResetBankAccountModal(props) {
WorkspaceResetBankAccountModal.displayName = 'WorkspaceResetBankAccountModal';
WorkspaceResetBankAccountModal.propTypes = propTypes;

export default withLocalize(WorkspaceResetBankAccountModal);
export default withOnyx({
session: {
key: ONYXKEYS.SESSION,
},
})(WorkspaceResetBankAccountModal);

0 comments on commit fa34d33

Please sign in to comment.