From 4e11125e6862353dfc095b831501988a43d5cc1c Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Sat, 30 Mar 2024 19:00:19 +0300 Subject: [PATCH 01/10] fixed optimistic submitted report action --- src/libs/ReportUtils.ts | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 9fa28535a7a7..cc52ce559d9b 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3283,8 +3283,40 @@ 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) { + const policy = getPolicy(report?.policyID); + const ownerPersonalDetails = getPersonalDetailsForAccountID(policy?.ownerAccountID ?? 0); + const ownerDisplayName = ownerPersonalDetails?.displayName + ? `${ownerPersonalDetails.displayName} (${ownerPersonalDetails.login})` + : ownerPersonalDetails?.login ?? Localize.translateLocal('common.hidden'); + + 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: ownerDisplayName, + }, + ]; + } + const amount = type === CONST.IOU.REPORT_ACTION_TYPE.PAY ? CurrencyUtils.convertToDisplayString(getMoneyRequestSpendBreakdown(!isEmptyObject(report) ? report : null).totalDisplaySpend, currency) @@ -3306,9 +3338,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 = `requested ${amount}${comment && ` for ${comment}`}`; break; From deb453cda65cc673b73114401e27bd5db2d10403 Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Sat, 30 Mar 2024 19:16:22 +0300 Subject: [PATCH 02/10] fixed for no display name case --- src/libs/ReportUtils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index cc52ce559d9b..8194667baf75 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3290,8 +3290,8 @@ function getIOUReportActionMessage(iouReportID: string, type: string, total: num const policy = getPolicy(report?.policyID); const ownerPersonalDetails = getPersonalDetailsForAccountID(policy?.ownerAccountID ?? 0); const ownerDisplayName = ownerPersonalDetails?.displayName - ? `${ownerPersonalDetails.displayName} (${ownerPersonalDetails.login})` - : ownerPersonalDetails?.login ?? Localize.translateLocal('common.hidden'); + ? `${ownerPersonalDetails.displayName}${ownerPersonalDetails.displayName !== ownerPersonalDetails.login ? ` (${ownerPersonalDetails.login})` : ''}` + : Localize.translateLocal('common.hidden'); return [ { From 22ca301945140408ecf14281b5b540cbbe51c37f Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Sat, 30 Mar 2024 19:49:26 +0300 Subject: [PATCH 03/10] changed to policy submitsTo --- src/libs/ReportUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 8194667baf75..79fa3a775073 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3288,7 +3288,7 @@ function getIOUReportActionMessage(iouReportID: string, type: string, total: num if (type === CONST.REPORT.ACTIONS.TYPE.SUBMITTED) { const policy = getPolicy(report?.policyID); - const ownerPersonalDetails = getPersonalDetailsForAccountID(policy?.ownerAccountID ?? 0); + const ownerPersonalDetails = getPersonalDetailsForAccountID(policy?.submitsTo ?? 0); const ownerDisplayName = ownerPersonalDetails?.displayName ? `${ownerPersonalDetails.displayName}${ownerPersonalDetails.displayName !== ownerPersonalDetails.login ? ` (${ownerPersonalDetails.login})` : ''}` : Localize.translateLocal('common.hidden'); From fa1a0f8712bf35f0754adcfd91941d216a6f6c14 Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Sat, 30 Mar 2024 20:14:06 +0300 Subject: [PATCH 04/10] Add submitted to oneself case --- src/libs/ReportUtils.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 79fa3a775073..7bea7466eae1 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3289,10 +3289,14 @@ function getIOUReportActionMessage(iouReportID: string, type: string, total: num if (type === CONST.REPORT.ACTIONS.TYPE.SUBMITTED) { const policy = getPolicy(report?.policyID); const ownerPersonalDetails = getPersonalDetailsForAccountID(policy?.submitsTo ?? 0); - const ownerDisplayName = ownerPersonalDetails?.displayName - ? `${ownerPersonalDetails.displayName}${ownerPersonalDetails.displayName !== ownerPersonalDetails.login ? ` (${ownerPersonalDetails.login})` : ''}` - : Localize.translateLocal('common.hidden'); - + let ownerDisplayName: string; + if (ownerPersonalDetails?.accountID === currentUserAccountID) { + ownerDisplayName = 'yourself'; + } else { + ownerDisplayName = ownerPersonalDetails?.displayName + ? `${ownerPersonalDetails.displayName}${ownerPersonalDetails.displayName !== ownerPersonalDetails.login ? ` (${ownerPersonalDetails.login})` : ''}` + : 'Hidden'; + } return [ { type: CONST.REPORT.MESSAGE.TYPE.TEXT, From cfc0c8a167cdeb188f9abf0d1f8c07ab0a882e85 Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Sat, 30 Mar 2024 20:45:48 +0300 Subject: [PATCH 05/10] changed variable name --- src/libs/ReportUtils.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 7bea7466eae1..fbcf6b038f51 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3289,11 +3289,11 @@ function getIOUReportActionMessage(iouReportID: string, type: string, total: num if (type === CONST.REPORT.ACTIONS.TYPE.SUBMITTED) { const policy = getPolicy(report?.policyID); const ownerPersonalDetails = getPersonalDetailsForAccountID(policy?.submitsTo ?? 0); - let ownerDisplayName: string; + let submittedToDisplayName: string; if (ownerPersonalDetails?.accountID === currentUserAccountID) { - ownerDisplayName = 'yourself'; + submittedToDisplayName = 'yourself'; } else { - ownerDisplayName = ownerPersonalDetails?.displayName + submittedToDisplayName = ownerPersonalDetails?.displayName ? `${ownerPersonalDetails.displayName}${ownerPersonalDetails.displayName !== ownerPersonalDetails.login ? ` (${ownerPersonalDetails.login})` : ''}` : 'Hidden'; } @@ -3316,7 +3316,7 @@ function getIOUReportActionMessage(iouReportID: string, type: string, total: num { type: CONST.REPORT.MESSAGE.TYPE.TEXT, style: 'strong', - text: ownerDisplayName, + text: submittedToDisplayName, }, ]; } From 9ce0d6b846d2bf737fc652ace9ca9545dced0d5b Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Tue, 2 Apr 2024 12:33:57 +0300 Subject: [PATCH 06/10] implemented it into separate function --- src/libs/ReportUtils.ts | 68 ++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 0dcf3ab50d7c..ec5165f3f99a 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3275,6 +3275,41 @@ function buildOptimisticExpenseReport(chatReportID: string, policyID: string, pa return expenseReport; } +function getIOUSubmittedMessage(report: OnyxEntry) { + const policy = getPolicy(report?.policyID); + const ownerPersonalDetails = getPersonalDetailsForAccountID(policy?.submitsTo ?? 0); + let submittedToDisplayName: string; + if (ownerPersonalDetails?.accountID === currentUserAccountID) { + submittedToDisplayName = 'yourself'; + } else { + submittedToDisplayName = ownerPersonalDetails?.displayName + ? `${ownerPersonalDetails.displayName}${ownerPersonalDetails.displayName !== ownerPersonalDetails.login ? ` (${ownerPersonalDetails.login})` : ''}` + : ''; + } + 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) @@ -3288,38 +3323,7 @@ function getIOUReportActionMessage(iouReportID: string, type: string, total: num const report = getReport(iouReportID); if (type === CONST.REPORT.ACTIONS.TYPE.SUBMITTED) { - const policy = getPolicy(report?.policyID); - const ownerPersonalDetails = getPersonalDetailsForAccountID(policy?.submitsTo ?? 0); - let submittedToDisplayName: string; - if (ownerPersonalDetails?.accountID === currentUserAccountID) { - submittedToDisplayName = 'yourself'; - } else { - submittedToDisplayName = ownerPersonalDetails?.displayName - ? `${ownerPersonalDetails.displayName}${ownerPersonalDetails.displayName !== ownerPersonalDetails.login ? ` (${ownerPersonalDetails.login})` : ''}` - : 'Hidden'; - } - 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, - }, - ]; + return getIOUSubmittedMessage(!isEmptyObject(report) ? report : null); } const amount = From 8103f5a8ab00445cc378b259e821e21fea758d64 Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Tue, 2 Apr 2024 13:03:30 +0300 Subject: [PATCH 07/10] avoided double terniary --- src/libs/ReportUtils.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index ec5165f3f99a..3c3817659bde 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3281,11 +3281,12 @@ function getIOUSubmittedMessage(report: OnyxEntry) { let submittedToDisplayName: string; if (ownerPersonalDetails?.accountID === currentUserAccountID) { submittedToDisplayName = 'yourself'; + } else if (ownerPersonalDetails?.displayName) { + submittedToDisplayName = `${ownerPersonalDetails.displayName}${ownerPersonalDetails.displayName !== ownerPersonalDetails.login ? ` (${ownerPersonalDetails.login})` : ''}`; } else { - submittedToDisplayName = ownerPersonalDetails?.displayName - ? `${ownerPersonalDetails.displayName}${ownerPersonalDetails.displayName !== ownerPersonalDetails.login ? ` (${ownerPersonalDetails.login})` : ''}` - : ''; + submittedToDisplayName = ''; } + return [ { type: CONST.REPORT.MESSAGE.TYPE.TEXT, From 989ed819c63871a4bebcfac011e719bdf300b1e5 Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Tue, 2 Apr 2024 13:49:20 +0300 Subject: [PATCH 08/10] minor fix --- src/libs/ReportUtils.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 3c3817659bde..dda853389bb7 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3281,10 +3281,8 @@ function getIOUSubmittedMessage(report: OnyxEntry) { let submittedToDisplayName: string; if (ownerPersonalDetails?.accountID === currentUserAccountID) { submittedToDisplayName = 'yourself'; - } else if (ownerPersonalDetails?.displayName) { - submittedToDisplayName = `${ownerPersonalDetails.displayName}${ownerPersonalDetails.displayName !== ownerPersonalDetails.login ? ` (${ownerPersonalDetails.login})` : ''}`; } else { - submittedToDisplayName = ''; + submittedToDisplayName = `${ownerPersonalDetails.displayName ?? ''}${ownerPersonalDetails.displayName !== ownerPersonalDetails.login ? ` (${ownerPersonalDetails.login})` : ''}`; } return [ From 7fe8f611f8b94b7ff2d5366ef8639f9fbf729250 Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Wed, 3 Apr 2024 17:53:14 +0300 Subject: [PATCH 09/10] re-shuffled code implementation --- src/libs/ReportUtils.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index dda853389bb7..11aff4c3c1d2 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3278,11 +3278,9 @@ function buildOptimisticExpenseReport(chatReportID: string, policyID: string, pa function getIOUSubmittedMessage(report: OnyxEntry) { const policy = getPolicy(report?.policyID); const ownerPersonalDetails = getPersonalDetailsForAccountID(policy?.submitsTo ?? 0); - let submittedToDisplayName: string; + let submittedToDisplayName = `${ownerPersonalDetails.displayName ?? ''}${ownerPersonalDetails.displayName !== ownerPersonalDetails.login ? ` (${ownerPersonalDetails.login})` : ''}`; if (ownerPersonalDetails?.accountID === currentUserAccountID) { submittedToDisplayName = 'yourself'; - } else { - submittedToDisplayName = `${ownerPersonalDetails.displayName ?? ''}${ownerPersonalDetails.displayName !== ownerPersonalDetails.login ? ` (${ownerPersonalDetails.login})` : ''}`; } return [ From b7b53dd129075fb0c3165e64d74c23e32b1cfac5 Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Fri, 5 Apr 2024 23:44:10 +0300 Subject: [PATCH 10/10] added admin-submit case --- src/libs/ReportUtils.ts | 47 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 0c9197c1796c..2cb8b205061b 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3314,9 +3314,50 @@ function buildOptimisticExpenseReport(chatReportID: string, policyID: string, pa function getIOUSubmittedMessage(report: OnyxEntry) { const policy = getPolicy(report?.policyID); - const ownerPersonalDetails = getPersonalDetailsForAccountID(policy?.submitsTo ?? 0); - let submittedToDisplayName = `${ownerPersonalDetails.displayName ?? ''}${ownerPersonalDetails.displayName !== ownerPersonalDetails.login ? ` (${ownerPersonalDetails.login})` : ''}`; - if (ownerPersonalDetails?.accountID === currentUserAccountID) { + + 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'; }