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

Only show settlement button if total is not 0 #23828

Merged
merged 5 commits into from
Aug 2, 2023
Merged
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
5 changes: 3 additions & 2 deletions src/components/MoneyReportHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ function MoneyReportHeader(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 && isPayer && !moneyRequestReport.isWaitingOnBankAccount;
const reportTotal = ReportUtils.getMoneyRequestTotal(props.report);
const shouldShowSettlementButton = !isSettled && isPayer && !moneyRequestReport.isWaitingOnBankAccount && reportTotal !== 0;
const bankAccountRoute = ReportUtils.getBankAccountRoute(props.chatReport);
const shouldShowPaypal = Boolean(lodashGet(props.personalDetails, [moneyRequestReport.managerID, 'payPalMeAddress']));
const formattedAmount = CurrencyUtils.convertToDisplayString(ReportUtils.getMoneyRequestTotal(props.report), props.report.currency);
const formattedAmount = CurrencyUtils.convertToDisplayString(reportTotal, props.report.currency);

return (
<View style={[styles.pt0]}>
Expand Down
6 changes: 4 additions & 2 deletions src/components/MoneyRequestDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ function MoneyRequestDetails(props) {
const transactionDate = lodashGet(props.parentReportAction, ['created']);
const formattedTransactionDate = DateUtils.getDateStringFromISOTimestamp(transactionDate);

const formattedAmount = CurrencyUtils.convertToDisplayString(ReportUtils.getMoneyRequestTotal(props.report), props.report.currency);
const reportTotal = ReportUtils.getMoneyRequestTotal(props.report);
const formattedAmount = CurrencyUtils.convertToDisplayString(reportTotal, props.report.currency);
const moneyRequestReport = props.isSingleTransactionView ? props.parentReport : props.report;
const isSettled = ReportUtils.isSettled(moneyRequestReport.reportID);
const isExpenseReport = ReportUtils.isExpenseReport(moneyRequestReport);
Expand All @@ -89,7 +90,8 @@ function MoneyRequestDetails(props) {
: UserUtils.getAvatar(lodashGet(props.personalDetails, [moneyRequestReport.managerID, 'avatar']), moneyRequestReport.managerID);
const isPayer =
Policy.isAdminOfFreePolicy([props.policy]) || (ReportUtils.isMoneyRequestReport(moneyRequestReport) && lodashGet(props.session, 'accountID', null) === moneyRequestReport.managerID);
const shouldShowSettlementButton = moneyRequestReport.reportID && !isSettled && !props.isSingleTransactionView && isPayer && !moneyRequestReport.isWaitingOnBankAccount;
const shouldShowSettlementButton =
moneyRequestReport.reportID && !isSettled && !props.isSingleTransactionView && isPayer && !moneyRequestReport.isWaitingOnBankAccount && reportTotal !== 0;
const bankAccountRoute = ReportUtils.getBankAccountRoute(props.chatReport);
const shouldShowPaypal = Boolean(lodashGet(props.personalDetails, [moneyRequestReport.ownerAccountID, 'payPalMeAddress']));
let description = `${props.translate('iou.amount')} • ${props.translate('iou.cash')}`;
Expand Down
18 changes: 10 additions & 8 deletions src/components/ReportActionItem/ReportPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,25 +95,27 @@ const defaultProps = {
function ReportPreview(props) {
const managerID = props.iouReport.managerID || props.action.actorAccountID || 0;
const isCurrentUserManager = managerID === lodashGet(props.session, 'accountID');
let reportAmount = ReportUtils.getMoneyRequestTotal(props.iouReport);
if (reportAmount) {
reportAmount = CurrencyUtils.convertToDisplayString(reportAmount, props.iouReport.currency);
const reportTotal = ReportUtils.getMoneyRequestTotal(props.iouReport);
let displayAmount;
if (reportTotal) {
displayAmount = CurrencyUtils.convertToDisplayString(reportTotal, props.iouReport.currency);
} else {
// If iouReport is not available, get amount from the action message (Ex: "Domain20821's Workspace owes $33.00" or "paid ₫60" or "paid -₫60 elsewhere")
reportAmount = '';
displayAmount = '';
const actionMessage = lodashGet(props.action, ['message', 0, 'text'], '');
const splits = actionMessage.split(' ');
for (let i = 0; i < splits.length; i++) {
if (/\d/.test(splits[i])) {
reportAmount = splits[i];
displayAmount = splits[i];
}
}
}

const managerName = ReportUtils.isPolicyExpenseChat(props.chatReport) ? ReportUtils.getPolicyName(props.chatReport) : ReportUtils.getDisplayNameForParticipant(managerID, true);
const bankAccountRoute = ReportUtils.getBankAccountRoute(props.chatReport);
const previewMessage = props.translate(ReportUtils.isSettled(props.iouReportID) || props.iouReport.isWaitingOnBankAccount ? 'iou.payerPaid' : 'iou.payerOwes', {payer: managerName});

const shouldShowSettlementButton =
!_.isEmpty(props.iouReport) && isCurrentUserManager && !ReportUtils.isSettled(props.iouReportID) && !props.iouReport.isWaitingOnBankAccount && reportTotal !== 0;
return (
<View style={[styles.chatItemMessage, ...props.containerStyles]}>
<PressableWithoutFeedback
Expand All @@ -135,7 +137,7 @@ function ReportPreview(props) {
</View>
<View style={styles.flexRow}>
<View style={[styles.flex1, styles.flexRow, styles.alignItemsCenter]}>
<Text style={styles.textHeadline}>{reportAmount}</Text>
<Text style={styles.textHeadline}>{displayAmount}</Text>
{ReportUtils.isSettled(props.iouReportID) && (
<View style={styles.defaultCheckmarkWrapper}>
<Icon
Expand All @@ -146,7 +148,7 @@ function ReportPreview(props) {
)}
</View>
</View>
{!_.isEmpty(props.iouReport) && isCurrentUserManager && !ReportUtils.isSettled(props.iouReportID) && !props.iouReport.isWaitingOnBankAccount && (
{shouldShowSettlementButton && (
<SettlementButton
currency={props.iouReport.currency}
policyID={props.iouReport.policyID}
Expand Down
Loading