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

Fix - “Submitted $amount” system message appears for a moment when Employee submit IOU #39321

Merged
merged 17 commits into from
Apr 22, 2024
Merged
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
83 changes: 79 additions & 4 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3443,6 +3443,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 @@ -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)
Expand All @@ -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;
Expand Down
Loading