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

[CP Stag] Update logic for business bank account payment #31858

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
29 changes: 4 additions & 25 deletions src/components/AddPaymentMethodMenu.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import lodashGet from 'lodash/get';
import PropTypes from 'prop-types';
import React from 'react';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
import useLocalize from '@hooks/useLocalize';
import compose from '@libs/compose';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import * as ReportUtils from '@libs/ReportUtils';
import iouReportPropTypes from '@pages/iouReportPropTypes';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import * as Expensicons from './Icon/Expensicons';
import PopoverMenu from './PopoverMenu';
import refPropTypes from './refPropTypes';
Expand Down Expand Up @@ -42,12 +37,6 @@ const propTypes = {

/** Popover anchor ref */
anchorRef: refPropTypes,

/** Session info for the currently logged in user. */
session: PropTypes.shape({
/** Currently logged in user accountID */
accountID: PropTypes.number,
}),
};

const defaultProps = {
Expand All @@ -58,10 +47,9 @@ const defaultProps = {
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM,
},
anchorRef: () => {},
session: {},
};

function AddPaymentMethodMenu({isVisible, onClose, anchorPosition, anchorAlignment, anchorRef, iouReport, onItemSelected, session}) {
function AddPaymentMethodMenu({isVisible, onClose, anchorPosition, anchorAlignment, anchorRef, iouReport, onItemSelected}) {
const {translate} = useLocalize();

return (
Expand All @@ -78,13 +66,11 @@ function AddPaymentMethodMenu({isVisible, onClose, anchorPosition, anchorAlignme
{
text: translate('common.personalBankAccount'),
icon: Expensicons.Bank,
onSelected: () => {
onItemSelected(CONST.PAYMENT_METHODS.PERSONAL_BANK_ACCOUNT);
},
onSelected: () => onItemSelected(CONST.PAYMENT_METHODS.PERSONAL_BANK_ACCOUNT),
},
]
: []),
...(!ReportActionsUtils.hasRequestFromCurrentAccount(lodashGet(iouReport, 'reportID', 0), lodashGet(session, 'accountID', 0))
...(ReportUtils.isExpenseReport(iouReport)
? [
Comment on lines -87 to +73
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not desired fix, we need this method in place so we can show the Bussiness bank account option in case of IOUs when there is only "one direction"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see! Thanks for clarifying!

{
text: translate('common.businessBankAccount'),
Expand All @@ -110,11 +96,4 @@ AddPaymentMethodMenu.propTypes = propTypes;
AddPaymentMethodMenu.defaultProps = defaultProps;
AddPaymentMethodMenu.displayName = 'AddPaymentMethodMenu';

export default compose(
withWindowDimensions,
withOnyx({
session: {
key: ONYXKEYS.SESSION,
},
}),
)(AddPaymentMethodMenu);
export default withWindowDimensions(AddPaymentMethodMenu);
21 changes: 0 additions & 21 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -631,26 +631,6 @@ function isNotifiableReportAction(reportAction: OnyxEntry<ReportAction>): boolea
return actions.includes(reportAction.actionName);
}

/**
* Helper method to determine if the provided accountID has made a request on the specified report.
*
* @param reportID
* @param currentAccountID
* @returns
*/
function hasRequestFromCurrentAccount(reportID: string, currentAccountID: number): boolean {
if (!reportID) {
return false;
}

const reportActions = Object.values(getAllReportActions(reportID));
if (reportActions.length === 0) {
return false;
}

return reportActions.some((action) => action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && action.actorAccountID === currentAccountID);
}

export {
extractLinksFromMessageHtml,
getAllReportActions,
Expand Down Expand Up @@ -691,7 +671,6 @@ export {
isReimbursementQueuedAction,
shouldReportActionBeVisible,
shouldReportActionBeVisibleAsLastAction,
hasRequestFromCurrentAccount,
getFirstVisibleReportActionID,
isChannelLogMemberAction,
};
Loading