Skip to content

Commit

Permalink
Merge pull request #23651 from Expensify/alberto-showComment
Browse files Browse the repository at this point in the history
Show comment/requests in report preview
  • Loading branch information
luacmartins authored Aug 8, 2023
2 parents fe8aeb8 + 2c0bbc7 commit 32326f6
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/components/ReportActionItem/ReportPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ const defaultProps = {
function ReportPreview(props) {
const managerID = props.iouReport.managerID || props.action.actorAccountID || 0;
const isCurrentUserManager = managerID === lodashGet(props.session, 'accountID');
const moneyRequestCount = lodashGet(props.action, 'childMoneyRequestCount', 0);
const moneyRequestComment = lodashGet(props.action, 'childLastMoneyRequestComment', '');
const showComment = moneyRequestComment || moneyRequestCount > 1;
const reportTotal = ReportUtils.getMoneyRequestTotal(props.iouReport);
let displayAmount;
if (reportTotal) {
Expand Down Expand Up @@ -148,6 +151,15 @@ function ReportPreview(props) {
)}
</View>
</View>
{showComment && (
<View style={[styles.flexRow]}>
<View style={[styles.flex1]}>
<Text style={[styles.mt1, styles.colorMuted]}>
{moneyRequestCount > 1 ? props.translate('iou.requestCount', {count: moneyRequestCount}) : moneyRequestComment}
</Text>
</View>
</View>
)}
{shouldShowSettlementButton && (
<SettlementButton
currency={props.iouReport.currency}
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ export default {
pendingConversionMessage: "Total will update when you're back online",
threadRequestReportName: ({formattedAmount, comment}) => `${formattedAmount} request${comment ? ` for ${comment}` : ''}`,
threadSentMoneyReportName: ({formattedAmount, comment}) => `${formattedAmount} sent${comment ? ` for ${comment}` : ''}`,
requestCount: ({count}) => `${count} requests`,
error: {
invalidSplit: 'Split amounts do not equal total amount',
other: 'Unexpected error, please try again later',
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ export default {
pendingConversionMessage: 'El total se actualizará cuando estés online',
threadRequestReportName: ({formattedAmount, comment}) => `Solicitud de ${formattedAmount}${comment ? ` para ${comment}` : ''}`,
threadSentMoneyReportName: ({formattedAmount, comment}) => `${formattedAmount} enviado${comment ? ` para ${comment}` : ''}`,
requestCount: ({count}) => `${count} solicitudes`,
error: {
invalidSplit: 'La suma de las partes no equivale al monto total',
other: 'Error inesperado, por favor inténtalo más tarde',
Expand Down
10 changes: 8 additions & 2 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1852,10 +1852,11 @@ function buildOptimisticIOUReportAction(
*
* @param {Object} chatReport
* @param {Object} iouReport
* @param {String} [comment] - User comment for the IOU.
*
* @returns {Object}
*/
function buildOptimisticReportPreview(chatReport, iouReport) {
function buildOptimisticReportPreview(chatReport, iouReport, comment = '') {
const message = getReportPreviewMessage(iouReport);
return {
reportActionID: NumberUtils.rand64(),
Expand All @@ -1876,6 +1877,8 @@ function buildOptimisticReportPreview(chatReport, iouReport) {
created: DateUtils.getDBTime(),
accountID: iouReport.managerID || 0,
actorAccountID: iouReport.managerID || 0,
childMoneyRequestCount: 1,
childLastMoneyRequestComment: comment,
};
}

Expand All @@ -1884,10 +1887,11 @@ function buildOptimisticReportPreview(chatReport, iouReport) {
*
* @param {Object} iouReport
* @param {Object} reportPreviewAction
* @param {String} [comment] - User comment for the IOU.
*
* @returns {Object}
*/
function updateReportPreview(iouReport, reportPreviewAction) {
function updateReportPreview(iouReport, reportPreviewAction, comment = '') {
const message = getReportPreviewMessage(iouReport, reportPreviewAction);
return {
...reportPreviewAction,
Expand All @@ -1900,6 +1904,8 @@ function updateReportPreview(iouReport, reportPreviewAction) {
type: CONST.REPORT.MESSAGE.TYPE.COMMENT,
},
],
childLastMoneyRequestComment: comment || reportPreviewAction.childLastMoneyRequestComment,
childMoneyRequestCount: reportPreviewAction.childMoneyRequestCount + 1,
};
}

Expand Down
7 changes: 5 additions & 2 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,9 @@ function requestMoney(report, amount, currency, payeeEmail, payeeAccountID, part

let reportPreviewAction = isNewIOUReport ? null : ReportActionsUtils.getReportPreviewAction(chatReport.reportID, iouReport.reportID);
if (reportPreviewAction) {
reportPreviewAction = ReportUtils.updateReportPreview(iouReport, reportPreviewAction);
reportPreviewAction = ReportUtils.updateReportPreview(iouReport, reportPreviewAction, comment);
} else {
reportPreviewAction = ReportUtils.buildOptimisticReportPreview(chatReport, iouReport);
reportPreviewAction = ReportUtils.buildOptimisticReportPreview(chatReport, iouReport, comment);
}

// STEP 5: Build Onyx Data
Expand Down Expand Up @@ -860,6 +860,9 @@ function deleteMoneyRequest(transactionID, reportAction, isSingleTransactionView
});
updatedReportPreviewAction.message[0].text = messageText;
updatedReportPreviewAction.message[0].html = messageText;
if (reportPreviewAction.childMoneyRequestCount > 0) {
updatedReportPreviewAction.childMoneyRequestCount = reportPreviewAction.childMoneyRequestCount - 1;
}
}

// STEP 5: Build Onyx data
Expand Down

0 comments on commit 32326f6

Please sign in to comment.