diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index a15e1937dbe2..bc6c4568da51 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3443,6 +3443,79 @@ function buildOptimisticExpenseReport(chatReportID: string, policyID: string, pa return expenseReport; } +function getIOUSubmittedMessage(report: OnyxEntry) { + const policy = getPolicy(report?.policyID); + + if (report?.ownerAccountID !== currentUserAccountID && policy.role === CONST.POLICY.ROLE.ADMIN) { + const ownerPersonalDetail = getPersonalDetailsForAccountID(report?.ownerAccountID ?? 0); + const ownerDisplayName = `${ownerPersonalDetail.displayName ?? ''}${ownerPersonalDetail.displayName !== ownerPersonalDetail.login ? ` (${ownerPersonalDetail.login})` : ''}`; + + return [ + { + style: 'normal', + text: 'You (on behalf of ', + type: CONST.REPORT.MESSAGE.TYPE.TEXT, + }, + { + style: 'strong', + text: ownerDisplayName, + type: CONST.REPORT.MESSAGE.TYPE.TEXT, + }, + { + style: 'normal', + text: ' via admin-submit)', + type: CONST.REPORT.MESSAGE.TYPE.TEXT, + }, + { + style: 'normal', + text: ' submitted this report', + type: CONST.REPORT.MESSAGE.TYPE.TEXT, + }, + { + style: 'normal', + text: ' to ', + type: CONST.REPORT.MESSAGE.TYPE.TEXT, + }, + { + style: 'strong', + text: 'you', + type: CONST.REPORT.MESSAGE.TYPE.TEXT, + }, + ]; + } + + const submittedToPersonalDetail = getPersonalDetailsForAccountID(policy?.submitsTo ?? 0); + let submittedToDisplayName = `${submittedToPersonalDetail.displayName ?? ''}${ + submittedToPersonalDetail.displayName !== submittedToPersonalDetail.login ? ` (${submittedToPersonalDetail.login})` : '' + }`; + if (submittedToPersonalDetail?.accountID === currentUserAccountID) { + submittedToDisplayName = 'yourself'; + } + + return [ + { + type: CONST.REPORT.MESSAGE.TYPE.TEXT, + style: 'strong', + text: 'You', + }, + { + type: CONST.REPORT.MESSAGE.TYPE.TEXT, + style: 'normal', + text: ' submitted this report', + }, + { + type: CONST.REPORT.MESSAGE.TYPE.TEXT, + style: 'normal', + text: ' to ', + }, + { + type: CONST.REPORT.MESSAGE.TYPE.TEXT, + style: 'strong', + text: submittedToDisplayName, + }, + ]; +} + /** * @param iouReportID - the report ID of the IOU report the action belongs to * @param type - IOUReportAction type. Can be oneOf(create, decline, cancel, pay, split) @@ -3452,8 +3525,13 @@ function buildOptimisticExpenseReport(chatReportID: string, policyID: string, pa * @param paymentType - IOU paymentMethodType. Can be oneOf(Elsewhere, Expensify) * @param isSettlingUp - Whether we are settling up an IOU */ -function getIOUReportActionMessage(iouReportID: string, type: string, total: number, comment: string, currency: string, paymentType = '', isSettlingUp = false): [Message] { +function getIOUReportActionMessage(iouReportID: string, type: string, total: number, comment: string, currency: string, paymentType = '', isSettlingUp = false): Message[] { const report = getReport(iouReportID); + + if (type === CONST.REPORT.ACTIONS.TYPE.SUBMITTED) { + return getIOUSubmittedMessage(!isEmptyObject(report) ? report : null); + } + const amount = type === CONST.IOU.REPORT_ACTION_TYPE.PAY ? CurrencyUtils.convertToDisplayString(getMoneyRequestSpendBreakdown(!isEmptyObject(report) ? report : null).totalDisplaySpend, currency) @@ -3475,9 +3553,6 @@ function getIOUReportActionMessage(iouReportID: string, type: string, total: num case CONST.REPORT.ACTIONS.TYPE.APPROVED: iouMessage = `approved ${amount}`; break; - case CONST.REPORT.ACTIONS.TYPE.SUBMITTED: - iouMessage = `submitted ${amount}`; - break; case CONST.IOU.REPORT_ACTION_TYPE.CREATE: iouMessage = `submitted ${amount}${comment && ` for ${comment}`}`; break;