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

Handle isWaitingOnBankAccount for IOU requests #20821

Merged
merged 77 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
cd6dba8
Handle isWaitingForBankAccount when paying request
nkuoch Jun 21, 2023
e84fc71
Handle reimbursed action
nkuoch Jun 22, 2023
c370ea9
Some cleaning
nkuoch Jun 22, 2023
0418d9a
Add translations
nkuoch Jun 27, 2023
f9a0756
New copies
nkuoch Jun 29, 2023
483a029
Merge branch 'main' into nat-iouw
nkuoch Jun 30, 2023
be5f7cc
js style
nkuoch Jun 30, 2023
a656df2
Merge branch 'main' into nat-iouw
nkuoch Jul 4, 2023
ff482ab
Use getMoneyRequestTotal for displayed amount
nkuoch Jul 4, 2023
ffdbf1a
Fix console error by adding report billing state
nkuoch Jul 4, 2023
2f1a1b2
Fix eslint
nkuoch Jul 4, 2023
f68a275
Some refactoring
nkuoch Jul 4, 2023
53717db
Use button instead of link to add a bank account
nkuoch Jul 4, 2023
7d5150f
No need to show green dot on parent report
nkuoch Jul 4, 2023
abcaacd
Small fixes from Carlos PR review
nkuoch Jul 4, 2023
4efa13b
Merge branch 'main' into nat-iouw
nkuoch Jul 4, 2023
c39b697
Fix lint
nkuoch Jul 4, 2023
3d7f396
js prettier
nkuoch Jul 4, 2023
2927f9a
Move addbankaccount button to MoneyRequestHeader and create generic R…
nkuoch Jul 5, 2023
c13502a
Fix tests and style
nkuoch Jul 5, 2023
d586383
If current user already has a iou waitingForBankAccount, prevent reus…
nkuoch Jul 7, 2023
f00bc0b
Some refactoring
nkuoch Jul 7, 2023
d440b61
Merge branch 'main' into nat-iouw
nkuoch Jul 7, 2023
67e19ad
Show green dot when admin needs to pay his own request
nkuoch Jul 7, 2023
ad9dacc
Add button back to reportAction level
nkuoch Jul 7, 2023
dc64d3f
Merge branch 'main' into nat-iouw
nkuoch Jul 7, 2023
d7ce6ce
Fix test
nkuoch Jul 7, 2023
5bc651a
prettier
nkuoch Jul 7, 2023
32acf1c
Fix tests
nkuoch Jul 7, 2023
bedc151
Rename method to hasIouWaitingOnCurrentUserBankAccount
nkuoch Jul 9, 2023
41d7bb3
Prettier
nkuoch Jul 9, 2023
b1cde86
Small fixes
nkuoch Jul 9, 2023
284ce2f
Prettier
nkuoch Jul 10, 2023
218d88a
Merge branch 'main' into nat-iouw
nkuoch Jul 11, 2023
aa2c40f
Dont show green button on chat report for isWaitingOnBankAccount case
nkuoch Jul 11, 2023
19df18a
Default report preview amount to the one from the report action if io…
nkuoch Jul 11, 2023
d8f75d5
Dont show green button on chat report for isWaitingOnBankAccount case
nkuoch Jul 11, 2023
840587d
Default report preview amount to the one from the report action if io…
nkuoch Jul 11, 2023
4449a86
Make sure we close the modal after clicking on Continue
nkuoch Jul 11, 2023
821628b
Merge branch 'main' into nat-iouw
nkuoch Jul 12, 2023
ad62d24
Fix missing iou amount
nkuoch Jul 12, 2023
4984806
Fix merge conflict
nkuoch Jul 12, 2023
77783a4
Merge branch 'nat-iouw' of github.com:Expensify/App into nat-iouw
nkuoch Jul 12, 2023
9f90c9f
prettier
nkuoch Jul 12, 2023
7f729f6
Merge branch 'vit-bumpOnyxVersion' into nat-iouw
nkuoch Jul 13, 2023
627f4cd
Merge branch 'main' into nat-iouw
nkuoch Jul 13, 2023
cae3c44
shouldShowGreenDotIndicator needs managerID in optionItem
nkuoch Jul 14, 2023
b889078
Fix unit test
nkuoch Jul 14, 2023
87eb926
Fix ioupreview amount for other types of messages
nkuoch Jul 14, 2023
4549681
Fix preview message
nkuoch Jul 14, 2023
7f1b9e7
Close modal to show report only if coming from click from button from…
nkuoch Jul 14, 2023
fbe5aed
Fix eslint
nkuoch Jul 14, 2023
caa301b
If no iouReport to get managerID from, get actorAccountID from report…
nkuoch Jul 14, 2023
cf72cc1
Update src/components/ReportActionItem/ReportPreview.js
nkuoch Jul 14, 2023
043398d
Fixes from Carlos PR review
nkuoch Jul 14, 2023
f40658c
Dont show settlement button if we dont have the ioureport
nkuoch Jul 15, 2023
bde5c68
Global create update
mountiny Jul 17, 2023
9370590
Resolve merge conflicts
mountiny Jul 17, 2023
35923fd
Merge branch 'main' into nat-iouw
mountiny Jul 17, 2023
05a7eab
Fix linter
mountiny Jul 17, 2023
e3513f5
Resolve merge conflicts
mountiny Jul 17, 2023
ba7f911
Update tests
mountiny Jul 17, 2023
40e6d86
Update the tests
mountiny Jul 17, 2023
5845661
Resolve merge conflicts
mountiny Jul 18, 2023
c1b8d6e
Remove duplicate single transaction details
mountiny Jul 18, 2023
8234369
Merge branch 'main' into nat-iouw
nkuoch Jul 19, 2023
871821f
Fix merge conflict
nkuoch Jul 19, 2023
05f270b
Fix cannot read property of null
nkuoch Jul 19, 2023
dfa3230
Revert console.log
nkuoch Jul 19, 2023
58bf070
Import underscore
nkuoch Jul 19, 2023
405f470
Merge branch 'main' into nat-iouw
nkuoch Jul 20, 2023
91a40c5
Fix merge conflict
nkuoch Jul 20, 2023
2f48cd2
Fix eslint
nkuoch Jul 20, 2023
3c45555
Merge branch 'main' into nat-iouw
nkuoch Jul 24, 2023
388d977
Fix addBankAccount button still visible after user adds a bank account
nkuoch Jul 24, 2023
1158139
Only show iou.pay, not reimbursed action to avoid duplicate message
nkuoch Jul 24, 2023
6462b40
Fix test
nkuoch Jul 25, 2023
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
2 changes: 2 additions & 0 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,8 @@ const CONST = {
TASKEDITED: 'TASKEDITED',
TASKCANCELED: 'TASKCANCELED',
IOU: 'IOU',
REIMBURSEMENTQUEUED: 'REIMBURSEMENTQUEUED',
REIMBURSED: 'REIMBURSED',
RENAMED: 'RENAMED',
CHRONOSOOOLIST: 'CHRONOSOOOLIST',
TASKCOMPLETED: 'TASKCOMPLETED',
Expand Down
2 changes: 1 addition & 1 deletion src/components/AddPlaidBankAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class AddPlaidBankAccount extends React.Component {
token={token}
onSuccess={({publicToken, metadata}) => {
Log.info('[PlaidLink] Success!');
BankAccounts.openPlaidBankAccountSelector(publicToken, metadata.institution.name, this.props.allowDebit);
BankAccounts.openPlaidBankAccountSelector(publicToken, metadata.institution.name, this.props.allowDebit, this.props.bankAccountID);
}}
onError={(error) => {
Log.hmmm('[PlaidLink] Error: ', error.message);
Expand Down
3 changes: 2 additions & 1 deletion src/components/LHNOptionsList/OptionRowLHN.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ function OptionRowLHN(props) {
!hasBrickError &&
(optionItem.isUnreadWithMention ||
(optionItem.hasOutstandingIOU && !optionItem.isIOUReportOwner) ||
(optionItem.isTaskReport && optionItem.isTaskAssignee && !optionItem.isTaskCompleted));
(optionItem.isTaskReport && optionItem.isTaskAssignee && !optionItem.isTaskCompleted) ||
(optionItem.isWaitingOnBankAccount && optionItem.isIOUReportOwner));

/**
* Show the ReportActionContextMenu modal popover.
Expand Down
11 changes: 9 additions & 2 deletions src/components/MoneyRequestHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,16 @@ function MoneyRequestHeader(props) {
const policy = props.policies[`${ONYXKEYS.COLLECTION.POLICY}${props.report.policyID}`];
const isPayer =
Policy.isAdminOfFreePolicy([policy]) || (ReportUtils.isMoneyRequestReport(moneyRequestReport) && lodashGet(props.session, 'accountID', null) === moneyRequestReport.managerID);
const shouldShowSettlementButton = !isSettled && !props.isSingleTransactionView && isPayer;
const shouldShowSettlementButton = !isSettled && !props.isSingleTransactionView && isPayer && !props.report.isWaitingOnBankAccount;
const bankAccountRoute = ReportUtils.getBankAccountRoute(props.chatReport);
const shouldShowPaypal = Boolean(lodashGet(props.personalDetails, [moneyRequestReport.managerID, 'payPalMeAddress']));
let description = `${props.translate('iou.amount')} • ${props.translate('iou.cash')}`;
if (isSettled) {
description += ` • ${props.translate('iou.settledExpensify')}`;
} else if (props.report.isWaitingOnBankAccount) {
description += ` • Waiting for credit account`;
mountiny marked this conversation as resolved.
Show resolved Hide resolved
}

return (
<View style={[{backgroundColor: themeColors.highlightBG}, styles.pl0]}>
<HeaderWithBackButton
Expand Down Expand Up @@ -185,7 +192,7 @@ function MoneyRequestHeader(props) {
title={formattedTransactionAmount}
shouldShowTitleIcon={isSettled}
titleIcon={Expensicons.Checkmark}
description={`${props.translate('iou.amount')} • ${props.translate('iou.cash')}${isSettled ? ` • ${props.translate('iou.settledExpensify')}` : ''}`}
description={description}
titleStyle={styles.newKansasLarge}
/>
<MenuItemWithTopDescription
Expand Down
10 changes: 8 additions & 2 deletions src/components/ReportActionItem/IOUPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,13 @@ function IOUPreview(props) {
return props.translate('iou.split');
}

return `${props.translate('iou.cash')}${!props.iouReport.hasOutstandingIOU ? ` • ${props.translate('iou.settledExpensify')}` : ''}`;
let msg = props.translate('iou.cash');
luacmartins marked this conversation as resolved.
Show resolved Hide resolved
if (props.iouReport.isWaitingOnBankAccount) {
msg += ` • ${props.translate('iou.pending')}`;
} else if (!props.iouReport.hasOutstandingIOU) {
msg += ` • ${props.translate('iou.settledExpensify')}`;
}
return msg;
};

const childContainer = (
Expand Down Expand Up @@ -206,7 +212,7 @@ function IOUPreview(props) {
<View style={[styles.flexRow]}>
<View style={[styles.flex1, styles.flexRow, styles.alignItemsCenter]}>
<Text style={styles.textHeadline}>{CurrencyUtils.convertToDisplayString(requestAmount, requestCurrency)}</Text>
{!props.iouReport.hasOutstandingIOU && !props.isBillSplit && (
{!props.iouReport.hasOutstandingIOU && !props.isBillSplit && !props.iouReport.isWaitingOnBankAccount && (
<View style={styles.defaultCheckmarkWrapper}>
<Icon
src={Expensicons.Checkmark}
Expand Down
2 changes: 1 addition & 1 deletion src/components/ReportActionItem/MoneyRequestAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function MoneyRequestAction(props) {
if (
!_.isEmpty(props.iouReport) &&
!_.isEmpty(props.reportActions) &&
props.chatReport.hasOutstandingIOU &&
(props.chatReport.hasOutstandingIOU || props.chatReport.isWaitingOnBankAccount) &&
props.isMostRecentIOUReportAction &&
props.action.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD &&
props.network.isOffline
Expand Down
9 changes: 7 additions & 2 deletions src/components/ReportActionItem/ReportPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import getButtonState from '../../libs/getButtonState';
import * as IOU from '../../libs/actions/IOU';
import refPropTypes from '../refPropTypes';
import PressableWithoutFeedback from '../Pressable/PressableWithoutFeedback';
import * as PersonalDetailsUtils from '../../libs/PersonalDetailsUtils';

const propTypes = {
/** All the data of the action */
Expand Down Expand Up @@ -100,6 +101,8 @@ function ReportPreview(props) {
const managerName = ReportUtils.isPolicyExpenseChat(props.chatReport) ? ReportUtils.getPolicyName(props.chatReport) : ReportUtils.getDisplayNameForParticipant(managerEmail, true);
const isCurrentUserManager = managerEmail === lodashGet(props.session, 'email', null);
const bankAccountRoute = ReportUtils.getBankAccountRoute(props.chatReport);
const submitterDisplayName = PersonalDetailsUtils.getDisplayNameOrDefault(props.personalDetailsList, [props.iouReport.ownerAccountID, 'displayName'], props.iouReport.ownerEmail);

return (
<View style={[styles.chatItemMessage]}>
{_.map(props.action.message, (message, index) => (
Expand All @@ -123,7 +126,9 @@ function ReportPreview(props) {
) : (
<View style={[styles.flexRow]}>
<Text style={[styles.chatItemMessage, styles.cursorPointer, styles.colorMuted]}>
{lodashGet(message, 'html', props.translate('iou.payerSettled', {amount: reportAmount}))}
{props.iouReport.isWaitingOnBankAccount
? `${props.translate('iou.waitingOnBankAccount', {submitterDisplayName})} ${props.translate('common.bankAccount')}`
: lodashGet(message, 'html', props.translate('iou.payerSettled', {amount: reportAmount}))}
</Text>
</View>
)}
Expand All @@ -134,7 +139,7 @@ function ReportPreview(props) {
/>
</PressableWithoutFeedback>
))}
{isCurrentUserManager && !ReportUtils.isSettled(props.iouReport.reportID) && (
{isCurrentUserManager && !ReportUtils.isSettled(props.iouReport.reportID) && !props.chatReport.isWaitingOnBankAccount && (
<SettlementButton
currency={props.iouReport.currency}
policyID={props.iouReport.policyID}
Expand Down
4 changes: 4 additions & 0 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ export default {
sendMoney: 'Send money',
pay: 'Pay',
viewDetails: 'View details',
pending: 'Pending',
settledExpensify: 'Paid',
settledElsewhere: 'Paid elsewhere',
settledPaypalMe: 'Paid using Paypal.me',
Expand All @@ -360,6 +361,9 @@ export default {
payerOwesAmount: ({payer, amount}) => `${payer} owes ${amount}`,
payerPaidAmount: ({payer, amount}) => `${payer} paid ${amount}`,
payerSettled: ({amount}) => `paid ${amount}`,
payerSettledUp: ({amount}) => `settled up ${amount}`,
mountiny marked this conversation as resolved.
Show resolved Hide resolved
waitingOnBankAccount: ({submitterDisplayName}) => `started settling up, payment is held until ${submitterDisplayName} adds a `,
afterAddedBankAccount: ({submitterDisplayName}) => `after ${submitterDisplayName} added a bank account`,
noReimbursableExpenses: 'This report has an invalid amount',
pendingConversionMessage: "Total will update when you're back online",
threadRequestReportName: ({formattedAmount, comment}) => `${formattedAmount} request${comment ? ` for ${comment}` : ''}`,
Expand Down
4 changes: 4 additions & 0 deletions src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ export default {
sendMoney: 'Enviar dinero',
pay: 'Pagar',
viewDetails: 'Ver detalles',
pending: 'Pendiente',
settledExpensify: 'Pagado',
settledElsewhere: 'Pagado de otra forma',
settledPaypalMe: 'Pagado con PayPal.me',
Expand All @@ -359,6 +360,9 @@ export default {
payerOwesAmount: ({payer, amount}) => `${payer} debe ${amount}`,
payerPaidAmount: ({payer, amount}) => `${payer} pagó ${amount}`,
payerSettled: ({amount}) => `pagó ${amount}`,
payerSettledUp: ({amount}) => `pagó ${amount}`,
waitingOnBankAccount: ({submitterDisplayName}) => `comenzó a establecerse, el pago se retiene hasta que ${submitterDisplayName} agrega una `,
afterAddedBankAccount: ({submitterDisplayName}) => `después ${submitterDisplayName} agregó una cuenta bancaria`,
noReimbursableExpenses: 'El monto de este informe es inválido',
pendingConversionMessage: 'El total se actualizará cuando estés online',
threadRequestReportName: ({formattedAmount, comment}) => `Solicitud de ${formattedAmount}${comment ? ` para ${comment}` : ''}`,
Expand Down
1 change: 1 addition & 0 deletions src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ function createOption(accountIDs, personalDetails, report, reportActions = {}, {
result.keyForList = String(report.reportID);
result.tooltipText = ReportUtils.getReportParticipantsTitle(report.participantAccountIDs || []);
result.hasOutstandingIOU = report.hasOutstandingIOU;
result.isWaitingOnBankAccount = report.isWaitingOnBankAccount;

hasMultipleParticipants = personalDetailList.length > 1 || result.isChatRoom || result.isPolicyExpenseChat;
subtitle = ReportUtils.getChatRoomSubtitle(report);
Expand Down
34 changes: 19 additions & 15 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,13 @@ function canFlagReportAction(reportAction) {
* @returns {Boolean}
*/
function isSettled(reportID) {
return !lodashGet(allReports, [`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, 'hasOutstandingIOU']);
const report = lodashGet(allReports, `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {});
return !report.hasOutstandingIOU && !report.isWaitingOnBankAccount;
luacmartins marked this conversation as resolved.
Show resolved Hide resolved
}

function isCurrentUserSubmitter(reportID) {
mountiny marked this conversation as resolved.
Show resolved Hide resolved
const report = lodashGet(allReports, `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {});
return report.ownerEmail === sessionEmail;
}

/**
Expand Down Expand Up @@ -916,7 +922,7 @@ function getMoneyRequestAction(reportAction = {}) {
* @returns {Number}
*/
function getMoneyRequestTotal(report, moneyRequestReports = {}) {
if (report.hasOutstandingIOU || isMoneyRequestReport(report)) {
if (report.hasOutstandingIOU || report.isWaitingOnBankAccount || isMoneyRequestReport(report)) {
const moneyRequestReport = moneyRequestReports[`${ONYXKEYS.COLLECTION.REPORT}${report.iouReportID}`] || report;
const total = lodashGet(moneyRequestReport, 'total', 0);

Expand Down Expand Up @@ -1811,20 +1817,16 @@ function isUnreadWithMention(report) {
* @returns {boolean}
*/
function hasOutstandingIOU(report, iouReports) {
if (!report || !report.iouReportID || _.isUndefined(report.hasOutstandingIOU)) {
return false;
}
mountiny marked this conversation as resolved.
Show resolved Hide resolved

const iouReport = iouReports && iouReports[`${ONYXKEYS.COLLECTION.REPORT}${report.iouReportID}`];
if (!iouReport || !iouReport.ownerAccountID) {
return false;
}
if (report.iouReportID) {
luacmartins marked this conversation as resolved.
Show resolved Hide resolved
const iouReport = iouReports && iouReports[`${ONYXKEYS.COLLECTION.REPORT}${report.iouReportID}`];
if (!iouReport || !iouReport.ownerAccountID) {
return false;
}

if (iouReport.ownerAccountID === currentUserAccountID) {
return false;
return iouReport.ownerAccountID === currentUserAccountID ? iouReport.isWaitingOnBankAccount : iouReport.hasOutstandingIOU;
}

return report.hasOutstandingIOU;
return report.ownerAccountID === currentUserAccountID ? report.isWaitingOnBankAccount : report.hasOutstandingIOU;
}

/**
Expand All @@ -1834,13 +1836,14 @@ function hasOutstandingIOU(report, iouReports) {
* @returns {Boolean}
*/
function isIOUOwnedByCurrentUser(report, iouReports = {}) {
if (report.hasOutstandingIOU) {
if (report.iouReportID) {
const iouReport = iouReports[`${ONYXKEYS.COLLECTION.REPORT}${report.iouReportID}`];
if (iouReport) {
return iouReport.ownerAccountID === currentUserAccountID;
}
}
return false;

return report.ownerAccountID === currentUserAccountID;
}

/**
Expand Down Expand Up @@ -2300,6 +2303,7 @@ export {
getIOUReportActionMessage,
getDisplayNameForParticipant,
isChatReport,
isCurrentUserSubmitter,
isExpenseReport,
isIOUReport,
isTaskReport,
Expand Down
28 changes: 21 additions & 7 deletions src/libs/SidebarUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,31 +148,38 @@ function getOrderedReportIDs(reportIDFromRoute) {

// The LHN is split into five distinct groups, and each group is sorted a little differently. The groups will ALWAYS be in this order:
// 1. Pinned - Always sorted by reportDisplayName
// 2. Outstanding IOUs - Always sorted by iouReportAmount with the largest amounts at the top of the group
// 3. Drafts - Always sorted by reportDisplayName
// 4. Non-archived reports
// 2. Waiting on bank account - Always sorted by reportDisplayName
// 3. Outstanding IOUs - Always sorted by iouReportAmount with the largest amounts at the top of the group
// 4. Drafts - Always sorted by reportDisplayName
// 5. Non-archived reports
// - Sorted by lastVisibleActionCreated in default (most recent) view mode
// - Sorted by reportDisplayName in GSD (focus) view mode
// 5. Archived reports
// 6. Archived reports
// - Sorted by lastVisibleActionCreated in default (most recent) view mode
// - Sorted by reportDisplayName in GSD (focus) view mode
let pinnedReports = [];
let outstandingIOUReports = [];
let waitingOnBankAccountReports = [];
let draftReports = [];
let nonArchivedReports = [];
let archivedReports = [];

_.each(reportsToDisplay, (report) => {
if (report.isPinned) {
pinnedReports.push(report);
return;
}

if (report.hasOutstandingIOU && !ReportUtils.isIOUOwnedByCurrentUser(report, allReports)) {
const isIOUOwnedByCurrentUser = ReportUtils.isIOUOwnedByCurrentUser(report, allReports);
if (report.hasOutstandingIOU && !isIOUOwnedByCurrentUser) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's use ReportUtils.isSettled

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No it's not the same logic - isSettled doesn't take into account the current user

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I meant instead of report.hasOutstandingIOU

outstandingIOUReports.push(report);
return;
}

if (report.isWaitingOnBankAccount && isIOUOwnedByCurrentUser) {
waitingOnBankAccountReports.push(report);
return;
}

if (report.hasDraft) {
draftReports.push(report);
return;
Expand All @@ -193,6 +200,7 @@ function getOrderedReportIDs(reportIDFromRoute) {

// Sort each group of reports accordingly
pinnedReports = _.sortBy(pinnedReports, (report) => report.displayName.toLowerCase());
waitingOnBankAccountReports = _.sortBy(waitingOnBankAccountReports, (report) => report.displayName.toLowerCase());
outstandingIOUReports = lodashOrderBy(outstandingIOUReports, ['iouReportAmount', (report) => report.displayName.toLowerCase()], ['desc', 'asc']);
draftReports = _.sortBy(draftReports, (report) => report.displayName.toLowerCase());
nonArchivedReports = isInDefaultMode
Expand All @@ -207,7 +215,10 @@ function getOrderedReportIDs(reportIDFromRoute) {

// Now that we have all the reports grouped and sorted, they must be flattened into an array and only return the reportID.
// The order the arrays are concatenated in matters and will determine the order that the groups are displayed in the sidebar.
return _.pluck([].concat(pinnedReports).concat(outstandingIOUReports).concat(draftReports).concat(nonArchivedReports).concat(archivedReports), 'reportID');
return _.pluck(
[].concat(pinnedReports).concat(waitingOnBankAccountReports).concat(outstandingIOUReports).concat(draftReports).concat(nonArchivedReports).concat(archivedReports),
'reportID',
);
}

/**
Expand Down Expand Up @@ -258,6 +269,7 @@ function getOptionData(reportID) {
shouldShowSubscript: false,
isPolicyExpenseChat: false,
isMoneyRequestReport: false,
isWaitingOnBankAccount: false,
};

const participantPersonalDetailList = _.values(OptionsListUtils.getPersonalDetailsForAccountIDs(report.participantAccountIDs, personalDetails));
Expand Down Expand Up @@ -289,6 +301,8 @@ function getOptionData(reportID) {
result.tooltipText = ReportUtils.getReportParticipantsTitle(report.participantAccountIDs || []);
result.hasOutstandingIOU = report.hasOutstandingIOU;
result.parentReportID = report.parentReportID || null;
result.isWaitingOnBankAccount = report.isWaitingOnBankAccount;

const hasMultipleParticipants = participantPersonalDetailList.length > 1 || result.isChatRoom || result.isPolicyExpenseChat;
const subtitle = ReportUtils.getChatRoomSubtitle(report);

Expand Down
4 changes: 3 additions & 1 deletion src/libs/actions/Plaid.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,16 @@ function openPlaidBankLogin(allowDebit, bankAccountID) {
* @param {String} publicToken
* @param {String} bankName
* @param {Boolean} allowDebit
* @param {Number} bankAccountID
*/
function openPlaidBankAccountSelector(publicToken, bankName, allowDebit) {
function openPlaidBankAccountSelector(publicToken, bankName, allowDebit, bankAccountID) {
API.read(
'OpenPlaidBankAccountSelector',
{
publicToken,
allowDebit,
bank: bankName,
bankAccountID,
},
{
optimisticData: [
Expand Down
11 changes: 10 additions & 1 deletion src/libs/actions/ReimbursementAccount/store.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Onyx from 'react-native-onyx';
import lodashGet from 'lodash/get';
import _ from 'underscore';
import ONYXKEYS from '../../../ONYXKEYS';
import BankAccount from '../../models/BankAccount';

/** Reimbursement account actively being set up */
let reimbursementAccountInSetup = {};
Expand Down Expand Up @@ -43,6 +45,13 @@ function getBankAccountList() {
return bankAccountList;
}

function hasCreditBankAccount() {
return _.some(bankAccountList, (bankAccountJSON) => {
const bankAccount = new BankAccount(bankAccountJSON);
return bankAccount.isDefaultCredit();
});
}

function getCredentials() {
return credentials;
}
Expand All @@ -51,4 +60,4 @@ function getReimbursementAccountWorkspaceID() {
return reimbursementAccountWorkspaceID;
}

export {getReimbursementAccountInSetup, getBankAccountList, getCredentials, getReimbursementAccountWorkspaceID};
export {getReimbursementAccountInSetup, getBankAccountList, getCredentials, getReimbursementAccountWorkspaceID, hasCreditBankAccount};
4 changes: 0 additions & 4 deletions src/pages/ReimbursementAccount/CompanyStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ class CompanyStep extends React.Component {
this.defaultWebsite = lodashGet(props, 'user.isFromPublicDomain', false) ? 'https://' : `https://www.${Str.extractEmailDomain(props.session.email, '')}`;
}

componentWillUnmount() {
BankAccounts.resetReimbursementAccount();
}

luacmartins marked this conversation as resolved.
Show resolved Hide resolved
/**
* @param {Array} fieldNames
*
Expand Down
Loading