From 639be9df4c35536dcc04a236ddbdbf95ea6f441e Mon Sep 17 00:00:00 2001 From: Pavlo Tsimura Date: Sat, 7 Oct 2023 01:18:20 +0200 Subject: [PATCH 1/6] Use localized message for split request Signed-off-by: Pavlo Tsimura --- src/languages/en.ts | 2 +- src/languages/es.ts | 2 +- src/languages/types.ts | 2 +- src/libs/ReportUtils.js | 7 +++++++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index 42dc255f51e..274f6bc31e4 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -534,7 +534,7 @@ export default { payElsewhere: 'Pay elsewhere', requestAmount: ({amount}: RequestAmountParams) => `request ${amount}`, requestedAmount: ({formattedAmount, comment}: RequestedAmountMessageParams) => `requested ${formattedAmount}${comment ? ` for ${comment}` : ''}`, - splitAmount: ({amount}: SplitAmountParams) => `split ${amount}`, + splitAmount: ({amount, comment}: SplitAmountParams) => `split ${amount}${comment ? ` for ${comment}` : ''}`, amountEach: ({amount}: AmountEachParams) => `${amount} each`, payerOwesAmount: ({payer, amount}: PayerOwesAmountParams) => `${payer} owes ${amount}`, payerOwes: ({payer}: PayerOwesParams) => `${payer} owes: `, diff --git a/src/languages/es.ts b/src/languages/es.ts index 0ef702ac7b7..2c091f4da1f 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -526,7 +526,7 @@ export default { payElsewhere: 'Pagar de otra forma', requestAmount: ({amount}: RequestAmountParams) => `solicitar ${amount}`, requestedAmount: ({formattedAmount, comment}: RequestedAmountMessageParams) => `solicité ${formattedAmount}${comment ? ` para ${comment}` : ''}`, - splitAmount: ({amount}: SplitAmountParams) => `dividir ${amount}`, + splitAmount: ({amount, comment}: SplitAmountParams) => `dividir ${amount}${comment ? ` para ${comment}` : ''}`, amountEach: ({amount}: AmountEachParams) => `${amount} cada uno`, payerOwesAmount: ({payer, amount}: PayerOwesAmountParams) => `${payer} debe ${amount}`, payerOwes: ({payer}: PayerOwesParams) => `${payer} debe: `, diff --git a/src/languages/types.ts b/src/languages/types.ts index 3ee504ccddd..8daf462886d 100644 --- a/src/languages/types.ts +++ b/src/languages/types.ts @@ -104,7 +104,7 @@ type RequestAmountParams = {amount: number}; type RequestedAmountMessageParams = {formattedAmount: string; comment: string}; -type SplitAmountParams = {amount: number}; +type SplitAmountParams = {amount: number; comment: string}; type AmountEachParams = {amount: number}; diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index ef9fb053309..75733594f01 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1512,6 +1512,13 @@ function getReportPreviewMessage(report, reportAction = {}, shouldConsiderReceip return reportActionMessage; } + if (!isIOUReport(report) && ReportActionsUtils.isSplitBillAction(reportAction)) { + const linkedTransaction = TransactionUtils.getLinkedTransaction(reportAction); + const {amount, currency, comment} = getTransactionDetails(linkedTransaction); + const formattedAmount = CurrencyUtils.convertToDisplayString(amount, currency) + return Localize.translateLocal('iou.splitAmount', {amount: formattedAmount, comment}); + } + const totalAmount = getMoneyRequestTotal(report); const payerName = isExpenseReport(report) ? getPolicyName(report) : getDisplayNameForParticipant(report.managerID, true); const formattedAmount = CurrencyUtils.convertToDisplayString(totalAmount, report.currency); From 852bcab6c0994127ee7beb22cc112d4fb5ca7c9f Mon Sep 17 00:00:00 2001 From: Pavlo Tsimura Date: Wed, 11 Oct 2023 09:32:15 +0200 Subject: [PATCH 2/6] Add explanatory comment --- src/libs/ReportUtils.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 75733594f01..255818b7d98 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1513,6 +1513,7 @@ function getReportPreviewMessage(report, reportAction = {}, shouldConsiderReceip } if (!isIOUReport(report) && ReportActionsUtils.isSplitBillAction(reportAction)) { + // This covers group chats where the last action is a split bill action const linkedTransaction = TransactionUtils.getLinkedTransaction(reportAction); const {amount, currency, comment} = getTransactionDetails(linkedTransaction); const formattedAmount = CurrencyUtils.convertToDisplayString(amount, currency) From 4f1af3602a499f3814004af917e58a5ab41077df Mon Sep 17 00:00:00 2001 From: Pavlo Tsimura Date: Wed, 11 Oct 2023 11:09:00 +0200 Subject: [PATCH 3/6] Prettier --- src/libs/ReportUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 255818b7d98..0ea18194871 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1516,7 +1516,7 @@ function getReportPreviewMessage(report, reportAction = {}, shouldConsiderReceip // This covers group chats where the last action is a split bill action const linkedTransaction = TransactionUtils.getLinkedTransaction(reportAction); const {amount, currency, comment} = getTransactionDetails(linkedTransaction); - const formattedAmount = CurrencyUtils.convertToDisplayString(amount, currency) + const formattedAmount = CurrencyUtils.convertToDisplayString(amount, currency); return Localize.translateLocal('iou.splitAmount', {amount: formattedAmount, comment}); } From a5e4be2c0ac29415bd2e60c016df80dedaa17b44 Mon Sep 17 00:00:00 2001 From: Pavlo Tsimura Date: Wed, 11 Oct 2023 14:55:37 +0200 Subject: [PATCH 4/6] Separate splitAmount copy to present and past form --- src/languages/en.ts | 4 +++- src/languages/es.ts | 4 +++- src/languages/types.ts | 5 ++++- src/libs/ReportUtils.js | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index 274f6bc31e4..655e86ef314 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -27,6 +27,7 @@ import type { SettleExpensifyCardParams, RequestAmountParams, SplitAmountParams, + DidSplitAmountParams, AmountEachParams, PayerOwesAmountParams, PayerOwesParams, @@ -534,7 +535,8 @@ export default { payElsewhere: 'Pay elsewhere', requestAmount: ({amount}: RequestAmountParams) => `request ${amount}`, requestedAmount: ({formattedAmount, comment}: RequestedAmountMessageParams) => `requested ${formattedAmount}${comment ? ` for ${comment}` : ''}`, - splitAmount: ({amount, comment}: SplitAmountParams) => `split ${amount}${comment ? ` for ${comment}` : ''}`, + splitAmount: ({amount}: SplitAmountParams) => `split ${amount}`, + didSplitAmount: ({amount, comment}: DidSplitAmountParams) => `split ${amount}${comment ? ` for ${comment}` : ''}`, amountEach: ({amount}: AmountEachParams) => `${amount} each`, payerOwesAmount: ({payer, amount}: PayerOwesAmountParams) => `${payer} owes ${amount}`, payerOwes: ({payer}: PayerOwesParams) => `${payer} owes: `, diff --git a/src/languages/es.ts b/src/languages/es.ts index 2c091f4da1f..246e3a0ae3a 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -27,6 +27,7 @@ import type { SettleExpensifyCardParams, RequestAmountParams, SplitAmountParams, + DidSplitAmountParams, AmountEachParams, PayerOwesAmountParams, PayerOwesParams, @@ -526,7 +527,8 @@ export default { payElsewhere: 'Pagar de otra forma', requestAmount: ({amount}: RequestAmountParams) => `solicitar ${amount}`, requestedAmount: ({formattedAmount, comment}: RequestedAmountMessageParams) => `solicité ${formattedAmount}${comment ? ` para ${comment}` : ''}`, - splitAmount: ({amount, comment}: SplitAmountParams) => `dividir ${amount}${comment ? ` para ${comment}` : ''}`, + splitAmount: ({amount}: SplitAmountParams) => `dividir ${amount}`, + didSplitAmount: ({amount, comment}: DidSplitAmountParams) => `dividió ${amount}${comment ? ` para ${comment}` : ''}`, amountEach: ({amount}: AmountEachParams) => `${amount} cada uno`, payerOwesAmount: ({payer, amount}: PayerOwesAmountParams) => `${payer} debe ${amount}`, payerOwes: ({payer}: PayerOwesParams) => `${payer} debe: `, diff --git a/src/languages/types.ts b/src/languages/types.ts index 8daf462886d..2f2ffe572d1 100644 --- a/src/languages/types.ts +++ b/src/languages/types.ts @@ -104,7 +104,9 @@ type RequestAmountParams = {amount: number}; type RequestedAmountMessageParams = {formattedAmount: string; comment: string}; -type SplitAmountParams = {amount: number; comment: string}; +type SplitAmountParams = {amount: number}; + +type DidSplitAmountParams = {amount: number; comment: string}; type AmountEachParams = {amount: number}; @@ -269,6 +271,7 @@ export type { RequestAmountParams, RequestedAmountMessageParams, SplitAmountParams, + DidSplitAmountParams, AmountEachParams, PayerOwesAmountParams, PayerOwesParams, diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 0ea18194871..10270cec436 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1517,7 +1517,7 @@ function getReportPreviewMessage(report, reportAction = {}, shouldConsiderReceip const linkedTransaction = TransactionUtils.getLinkedTransaction(reportAction); const {amount, currency, comment} = getTransactionDetails(linkedTransaction); const formattedAmount = CurrencyUtils.convertToDisplayString(amount, currency); - return Localize.translateLocal('iou.splitAmount', {amount: formattedAmount, comment}); + return Localize.translateLocal('iou.didSplitAmount', {amount: formattedAmount, comment}); } const totalAmount = getMoneyRequestTotal(report); From 23caa82c12826371a0088dff93c91ef770f1006d Mon Sep 17 00:00:00 2001 From: Pavlo Tsimura Date: Wed, 11 Oct 2023 18:06:04 +0200 Subject: [PATCH 5/6] DidSplitAmountParams message formatting Co-authored-by: Aimane Chnaif <96077027+aimane-chnaif@users.noreply.github.com> --- src/languages/en.ts | 4 ++-- src/languages/es.ts | 4 ++-- src/languages/types.ts | 4 ++-- src/libs/ReportUtils.js | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index 655e86ef314..dbd180401c3 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -27,7 +27,7 @@ import type { SettleExpensifyCardParams, RequestAmountParams, SplitAmountParams, - DidSplitAmountParams, + DidSplitAmountMessageParams, AmountEachParams, PayerOwesAmountParams, PayerOwesParams, @@ -536,7 +536,7 @@ export default { requestAmount: ({amount}: RequestAmountParams) => `request ${amount}`, requestedAmount: ({formattedAmount, comment}: RequestedAmountMessageParams) => `requested ${formattedAmount}${comment ? ` for ${comment}` : ''}`, splitAmount: ({amount}: SplitAmountParams) => `split ${amount}`, - didSplitAmount: ({amount, comment}: DidSplitAmountParams) => `split ${amount}${comment ? ` for ${comment}` : ''}`, + didSplitAmount: ({formattedAmount, comment}: DidSplitAmountMessageParams) => `split ${formattedAmount}${comment ? ` for ${comment}` : ''}`, amountEach: ({amount}: AmountEachParams) => `${amount} each`, payerOwesAmount: ({payer, amount}: PayerOwesAmountParams) => `${payer} owes ${amount}`, payerOwes: ({payer}: PayerOwesParams) => `${payer} owes: `, diff --git a/src/languages/es.ts b/src/languages/es.ts index 246e3a0ae3a..f9942e194f9 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -27,7 +27,7 @@ import type { SettleExpensifyCardParams, RequestAmountParams, SplitAmountParams, - DidSplitAmountParams, + DidSplitAmountMessageParams, AmountEachParams, PayerOwesAmountParams, PayerOwesParams, @@ -528,7 +528,7 @@ export default { requestAmount: ({amount}: RequestAmountParams) => `solicitar ${amount}`, requestedAmount: ({formattedAmount, comment}: RequestedAmountMessageParams) => `solicité ${formattedAmount}${comment ? ` para ${comment}` : ''}`, splitAmount: ({amount}: SplitAmountParams) => `dividir ${amount}`, - didSplitAmount: ({amount, comment}: DidSplitAmountParams) => `dividió ${amount}${comment ? ` para ${comment}` : ''}`, + didSplitAmount: ({formattedAmount, comment}: DidSplitAmountMessageParams) => `dividió ${formattedAmount}${comment ? ` para ${comment}` : ''}`, amountEach: ({amount}: AmountEachParams) => `${amount} cada uno`, payerOwesAmount: ({payer, amount}: PayerOwesAmountParams) => `${payer} debe ${amount}`, payerOwes: ({payer}: PayerOwesParams) => `${payer} debe: `, diff --git a/src/languages/types.ts b/src/languages/types.ts index 2f2ffe572d1..9560cd41b25 100644 --- a/src/languages/types.ts +++ b/src/languages/types.ts @@ -106,7 +106,7 @@ type RequestedAmountMessageParams = {formattedAmount: string; comment: string}; type SplitAmountParams = {amount: number}; -type DidSplitAmountParams = {amount: number; comment: string}; +type DidSplitAmountMessageParams = {formattedAmount: string; comment: string}; type AmountEachParams = {amount: number}; @@ -271,7 +271,7 @@ export type { RequestAmountParams, RequestedAmountMessageParams, SplitAmountParams, - DidSplitAmountParams, + DidSplitAmountMessageParams, AmountEachParams, PayerOwesAmountParams, PayerOwesParams, diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 10270cec436..f09bbb47d26 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1517,7 +1517,7 @@ function getReportPreviewMessage(report, reportAction = {}, shouldConsiderReceip const linkedTransaction = TransactionUtils.getLinkedTransaction(reportAction); const {amount, currency, comment} = getTransactionDetails(linkedTransaction); const formattedAmount = CurrencyUtils.convertToDisplayString(amount, currency); - return Localize.translateLocal('iou.didSplitAmount', {amount: formattedAmount, comment}); + return Localize.translateLocal('iou.didSplitAmount', {formattedAmount, comment}); } const totalAmount = getMoneyRequestTotal(report); From b948d74a5842f058e9f71550bab96289344789fe Mon Sep 17 00:00:00 2001 From: Pavlo Tsimura Date: Thu, 12 Oct 2023 20:29:36 +0200 Subject: [PATCH 6/6] Early return if the linked transaction is not found Co-authored-by: Aimane Chnaif <96077027+aimane-chnaif@users.noreply.github.com> --- src/libs/ReportUtils.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 2adb2e4942e..85ee45c8724 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1518,6 +1518,9 @@ function getReportPreviewMessage(report, reportAction = {}, shouldConsiderReceip if (!isIOUReport(report) && ReportActionsUtils.isSplitBillAction(reportAction)) { // This covers group chats where the last action is a split bill action const linkedTransaction = TransactionUtils.getLinkedTransaction(reportAction); + if (_.isEmpty(linkedTransaction)) { + return reportActionMessage; + } const {amount, currency, comment} = getTransactionDetails(linkedTransaction); const formattedAmount = CurrencyUtils.convertToDisplayString(amount, currency); return Localize.translateLocal('iou.didSplitAmount', {formattedAmount, comment});