Skip to content

Commit

Permalink
Merge pull request #39321 from FitseTLT/fix-submitted-optimistic-message
Browse files Browse the repository at this point in the history
Fix - “Submitted $amount” system message appears for a moment when Employee submit IOU
  • Loading branch information
pecanoro authored Apr 22, 2024
2 parents d084710 + e9df81b commit a9d5bec
Showing 1 changed file with 79 additions and 4 deletions.
83 changes: 79 additions & 4 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3481,6 +3481,79 @@ function buildOptimisticExpenseReport(chatReportID: string, policyID: string, pa
return expenseReport;
}

function getIOUSubmittedMessage(report: OnyxEntry<Report>) {
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)
Expand All @@ -3490,8 +3563,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)
Expand All @@ -3513,9 +3591,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;
Expand Down

0 comments on commit a9d5bec

Please sign in to comment.