From d77413d6ddfbd47a26a753259d9de2a77e6b4390 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Tue, 24 Oct 2023 06:20:50 +0300 Subject: [PATCH 01/16] fix: adding condition to change amount and merchant to TBD, when a transaction's waypoints were updated offline. --- src/components/ReportActionItem/MoneyRequestPreview.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/ReportActionItem/MoneyRequestPreview.js b/src/components/ReportActionItem/MoneyRequestPreview.js index 43500c731728..28e6d01476c6 100644 --- a/src/components/ReportActionItem/MoneyRequestPreview.js +++ b/src/components/ReportActionItem/MoneyRequestPreview.js @@ -173,7 +173,9 @@ function MoneyRequestPreview(props) { const shouldShowDescription = !_.isEmpty(description) && !shouldShowMerchant; const receiptImages = hasReceipt ? [ReceiptUtils.getThumbnailAndImageURIs(props.transaction)] : []; - + + const hasPendingWaypoints = lodashGet(props.transaction, 'pendingFields.waypoints', null); + const getSettledMessage = () => { if (isExpensifyCardTransaction) { return props.translate('common.done'); @@ -305,7 +307,7 @@ function MoneyRequestPreview(props) { {shouldShowMerchant && ( - {requestMerchant} + {hasPendingWaypoints ? requestMerchant.replace(/.+?(?=\s)/, props.translate('common.tbd')) : requestMerchant} )} From 15ee5ce565fc2cd63c7a295cf40d2b98943c6cdb Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Tue, 24 Oct 2023 06:23:30 +0300 Subject: [PATCH 02/16] fix: adding condition to change amount and merchant to TBD, when a transaction's waypoints were updated offline. --- src/components/ReportActionItem/MoneyRequestView.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/ReportActionItem/MoneyRequestView.js b/src/components/ReportActionItem/MoneyRequestView.js index 19f4a5b8e103..538c25166a77 100644 --- a/src/components/ReportActionItem/MoneyRequestView.js +++ b/src/components/ReportActionItem/MoneyRequestView.js @@ -99,7 +99,8 @@ function MoneyRequestView({report, betas, parentReport, policyCategories, should transactionMerchant === '' || transactionMerchant === CONST.TRANSACTION.UNKNOWN_MERCHANT || transactionMerchant === CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT; const isDistanceRequest = TransactionUtils.isDistanceRequest(transaction); let formattedTransactionAmount = transactionAmount ? CurrencyUtils.convertToDisplayString(transactionAmount, transactionCurrency) : ''; - if (isDistanceRequest && !formattedTransactionAmount) { + const hasPendingWaypoints = lodashGet(transaction, 'pendingFields.waypoints', null); + if (isDistanceRequest && (!formattedTransactionAmount || hasPendingWaypoints)) { formattedTransactionAmount = translate('common.tbd'); } const formattedOriginalAmount = transactionOriginalAmount && transactionOriginalCurrency && CurrencyUtils.convertToDisplayString(transactionOriginalAmount, transactionOriginalCurrency); @@ -206,7 +207,7 @@ function MoneyRequestView({report, betas, parentReport, policyCategories, should Date: Tue, 24 Oct 2023 06:27:59 +0300 Subject: [PATCH 03/16] fix: adding condition return the pending map when the transaction's waypoints is updated offline --- src/libs/ReceiptUtils.ts | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/libs/ReceiptUtils.ts b/src/libs/ReceiptUtils.ts index 13e8a195cccb..9005f34a2d12 100644 --- a/src/libs/ReceiptUtils.ts +++ b/src/libs/ReceiptUtils.ts @@ -35,18 +35,21 @@ function getThumbnailAndImageURIs(transaction: Transaction, receiptPath: string const isReceiptImage = Str.isImage(filename); const hasEReceipt = transaction?.hasEReceipt; + + if (!Object.hasOwn(transaction?.pendingFields ?? {}, 'waypoints')){ - if (hasEReceipt) { - return {thumbnail: null, image: ROUTES.ERECEIPT.getRoute(transaction.transactionID), transaction}; - } - - // For local files, we won't have a thumbnail yet - if (isReceiptImage && (path.startsWith('blob:') || path.startsWith('file:'))) { - return {thumbnail: null, image: path}; - } - - if (isReceiptImage) { - return {thumbnail: `${path}.1024.jpg`, image: path}; + if (hasEReceipt) { + return {thumbnail: null, image: ROUTES.ERECEIPT.getRoute(transaction.transactionID), transaction}; + } + + // For local files, we won't have a thumbnail yet + if (isReceiptImage && (path.startsWith('blob:') || path.startsWith('file:'))) { + return {thumbnail: null, image: path}; + } + + if (isReceiptImage) { + return {thumbnail: `${path}.1024.jpg`, image: path}; + } } const {fileExtension} = FileUtils.splitExtensionFromFileName(filename) as FileNameAndExtension; From 1f5b971f6e0872873b6737ac0ae1b1b804fda82c Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Tue, 24 Oct 2023 06:34:10 +0300 Subject: [PATCH 04/16] fix: formatting amount and merchant displays, if the report has one only distance request and the waypoints were modified and not yet updated to the server. --- .../ReportActionItem/ReportPreview.js | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index bdeec2640cdc..f70f82bb59b6 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -129,17 +129,23 @@ function ReportPreview(props) { const lastThreeTransactionsWithReceipts = transactionsWithReceipts.slice(-3); const lastThreeReceipts = _.map(lastThreeTransactionsWithReceipts, (transaction) => ReceiptUtils.getThumbnailAndImageURIs(transaction)); const hasNonReimbursableTransactions = ReportUtils.hasNonReimbursableTransactions(props.iouReportID); - const hasOnlyOneReceiptRequest = numberOfRequests === 1 && hasReceipts; - const previewSubtitle = hasOnlyOneReceiptRequest - ? TransactionUtils.getMerchant(transactionsWithReceipts[0]) - : props.translate('iou.requestCount', { - count: numberOfRequests, - scanningReceipts: numberOfScanningReceipts, - }); + let formattedMerchant = numberOfRequests === 1 && hasReceipts ? TransactionUtils.getMerchant(transactionsWithReceipts[0]) : null; + const hasPendingWaypoints = formattedMerchant && hasOnlyDistanceRequests && _.every(transactionsWithReceipts, (transaction) => lodashGet(transaction, 'pendingFields.waypoints', null)); + if (hasPendingWaypoints){ + formattedMerchant = formattedMerchant.replace(/.+?(?=\s)/, props.translate('common.tbd')) + } + const previewSubtitle = formattedMerchant || + props.translate('iou.requestCount', { + count: numberOfRequests, + scanningReceipts: numberOfScanningReceipts, + }); const shouldShowSubmitButton = isReportDraft && reimbursableSpend !== 0; const getDisplayAmount = () => { + if (hasPendingWaypoints){ + return props.translate('common.tbd'); + } if (totalDisplaySpend) { return CurrencyUtils.convertToDisplayString(totalDisplaySpend, props.iouReport.currency); } From 796de4bc87c427504541acbb2aaf1f46f8a23ae8 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Tue, 24 Oct 2023 08:14:24 +0300 Subject: [PATCH 05/16] refactor: making the changes look prettier --- src/components/ReportActionItem/MoneyRequestPreview.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/components/ReportActionItem/MoneyRequestPreview.js b/src/components/ReportActionItem/MoneyRequestPreview.js index 28e6d01476c6..2acc46924694 100644 --- a/src/components/ReportActionItem/MoneyRequestPreview.js +++ b/src/components/ReportActionItem/MoneyRequestPreview.js @@ -173,9 +173,9 @@ function MoneyRequestPreview(props) { const shouldShowDescription = !_.isEmpty(description) && !shouldShowMerchant; const receiptImages = hasReceipt ? [ReceiptUtils.getThumbnailAndImageURIs(props.transaction)] : []; - + const hasPendingWaypoints = lodashGet(props.transaction, 'pendingFields.waypoints', null); - + const getSettledMessage = () => { if (isExpensifyCardTransaction) { return props.translate('common.done'); @@ -224,7 +224,7 @@ function MoneyRequestPreview(props) { const getDisplayAmountText = () => { if (isDistanceRequest) { - return requestAmount ? CurrencyUtils.convertToDisplayString(requestAmount, props.transaction.currency) : props.translate('common.tbd'); + return requestAmount && !hasPendingWaypoints ? CurrencyUtils.convertToDisplayString(requestAmount, props.transaction.currency) : props.translate('common.tbd'); } if (isScanning) { @@ -307,7 +307,9 @@ function MoneyRequestPreview(props) { {shouldShowMerchant && ( - {hasPendingWaypoints ? requestMerchant.replace(/.+?(?=\s)/, props.translate('common.tbd')) : requestMerchant} + + {hasPendingWaypoints ? requestMerchant.replace(/.+?(?=\s)/, props.translate('common.tbd')) : requestMerchant} + )} From 3c6662f35c818a621bd140e83f9568366b522348 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Tue, 24 Oct 2023 08:16:34 +0300 Subject: [PATCH 06/16] refactor: making the changes a bit prettier --- src/components/ReportActionItem/ReportPreview.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index f70f82bb59b6..4cc99838c0a4 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -131,10 +131,11 @@ function ReportPreview(props) { const hasNonReimbursableTransactions = ReportUtils.hasNonReimbursableTransactions(props.iouReportID); let formattedMerchant = numberOfRequests === 1 && hasReceipts ? TransactionUtils.getMerchant(transactionsWithReceipts[0]) : null; const hasPendingWaypoints = formattedMerchant && hasOnlyDistanceRequests && _.every(transactionsWithReceipts, (transaction) => lodashGet(transaction, 'pendingFields.waypoints', null)); - if (hasPendingWaypoints){ - formattedMerchant = formattedMerchant.replace(/.+?(?=\s)/, props.translate('common.tbd')) + if (hasPendingWaypoints) { + formattedMerchant = formattedMerchant.replace(/.+?(?=\s)/, props.translate('common.tbd')); } - const previewSubtitle = formattedMerchant || + const previewSubtitle = + formattedMerchant || props.translate('iou.requestCount', { count: numberOfRequests, scanningReceipts: numberOfScanningReceipts, @@ -143,8 +144,8 @@ function ReportPreview(props) { const shouldShowSubmitButton = isReportDraft && reimbursableSpend !== 0; const getDisplayAmount = () => { - if (hasPendingWaypoints){ - return props.translate('common.tbd'); + if (hasPendingWaypoints) { + return props.translate('common.tbd'); } if (totalDisplaySpend) { return CurrencyUtils.convertToDisplayString(totalDisplaySpend, props.iouReport.currency); From 45124ffb11933bb24ab33b584afd62fd2115b248 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Tue, 24 Oct 2023 08:18:56 +0300 Subject: [PATCH 07/16] refactor: making ReceiptUtils.ts look prettier --- src/libs/ReceiptUtils.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/libs/ReceiptUtils.ts b/src/libs/ReceiptUtils.ts index 9005f34a2d12..84d13a296092 100644 --- a/src/libs/ReceiptUtils.ts +++ b/src/libs/ReceiptUtils.ts @@ -35,18 +35,17 @@ function getThumbnailAndImageURIs(transaction: Transaction, receiptPath: string const isReceiptImage = Str.isImage(filename); const hasEReceipt = transaction?.hasEReceipt; - - if (!Object.hasOwn(transaction?.pendingFields ?? {}, 'waypoints')){ + if (!Object.hasOwn(transaction?.pendingFields ?? {}, 'waypoints')) { if (hasEReceipt) { return {thumbnail: null, image: ROUTES.ERECEIPT.getRoute(transaction.transactionID), transaction}; } - + // For local files, we won't have a thumbnail yet if (isReceiptImage && (path.startsWith('blob:') || path.startsWith('file:'))) { return {thumbnail: null, image: path}; } - + if (isReceiptImage) { return {thumbnail: `${path}.1024.jpg`, image: path}; } From 717b517a5a8d3444c834f82bf131cb37cad95377 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Wed, 25 Oct 2023 12:04:56 +0300 Subject: [PATCH 08/16] Update src/libs/ReceiptUtils.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Arkadiusz ChrabÄ…szczewski --- src/libs/ReceiptUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReceiptUtils.ts b/src/libs/ReceiptUtils.ts index 84d13a296092..0fec426e3489 100644 --- a/src/libs/ReceiptUtils.ts +++ b/src/libs/ReceiptUtils.ts @@ -36,7 +36,7 @@ function getThumbnailAndImageURIs(transaction: Transaction, receiptPath: string const hasEReceipt = transaction?.hasEReceipt; - if (!Object.hasOwn(transaction?.pendingFields ?? {}, 'waypoints')) { + if (!transaction?.pendingFields?.waypoints) { if (hasEReceipt) { return {thumbnail: null, image: ROUTES.ERECEIPT.getRoute(transaction.transactionID), transaction}; } From 13ee0665059cac3bd831b587196e90f9aec75eb2 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Wed, 25 Oct 2023 12:05:27 +0300 Subject: [PATCH 09/16] Update src/components/ReportActionItem/ReportPreview.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Arkadiusz ChrabÄ…szczewski --- src/components/ReportActionItem/ReportPreview.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index 4cc99838c0a4..1d4647dd535d 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -144,7 +144,7 @@ function ReportPreview(props) { const shouldShowSubmitButton = isReportDraft && reimbursableSpend !== 0; const getDisplayAmount = () => { - if (hasPendingWaypoints) { + if (hasPendingWaypoints || hasOnlyDistanceRequests) { return props.translate('common.tbd'); } if (totalDisplaySpend) { From 8b78cc541571f6af8444272b67913c3c972c4f7f Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Thu, 26 Oct 2023 13:13:13 +0300 Subject: [PATCH 10/16] fix: reverting line due to typescript checks --- src/libs/ReceiptUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReceiptUtils.ts b/src/libs/ReceiptUtils.ts index 0fec426e3489..84d13a296092 100644 --- a/src/libs/ReceiptUtils.ts +++ b/src/libs/ReceiptUtils.ts @@ -36,7 +36,7 @@ function getThumbnailAndImageURIs(transaction: Transaction, receiptPath: string const hasEReceipt = transaction?.hasEReceipt; - if (!transaction?.pendingFields?.waypoints) { + if (!Object.hasOwn(transaction?.pendingFields ?? {}, 'waypoints')) { if (hasEReceipt) { return {thumbnail: null, image: ROUTES.ERECEIPT.getRoute(transaction.transactionID), transaction}; } From 7748f18074ffd0339aab42cb6e5086cb401bed55 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Thu, 26 Oct 2023 14:54:34 +0300 Subject: [PATCH 11/16] fix: Adding regex constant for matching the first space in a distance merchant string --- src/CONST.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/CONST.ts b/src/CONST.ts index a6106b88a532..0ccd0dbbd6e3 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -803,7 +803,7 @@ const CONST = { }, // at least 8 characters, 1 capital letter, 1 lowercase number, 1 number - PASSWORD_COMPLEXITY_REGEX_STRING: '^(?=.*[A-Z])(?=.*[0-9])(?=.*[a-z]).{8,}$', + PASSWORD_COMPLEXITY__STRING: '^(?=.*[A-Z])(?=.*[0-9])(?=.*[a-z]).{8,}$', // 6 numeric digits VALIDATE_CODE_REGEX_STRING: /^\d{6}$/, @@ -1324,6 +1324,8 @@ const CONST = { SPECIAL_CHAR: /[,/?"{}[\]()&^%;`$=#<>!*]/g, + FIRST_SPACE: /.+?(?=\s)/, + get SPECIAL_CHAR_OR_EMOJI() { return new RegExp(`[~\\n\\s]|(_\\b(?!$))|${this.SPECIAL_CHAR.source}|${this.EMOJI.source}`, 'gu'); }, From f1c3c5527e58d1230c182b3cc344f0221ac111a7 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Thu, 26 Oct 2023 14:55:41 +0300 Subject: [PATCH 12/16] refactor: Replacing raw regex with constant from CONST.ts --- src/components/ReportActionItem/MoneyRequestView.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ReportActionItem/MoneyRequestView.js b/src/components/ReportActionItem/MoneyRequestView.js index 538c25166a77..599c4cf4fcd4 100644 --- a/src/components/ReportActionItem/MoneyRequestView.js +++ b/src/components/ReportActionItem/MoneyRequestView.js @@ -207,7 +207,7 @@ function MoneyRequestView({report, betas, parentReport, policyCategories, should Date: Thu, 26 Oct 2023 14:57:12 +0300 Subject: [PATCH 13/16] refactor: Replacing raw regex with constant from CONST.ts --- src/components/ReportActionItem/ReportPreview.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index 1d4647dd535d..3f1070f9fb5d 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -132,7 +132,7 @@ function ReportPreview(props) { let formattedMerchant = numberOfRequests === 1 && hasReceipts ? TransactionUtils.getMerchant(transactionsWithReceipts[0]) : null; const hasPendingWaypoints = formattedMerchant && hasOnlyDistanceRequests && _.every(transactionsWithReceipts, (transaction) => lodashGet(transaction, 'pendingFields.waypoints', null)); if (hasPendingWaypoints) { - formattedMerchant = formattedMerchant.replace(/.+?(?=\s)/, props.translate('common.tbd')); + formattedMerchant = formattedMerchant.replace(CONST.REGEX.FIRST_SPACE, props.translate('common.tbd')); } const previewSubtitle = formattedMerchant || From 0e7faeafcca138aa56af25823052ec6551961104 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Thu, 26 Oct 2023 15:00:28 +0300 Subject: [PATCH 14/16] =?UTF-8?q?=E2=80=8C=E2=80=8Crefactor:=20Replacing?= =?UTF-8?q?=20raw=20regex=20with=20constant=20from=20CONST.ts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ReportActionItem/MoneyRequestPreview.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ReportActionItem/MoneyRequestPreview.js b/src/components/ReportActionItem/MoneyRequestPreview.js index 2acc46924694..3a2b78144e81 100644 --- a/src/components/ReportActionItem/MoneyRequestPreview.js +++ b/src/components/ReportActionItem/MoneyRequestPreview.js @@ -308,7 +308,7 @@ function MoneyRequestPreview(props) { {shouldShowMerchant && ( - {hasPendingWaypoints ? requestMerchant.replace(/.+?(?=\s)/, props.translate('common.tbd')) : requestMerchant} + {hasPendingWaypoints ? requestMerchant.replace(CONST.REGEX.FIRST_SPACE, props.translate('common.tbd')) : requestMerchant} )} From 6c50d5e2385f2ff8843c1a5802f48122c9b70cf9 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Thu, 26 Oct 2023 15:07:39 +0300 Subject: [PATCH 15/16] fix: reverting line --- src/components/ReportActionItem/ReportPreview.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index 3f1070f9fb5d..f31a70459841 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -144,7 +144,7 @@ function ReportPreview(props) { const shouldShowSubmitButton = isReportDraft && reimbursableSpend !== 0; const getDisplayAmount = () => { - if (hasPendingWaypoints || hasOnlyDistanceRequests) { + if (hasPendingWaypoints) { return props.translate('common.tbd'); } if (totalDisplaySpend) { From 3520b633bb7c4e5e544ff71ac2da1a8f6613f177 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Fri, 27 Oct 2023 21:33:57 +0300 Subject: [PATCH 16/16] fix: reverting line --- src/CONST.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CONST.ts b/src/CONST.ts index ec992261fd94..1cd11aec2116 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -803,7 +803,7 @@ const CONST = { }, // at least 8 characters, 1 capital letter, 1 lowercase number, 1 number - PASSWORD_COMPLEXITY__STRING: '^(?=.*[A-Z])(?=.*[0-9])(?=.*[a-z]).{8,}$', + PASSWORD_COMPLEXITY_REGEX_STRING: '^(?=.*[A-Z])(?=.*[0-9])(?=.*[a-z]).{8,}$', // 6 numeric digits VALIDATE_CODE_REGEX_STRING: /^\d{6}$/,