Skip to content
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

fix-27526: Web - Fix bank account start over with google login #29167

Merged
merged 4 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {object} session
zukilover marked this conversation as resolved.
Show resolved Hide resolved
*/
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
32 changes: 22 additions & 10 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) {
zukilover marked this conversation as resolved.
Show resolved Hide resolved
const {translate} = useLocalize();
const achData = lodashGet(props.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, props.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);
Loading