From 142c1fac0968385e95f9b1a6d1d21c54639c0341 Mon Sep 17 00:00:00 2001 From: Artem Makushov Date: Tue, 5 Dec 2023 00:23:48 +0100 Subject: [PATCH 01/13] merchant update --- src/components/MoneyRequestConfirmationList.js | 10 ++++++++-- src/libs/actions/IOU.js | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/components/MoneyRequestConfirmationList.js b/src/components/MoneyRequestConfirmationList.js index 1b4967a9c54c..43eabe31c79a 100755 --- a/src/components/MoneyRequestConfirmationList.js +++ b/src/components/MoneyRequestConfirmationList.js @@ -496,7 +496,7 @@ function MoneyRequestConfirmationList(props) { } const shouldShowSettlementButton = props.iouType === CONST.IOU.TYPE.SEND; - const shouldDisableButton = selectedParticipants.length === 0; + const shouldDisableButton = selectedParticipants.length === 0 || (props.isPolicyExpenseChat && !props.iouMerchant); const button = shouldShowSettlementButton ? ( )} {shouldShowCategories && ( diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index d9de984ad12c..7e29e46695b3 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -101,7 +101,7 @@ function resetMoneyRequestInfo(id = '') { currency: lodashGet(currentUserPersonalDetails, 'localCurrencyCode', CONST.CURRENCY.USD), comment: '', participants: [], - merchant: CONST.TRANSACTION.DEFAULT_MERCHANT, + merchant: '', category: '', tag: '', created, From 58f34d4275ca981d33f8fa3eeb54a11c0f60e35a Mon Sep 17 00:00:00 2001 From: Artem Makushov Date: Wed, 6 Dec 2023 14:24:30 +0100 Subject: [PATCH 02/13] fix --- src/components/MoneyRequestConfirmationList.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/components/MoneyRequestConfirmationList.js b/src/components/MoneyRequestConfirmationList.js index 43eabe31c79a..0e09388c4ac7 100755 --- a/src/components/MoneyRequestConfirmationList.js +++ b/src/components/MoneyRequestConfirmationList.js @@ -267,6 +267,8 @@ function MoneyRequestConfirmationList(props) { return (props.hasSmartScanFailed && TransactionUtils.hasMissingSmartscanFields(transaction)) || (didConfirmSplit && TransactionUtils.areRequiredFieldsEmpty(transaction)); }, [props.isEditingSplitBill, props.hasSmartScanFailed, transaction, didConfirmSplit]); + const isIOUMerchantPresent = props.isPolicyExpenseChat && !props.iouMerchant; + useEffect(() => { if (shouldDisplayFieldError && props.hasSmartScanFailed) { setFormError('iou.receiptScanningFailed'); @@ -496,7 +498,7 @@ function MoneyRequestConfirmationList(props) { } const shouldShowSettlementButton = props.iouType === CONST.IOU.TYPE.SEND; - const shouldDisableButton = selectedParticipants.length === 0 || (props.isPolicyExpenseChat && !props.iouMerchant); + const shouldDisableButton = selectedParticipants.length === 0 || isIOUMerchantPresent; const button = shouldShowSettlementButton ? ( )} {shouldShowCategories && ( From 7fcc36ead371dc78b2bedac1b39eaab73fb5c991 Mon Sep 17 00:00:00 2001 From: Artem Makushov Date: Wed, 6 Dec 2023 21:01:33 +0100 Subject: [PATCH 03/13] fix lint --- src/components/MoneyRequestConfirmationList.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/MoneyRequestConfirmationList.js b/src/components/MoneyRequestConfirmationList.js index 0e09388c4ac7..d2d8e381bba3 100755 --- a/src/components/MoneyRequestConfirmationList.js +++ b/src/components/MoneyRequestConfirmationList.js @@ -545,12 +545,11 @@ function MoneyRequestConfirmationList(props) { }, [ props.isReadOnly, props.iouType, - props.isPolicyExpenseChat, - props.iouMerchant, props.bankAccountRoute, props.iouCurrencyCode, props.policyID, selectedParticipants.length, + isIOUMerchantPresent, confirm, splitOrRequestOptions, formError, From 3a81ea41d5c8b1d763e8b1a80c072462e5369ea3 Mon Sep 17 00:00:00 2001 From: Artem Makushov Date: Thu, 7 Dec 2023 15:01:36 +0100 Subject: [PATCH 04/13] remove require for smart scan --- src/components/MoneyRequestConfirmationList.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/MoneyRequestConfirmationList.js b/src/components/MoneyRequestConfirmationList.js index d2d8e381bba3..33c049b45265 100755 --- a/src/components/MoneyRequestConfirmationList.js +++ b/src/components/MoneyRequestConfirmationList.js @@ -267,7 +267,7 @@ function MoneyRequestConfirmationList(props) { return (props.hasSmartScanFailed && TransactionUtils.hasMissingSmartscanFields(transaction)) || (didConfirmSplit && TransactionUtils.areRequiredFieldsEmpty(transaction)); }, [props.isEditingSplitBill, props.hasSmartScanFailed, transaction, didConfirmSplit]); - const isIOUMerchantPresent = props.isPolicyExpenseChat && !props.iouMerchant; + const isIOUMerchantPresent = props.isPolicyExpenseChat && !props.isScanRequest && !props.iouMerchant; useEffect(() => { if (shouldDisplayFieldError && props.hasSmartScanFailed) { From c583248e46a710b27696ad5ca6cba1e7534d2cab Mon Sep 17 00:00:00 2001 From: Artem Makushov Date: Tue, 12 Dec 2023 15:21:54 +0100 Subject: [PATCH 05/13] update ('none') display --- .../MoneyRequestConfirmationList.js | 11 ++++---- .../ReportActionItem/MoneyRequestView.js | 2 +- src/libs/actions/IOU.js | 2 +- src/pages/EditRequestMerchantPage.js | 27 +++++++++++-------- src/pages/EditRequestPage.js | 5 ++++ src/pages/iou/MoneyRequestMerchantPage.js | 4 ++- 6 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/components/MoneyRequestConfirmationList.js b/src/components/MoneyRequestConfirmationList.js index 33c049b45265..cd2215f0c7fb 100755 --- a/src/components/MoneyRequestConfirmationList.js +++ b/src/components/MoneyRequestConfirmationList.js @@ -267,7 +267,8 @@ function MoneyRequestConfirmationList(props) { return (props.hasSmartScanFailed && TransactionUtils.hasMissingSmartscanFields(transaction)) || (didConfirmSplit && TransactionUtils.areRequiredFieldsEmpty(transaction)); }, [props.isEditingSplitBill, props.hasSmartScanFailed, transaction, didConfirmSplit]); - const isIOUMerchantPresent = props.isPolicyExpenseChat && !props.isScanRequest && !props.iouMerchant; + const isMerchantEmpty = !props.iouMerchant || props.iouMerchant === CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT || props.iouMerchant === CONST.TRANSACTION.DEFAULT_MERCHANT; + const shouldDisplayMerchantError = props.isPolicyExpenseChat && !props.isScanRequest && isMerchantEmpty; useEffect(() => { if (shouldDisplayFieldError && props.hasSmartScanFailed) { @@ -498,7 +499,7 @@ function MoneyRequestConfirmationList(props) { } const shouldShowSettlementButton = props.iouType === CONST.IOU.TYPE.SEND; - const shouldDisableButton = selectedParticipants.length === 0 || isIOUMerchantPresent; + const shouldDisableButton = selectedParticipants.length === 0 || shouldDisplayMerchantError; const button = shouldShowSettlementButton ? ( )} {shouldShowCategories && ( diff --git a/src/components/ReportActionItem/MoneyRequestView.js b/src/components/ReportActionItem/MoneyRequestView.js index 0249a9f5bb11..f2abcaa06222 100644 --- a/src/components/ReportActionItem/MoneyRequestView.js +++ b/src/components/ReportActionItem/MoneyRequestView.js @@ -232,7 +232,7 @@ function MoneyRequestView({report, parentReport, policyCategories, shouldShowHor { - const errors = {}; - - if (_.isEmpty(value.merchant)) { - errors.merchant = 'common.error.fieldRequired'; - } - - return errors; - }, []); + const validate = useCallback( + (value) => { + const errors = {}; + if (_.isEmpty(value.merchant) && isPolicyExpenseChat) { + errors.merchant = 'common.error.fieldRequired'; + } + return errors; + }, + [isPolicyExpenseChat], + ); return ( { // In case the merchant hasn't been changed, do not make the API request. if (transactionChanges.merchant.trim() === transactionMerchant) { Navigation.dismissModal(); return; } + if (transactionChanges.merchant.trim() === '') { + editMoneyRequest({merchant: CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT}); + return; + } editMoneyRequest({merchant: transactionChanges.merchant.trim()}); }} /> diff --git a/src/pages/iou/MoneyRequestMerchantPage.js b/src/pages/iou/MoneyRequestMerchantPage.js index 2c5869dfa7a3..e181e0cce0cd 100644 --- a/src/pages/iou/MoneyRequestMerchantPage.js +++ b/src/pages/iou/MoneyRequestMerchantPage.js @@ -48,11 +48,13 @@ const defaultProps = { }; function MoneyRequestMerchantPage({iou, route}) { + console.log('iou :>> ', iou); const styles = useThemeStyles(); const {translate} = useLocalize(); const {inputCallbackRef} = useAutoFocusInput(); const iouType = lodashGet(route, 'params.iouType', ''); const reportID = lodashGet(route, 'params.reportID', ''); + const isEmptyMerchant = iou.merchant === '' || iou.merchant === CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT || iou.merchant === CONST.TRANSACTION.DEFAULT_MERCHANT; useEffect(() => { const moneyRequestId = `${iouType}${reportID}`; @@ -114,7 +116,7 @@ function MoneyRequestMerchantPage({iou, route}) { InputComponent={TextInput} inputID="moneyRequestMerchant" name="moneyRequestMerchant" - defaultValue={iou.merchant} + defaultValue={isEmptyMerchant ? '' : iou.merchant} maxLength={CONST.MERCHANT_NAME_MAX_LENGTH} label={translate('common.merchant')} accessibilityLabel={translate('common.merchant')} From f696242251356d4bccfc2834a4c9df08f95b6c56 Mon Sep 17 00:00:00 2001 From: Artem Makushov Date: Tue, 12 Dec 2023 17:27:22 +0100 Subject: [PATCH 06/13] lint fix --- src/pages/iou/MoneyRequestMerchantPage.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/iou/MoneyRequestMerchantPage.js b/src/pages/iou/MoneyRequestMerchantPage.js index e181e0cce0cd..f469992ea074 100644 --- a/src/pages/iou/MoneyRequestMerchantPage.js +++ b/src/pages/iou/MoneyRequestMerchantPage.js @@ -48,7 +48,6 @@ const defaultProps = { }; function MoneyRequestMerchantPage({iou, route}) { - console.log('iou :>> ', iou); const styles = useThemeStyles(); const {translate} = useLocalize(); const {inputCallbackRef} = useAutoFocusInput(); From 619f92953364356bbd8d83494e7fd5cd4653d243 Mon Sep 17 00:00:00 2001 From: Artem Makushov Date: Thu, 14 Dec 2023 15:27:48 +0100 Subject: [PATCH 07/13] updates --- src/components/MoneyRequestConfirmationList.js | 2 +- src/pages/EditRequestMerchantPage.js | 2 +- src/pages/EditRequestPage.js | 1 + src/pages/iou/MoneyRequestMerchantPage.js | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/components/MoneyRequestConfirmationList.js b/src/components/MoneyRequestConfirmationList.js index cd2215f0c7fb..7d36efa08d1e 100755 --- a/src/components/MoneyRequestConfirmationList.js +++ b/src/components/MoneyRequestConfirmationList.js @@ -267,7 +267,7 @@ function MoneyRequestConfirmationList(props) { return (props.hasSmartScanFailed && TransactionUtils.hasMissingSmartscanFields(transaction)) || (didConfirmSplit && TransactionUtils.areRequiredFieldsEmpty(transaction)); }, [props.isEditingSplitBill, props.hasSmartScanFailed, transaction, didConfirmSplit]); - const isMerchantEmpty = !props.iouMerchant || props.iouMerchant === CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT || props.iouMerchant === CONST.TRANSACTION.DEFAULT_MERCHANT; + const isMerchantEmpty = !props.iouMerchant || props.iouMerchant === CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT; const shouldDisplayMerchantError = props.isPolicyExpenseChat && !props.isScanRequest && isMerchantEmpty; useEffect(() => { diff --git a/src/pages/EditRequestMerchantPage.js b/src/pages/EditRequestMerchantPage.js index 82ac20979594..d769e69a1c3d 100644 --- a/src/pages/EditRequestMerchantPage.js +++ b/src/pages/EditRequestMerchantPage.js @@ -32,7 +32,7 @@ function EditRequestMerchantPage({defaultMerchant, onSubmit, isPolicyExpenseChat const validate = useCallback( (value) => { const errors = {}; - if (_.isEmpty(value.merchant) && isPolicyExpenseChat) { + if (_.isEmpty(value.merchant) && value.merchant.trim() === '' && isPolicyExpenseChat) { errors.merchant = 'common.error.fieldRequired'; } return errors; diff --git a/src/pages/EditRequestPage.js b/src/pages/EditRequestPage.js index 918337593583..bf6ac9f0c5fc 100644 --- a/src/pages/EditRequestPage.js +++ b/src/pages/EditRequestPage.js @@ -193,6 +193,7 @@ function EditRequestPage({report, route, parentReport, policyCategories, policyT Navigation.dismissModal(); return; } + // This is possible only in case of IOU requests. if (transactionChanges.merchant.trim() === '') { editMoneyRequest({merchant: CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT}); return; diff --git a/src/pages/iou/MoneyRequestMerchantPage.js b/src/pages/iou/MoneyRequestMerchantPage.js index f469992ea074..6aeaa81907c3 100644 --- a/src/pages/iou/MoneyRequestMerchantPage.js +++ b/src/pages/iou/MoneyRequestMerchantPage.js @@ -53,7 +53,7 @@ function MoneyRequestMerchantPage({iou, route}) { const {inputCallbackRef} = useAutoFocusInput(); const iouType = lodashGet(route, 'params.iouType', ''); const reportID = lodashGet(route, 'params.reportID', ''); - const isEmptyMerchant = iou.merchant === '' || iou.merchant === CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT || iou.merchant === CONST.TRANSACTION.DEFAULT_MERCHANT; + const isEmptyMerchant = iou.merchant === '' || iou.merchant === CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT; useEffect(() => { const moneyRequestId = `${iouType}${reportID}`; From 525fc0124e3979ea6d179152670727c9e31c4d72 Mon Sep 17 00:00:00 2001 From: Artem Makushov Date: Mon, 18 Dec 2023 23:07:04 +0100 Subject: [PATCH 08/13] updated new stepper --- ...oraryForRefactorRequestConfirmationList.js | 25 ++++++++++++++++--- src/libs/TransactionUtils.ts | 2 +- src/libs/actions/IOU.js | 1 + .../request/step/IOURequestStepMerchant.js | 3 ++- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js index d5e9fc8d1e39..56ed0b06d04f 100755 --- a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js +++ b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js @@ -297,6 +297,9 @@ function MoneyTemporaryForRefactorRequestConfirmationList({ return (hasSmartScanFailed && TransactionUtils.hasMissingSmartscanFields(transaction)) || (didConfirmSplit && TransactionUtils.areRequiredFieldsEmpty(transaction)); }, [isEditingSplitBill, hasSmartScanFailed, transaction, didConfirmSplit]); + const isMerchantEmpty = !iouMerchant || iouMerchant === CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT; + const shouldDisplayMerchantError = isPolicyExpenseChat && !isScanRequest && isMerchantEmpty; + useEffect(() => { if (shouldDisplayFieldError && hasSmartScanFailed) { setFormError('iou.receiptScanningFailed'); @@ -515,7 +518,7 @@ function MoneyTemporaryForRefactorRequestConfirmationList({ } const shouldShowSettlementButton = iouType === CONST.IOU.TYPE.SEND; - const shouldDisableButton = selectedParticipants.length === 0; + const shouldDisableButton = selectedParticipants.length === 0 || shouldDisplayMerchantError; const button = shouldShowSettlementButton ? ( ); - }, [confirm, bankAccountRoute, iouCurrencyCode, iouType, isReadOnly, policyID, selectedParticipants, splitOrRequestOptions, translate, formError, styles.ph1, styles.mb2]); + }, [ + isReadOnly, + iouType, + selectedParticipants.length, + shouldDisplayMerchantError, + confirm, + bankAccountRoute, + iouCurrencyCode, + policyID, + splitOrRequestOptions, + formError, + styles.ph1, + styles.mb2, + translate, + ]); const {image: receiptImage, thumbnail: receiptThumbnail} = receiptPath && receiptFilename ? ReceiptUtils.getThumbnailAndImageURIs(transaction, receiptPath, receiptFilename) : {}; return ( @@ -691,7 +708,7 @@ function MoneyTemporaryForRefactorRequestConfirmationList({ {shouldShowMerchant && ( )} {shouldShowCategories && ( diff --git a/src/libs/TransactionUtils.ts b/src/libs/TransactionUtils.ts index 232c30658838..dbaf887ca791 100644 --- a/src/libs/TransactionUtils.ts +++ b/src/libs/TransactionUtils.ts @@ -107,7 +107,7 @@ function buildOptimisticTransaction( currency, reportID, comment: commentJSON, - merchant: merchant || CONST.TRANSACTION.DEFAULT_MERCHANT, + merchant: merchant || CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT, created: created || DateUtils.getDBTime(), pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, receipt, diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index dbe9194a3c5a..8a0e4ee1d900 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -159,6 +159,7 @@ function startMoneyRequest_temporaryForRefactor(reportID, isFromGlobalCreate, io reportID, transactionID: newTransactionID, isFromGlobalCreate, + merchant: CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT, }); } diff --git a/src/pages/iou/request/step/IOURequestStepMerchant.js b/src/pages/iou/request/step/IOURequestStepMerchant.js index 3234b6046f31..355bb76b89b0 100644 --- a/src/pages/iou/request/step/IOURequestStepMerchant.js +++ b/src/pages/iou/request/step/IOURequestStepMerchant.js @@ -41,6 +41,7 @@ function IOURequestStepMerchant({ const styles = useThemeStyles(); const {translate} = useLocalize(); const {inputCallbackRef} = useAutoFocusInput(); + const isEmptyMerchant = merchant === '' || merchant === CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT; const navigateBack = () => { Navigation.goBack(backTo || ROUTES.HOME); @@ -89,7 +90,7 @@ function IOURequestStepMerchant({ InputComponent={TextInput} inputID="moneyRequestMerchant" name="moneyRequestMerchant" - defaultValue={merchant} + defaultValue={isEmptyMerchant ? '' : merchant} maxLength={CONST.MERCHANT_NAME_MAX_LENGTH} label={translate('common.merchant')} accessibilityLabel={translate('common.merchant')} From b04dc7ea41269a7027f472623384e226e33e447a Mon Sep 17 00:00:00 2001 From: Artem Makushov Date: Thu, 21 Dec 2023 14:32:36 +0100 Subject: [PATCH 09/13] change default merchant value in tests --- tests/actions/IOUTest.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/actions/IOUTest.js b/tests/actions/IOUTest.js index 97c1bf35732f..dd45c7b60f15 100644 --- a/tests/actions/IOUTest.js +++ b/tests/actions/IOUTest.js @@ -313,7 +313,7 @@ describe('actions/IOU', () => { // The comment should be correct expect(transaction.comment.comment).toBe(comment); - expect(transaction.merchant).toBe(CONST.TRANSACTION.DEFAULT_MERCHANT); + expect(transaction.merchant).toBe(CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT); // It should be pending expect(transaction.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); @@ -497,7 +497,7 @@ describe('actions/IOU', () => { expect(newTransaction.reportID).toBe(iouReportID); expect(newTransaction.amount).toBe(amount); expect(newTransaction.comment.comment).toBe(comment); - expect(newTransaction.merchant).toBe(CONST.TRANSACTION.DEFAULT_MERCHANT); + expect(newTransaction.merchant).toBe(CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT); expect(newTransaction.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); // The transactionID on the iou action should match the one from the transactions collection @@ -642,7 +642,7 @@ describe('actions/IOU', () => { expect(transaction.reportID).toBe(iouReportID); expect(transaction.amount).toBe(amount); expect(transaction.comment.comment).toBe(comment); - expect(transaction.merchant).toBe(CONST.TRANSACTION.DEFAULT_MERCHANT); + expect(transaction.merchant).toBe(CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT); expect(transaction.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); // The transactionID on the iou action should match the one from the transactions collection @@ -1102,10 +1102,10 @@ describe('actions/IOU', () => { expect(vitTransaction.comment.comment).toBe(comment); expect(groupTransaction.comment.comment).toBe(comment); - expect(carlosTransaction.merchant).toBe(CONST.TRANSACTION.DEFAULT_MERCHANT); - expect(julesTransaction.merchant).toBe(CONST.TRANSACTION.DEFAULT_MERCHANT); - expect(vitTransaction.merchant).toBe(CONST.TRANSACTION.DEFAULT_MERCHANT); - expect(groupTransaction.merchant).toBe(CONST.TRANSACTION.DEFAULT_MERCHANT); + expect(carlosTransaction.merchant).toBe(CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT); + expect(julesTransaction.merchant).toBe(CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT); + expect(vitTransaction.merchant).toBe(CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT); + expect(groupTransaction.merchant).toBe(CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT); expect(carlosTransaction.comment.source).toBe(CONST.IOU.TYPE.SPLIT); expect(julesTransaction.comment.source).toBe(CONST.IOU.TYPE.SPLIT); From 7df83930a14954486a8d276613542d0a97e5fcb2 Mon Sep 17 00:00:00 2001 From: Artem Makushov Date: Fri, 22 Dec 2023 17:49:00 +0100 Subject: [PATCH 10/13] updated errors --- ...oraryForRefactorRequestConfirmationList.js | 71 +++++++++++++------ src/languages/en.ts | 1 + src/languages/es.ts | 1 + 3 files changed, 52 insertions(+), 21 deletions(-) diff --git a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js index 1a45f5b509a7..35702c0ac0cb 100755 --- a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js +++ b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js @@ -309,9 +309,13 @@ function MoneyTemporaryForRefactorRequestConfirmationList({ setFormError('iou.error.genericSmartscanFailureMessage'); return; } + if (shouldDisplayMerchantError) { + setFormError('iou.error.invalidMerchant'); + return; + } // reset the form error whenever the screen gains or loses focus setFormError(''); - }, [isFocused, transaction, shouldDisplayFieldError, hasSmartScanFailed, didConfirmSplit]); + }, [isFocused, transaction, shouldDisplayFieldError, hasSmartScanFailed, didConfirmSplit, shouldDisplayMerchantError]); useEffect(() => { if (!shouldCalculateDistanceAmount) { @@ -481,6 +485,9 @@ function MoneyTemporaryForRefactorRequestConfirmationList({ if (_.isEmpty(selectedParticipants)) { return; } + if (shouldDisplayMerchantError) { + return; + } if (iouType === CONST.IOU.TYPE.SEND) { if (!paymentMethod) { @@ -509,7 +516,19 @@ function MoneyTemporaryForRefactorRequestConfirmationList({ onConfirm(selectedParticipants); } }, - [selectedParticipants, onSendMoney, onConfirm, isEditingSplitBill, iouType, isDistanceRequest, isDistanceRequestWithoutRoute, iouCurrencyCode, iouAmount, transaction], + [ + selectedParticipants, + shouldDisplayMerchantError, + iouType, + onSendMoney, + iouCurrencyCode, + isDistanceRequest, + isDistanceRequestWithoutRoute, + iouAmount, + isEditingSplitBill, + transaction, + onConfirm, + ], ); const footerContent = useMemo(() => { @@ -518,7 +537,7 @@ function MoneyTemporaryForRefactorRequestConfirmationList({ } const shouldShowSettlementButton = iouType === CONST.IOU.TYPE.SEND; - const shouldDisableButton = selectedParticipants.length === 0 || shouldDisplayMerchantError; + const shouldDisableButton = selectedParticipants.length === 0; const button = shouldShowSettlementButton ? ( ); - }, [ - isReadOnly, - iouType, - selectedParticipants.length, - shouldDisplayMerchantError, - confirm, - bankAccountRoute, - iouCurrencyCode, - policyID, - splitOrRequestOptions, - formError, - styles.ph1, - styles.mb2, - translate, - ]); + }, [isReadOnly, iouType, selectedParticipants.length, confirm, bankAccountRoute, iouCurrencyCode, policyID, splitOrRequestOptions, formError, styles.ph1, styles.mb2, translate]); const {image: receiptImage, thumbnail: receiptThumbnail} = receiptPath && receiptFilename ? ReceiptUtils.getThumbnailAndImageURIs(transaction, receiptPath, receiptFilename) : {}; return ( @@ -655,6 +660,28 @@ function MoneyTemporaryForRefactorRequestConfirmationList({ interactive={!isReadOnly} numberOfLinesTitle={2} /> + {shouldDisplayMerchantError && ( + { + if (isEditingSplitBill) { + Navigation.navigate(ROUTES.EDIT_SPLIT_BILL.getRoute(reportID, reportActionID, CONST.EDIT_REQUEST_FIELD.MERCHANT)); + return; + } + Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_MERCHANT.getRoute(iouType, transaction.transactionID, reportID, Navigation.getActiveRouteWithoutParams())); + }} + disabled={didConfirm} + interactive={!isReadOnly} + brickRoadIndicator={ + shouldDisplayMerchantError || (shouldDisplayFieldError && TransactionUtils.isMerchantMissing(transaction)) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : '' + } + error={shouldDisplayMerchantError || (shouldDisplayFieldError && TransactionUtils.isMerchantMissing(transaction)) ? translate('common.error.fieldRequired') : ''} + /> + )} {!shouldShowAllFields && ( @@ -706,7 +733,7 @@ function MoneyTemporaryForRefactorRequestConfirmationList({ interactive={!isReadOnly} /> )} - {shouldShowMerchant && ( + {!shouldDisplayMerchantError && shouldShowMerchant && ( )} {shouldShowCategories && ( diff --git a/src/languages/en.ts b/src/languages/en.ts index 71d27e341cac..3597166c38e5 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -618,6 +618,7 @@ export default { genericSmartscanFailureMessage: 'Transaction is missing fields', atLeastTwoDifferentWaypoints: 'Please enter at least two different addresses', splitBillMultipleParticipantsErrorMessage: 'Split bill is only allowed between a single workspace or individual users. Please update your selection.', + invalidMerchant: 'Please enter a corrent merchant.', }, waitingOnEnabledWallet: ({submitterDisplayName}: WaitingOnBankAccountParams) => `Started settling up, payment is held until ${submitterDisplayName} enables their Wallet`, enableWallet: 'Enable Wallet', diff --git a/src/languages/es.ts b/src/languages/es.ts index 85223c559f81..de5ae7f51f9f 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -613,6 +613,7 @@ export default { genericSmartscanFailureMessage: 'La transacción tiene campos vacíos', atLeastTwoDifferentWaypoints: 'Por favor introduce al menos dos direcciones diferentes', splitBillMultipleParticipantsErrorMessage: 'Solo puedes dividir una cuenta entre un único espacio de trabajo o con usuarios individuales. Por favor actualiza tu selección.', + invalidMerchant: 'Por favor ingrese un comerciante correcto.', }, waitingOnEnabledWallet: ({submitterDisplayName}: WaitingOnBankAccountParams) => `Inició el pago, pero no se procesará hasta que ${submitterDisplayName} active su Billetera`, enableWallet: 'Habilitar Billetera', From 3905c898d39c25244412266537515d2aa5741a1c Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Wed, 27 Dec 2023 09:40:09 +0100 Subject: [PATCH 11/13] fix: minor fix --- .../MoneyTemporaryForRefactorRequestConfirmationList.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js index 24c67296a6d0..d3663f6e0aae 100755 --- a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js +++ b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js @@ -97,6 +97,9 @@ const propTypes = { /** Should the list be read only, and not editable? */ isReadOnly: PropTypes.bool, + /** Whether the money request is a scan request */ + isScanRequest: PropTypes.bool, + /** Depending on expense report or personal IOU report, respective bank account route */ bankAccountRoute: PropTypes.string, @@ -211,6 +214,7 @@ function MoneyTemporaryForRefactorRequestConfirmationList({ isEditingSplitBill, isPolicyExpenseChat, isReadOnly, + isScanRequest, listStyles, mileageRate, onConfirm, From 9860e010c249bde53a81a59d0ac0cd702e6dbc8b Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Thu, 28 Dec 2023 11:09:17 +0100 Subject: [PATCH 12/13] fix: validate merchant field on submit --- ...oraryForRefactorRequestConfirmationList.js | 45 ++++++++++++------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js index d3663f6e0aae..8eef1148ca74 100755 --- a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js +++ b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js @@ -285,6 +285,8 @@ function MoneyTemporaryForRefactorRequestConfirmationList({ const [didConfirm, setDidConfirm] = useState(false); const [didConfirmSplit, setDidConfirmSplit] = useState(false); + const [merchantError, setMerchantError] = useState(false); + const shouldDisplayFieldError = useMemo(() => { if (!isEditingSplitBill) { return false; @@ -294,7 +296,19 @@ function MoneyTemporaryForRefactorRequestConfirmationList({ }, [isEditingSplitBill, hasSmartScanFailed, transaction, didConfirmSplit]); const isMerchantEmpty = !iouMerchant || iouMerchant === CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT; - const shouldDisplayMerchantError = isPolicyExpenseChat && !isScanRequest && isMerchantEmpty; + const isMerchantRequired = isPolicyExpenseChat && !isScanRequest; + + useEffect(() => { + if ((!isMerchantRequired && isMerchantEmpty) || !merchantError) { + return; + } + if (!isMerchantEmpty && merchantError) { + setMerchantError(false); + if (formError === 'iou.error.invalidMerchant') { + setFormError(''); + } + } + }, [formError, isMerchantEmpty, merchantError, isMerchantRequired]); useEffect(() => { if (shouldDisplayFieldError && hasSmartScanFailed) { @@ -305,13 +319,13 @@ function MoneyTemporaryForRefactorRequestConfirmationList({ setFormError('iou.error.genericSmartscanFailureMessage'); return; } - if (shouldDisplayMerchantError) { + if (merchantError) { setFormError('iou.error.invalidMerchant'); return; } // reset the form error whenever the screen gains or loses focus setFormError(''); - }, [isFocused, transaction, shouldDisplayFieldError, hasSmartScanFailed, didConfirmSplit, shouldDisplayMerchantError]); + }, [isFocused, transaction, shouldDisplayFieldError, hasSmartScanFailed, didConfirmSplit, isMerchantRequired, merchantError]); useEffect(() => { if (!shouldCalculateDistanceAmount) { @@ -481,7 +495,8 @@ function MoneyTemporaryForRefactorRequestConfirmationList({ if (_.isEmpty(selectedParticipants)) { return; } - if (shouldDisplayMerchantError) { + if ((isMerchantRequired && isMerchantEmpty) || (shouldDisplayFieldError && TransactionUtils.isMerchantMissing(transaction))) { + setMerchantError(true); return; } @@ -514,7 +529,10 @@ function MoneyTemporaryForRefactorRequestConfirmationList({ }, [ selectedParticipants, - shouldDisplayMerchantError, + isMerchantRequired, + isMerchantEmpty, + shouldDisplayFieldError, + transaction, iouType, onSendMoney, iouCurrencyCode, @@ -522,7 +540,6 @@ function MoneyTemporaryForRefactorRequestConfirmationList({ isDistanceRequestWithoutRoute, iouAmount, isEditingSplitBill, - transaction, onConfirm, ], ); @@ -655,7 +672,7 @@ function MoneyTemporaryForRefactorRequestConfirmationList({ interactive={!isReadOnly} numberOfLinesTitle={2} /> - {shouldDisplayMerchantError && ( + {isMerchantRequired && ( )} {!shouldShowAllFields && ( @@ -728,7 +743,7 @@ function MoneyTemporaryForRefactorRequestConfirmationList({ interactive={!isReadOnly} /> )} - {!shouldDisplayMerchantError && shouldShowMerchant && ( + {!isMerchantRequired && shouldShowMerchant && ( )} {shouldShowCategories && ( From 513b612d7d18b501c39f5359d41a41821a636a16 Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Fri, 29 Dec 2023 09:42:39 +0100 Subject: [PATCH 13/13] fix: do not show merchant on scan request --- .../MoneyTemporaryForRefactorRequestConfirmationList.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js index 8eef1148ca74..dab34e324ffa 100755 --- a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js +++ b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js @@ -296,7 +296,7 @@ function MoneyTemporaryForRefactorRequestConfirmationList({ }, [isEditingSplitBill, hasSmartScanFailed, transaction, didConfirmSplit]); const isMerchantEmpty = !iouMerchant || iouMerchant === CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT; - const isMerchantRequired = isPolicyExpenseChat && !isScanRequest; + const isMerchantRequired = isPolicyExpenseChat && !isScanRequest && shouldShowMerchant; useEffect(() => { if ((!isMerchantRequired && isMerchantEmpty) || !merchantError) {