diff --git a/src/CONST.js b/src/CONST.js index 4234ed8a5ab..108196b8a52 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -663,6 +663,7 @@ const CONST = { SYSTEM: 'system', }, TRANSACTION: { + DEFAULT_MERCHANT: 'Request', TYPE: { CUSTOM_UNIT: 'customUnit', }, diff --git a/src/components/MoneyRequestConfirmationList.js b/src/components/MoneyRequestConfirmationList.js index ffd65cfb8f7..50ba4aba95c 100755 --- a/src/components/MoneyRequestConfirmationList.js +++ b/src/components/MoneyRequestConfirmationList.js @@ -386,7 +386,7 @@ function MoneyRequestConfirmationList(props) { /> Navigation.navigate(ROUTES.getEditRequestRoute(report.reportID, CONST.EDIT_REQUEST_FIELD.MERCHANT))} /> {shouldShowHorizontalRule && } diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index f1eee1c6f25..ed894319fbd 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1412,11 +1412,6 @@ function getModifiedExpenseMessage(reportAction) { return getProperSchemaForModifiedExpenseMessage(reportActionOriginalMessage.newComment, reportActionOriginalMessage.oldComment, 'description', true); } - const hasModifiedMerchant = _.has(reportActionOriginalMessage, 'oldMerchant') && _.has(reportActionOriginalMessage, 'merchant'); - if (hasModifiedMerchant) { - return getProperSchemaForModifiedExpenseMessage(reportActionOriginalMessage.merchant, reportActionOriginalMessage.oldMerchant, 'merchant', true); - } - const hasModifiedCreated = _.has(reportActionOriginalMessage, 'oldCreated') && _.has(reportActionOriginalMessage, 'created'); if (hasModifiedCreated) { // Take only the YYYY-MM-DD value as the original date includes timestamp @@ -1424,6 +1419,11 @@ function getModifiedExpenseMessage(reportAction) { formattedOldCreated = format(formattedOldCreated, CONST.DATE.FNS_FORMAT_STRING); return getProperSchemaForModifiedExpenseMessage(reportActionOriginalMessage.created, formattedOldCreated, 'date', false); } + + const hasModifiedMerchant = _.has(reportActionOriginalMessage, 'oldMerchant') && _.has(reportActionOriginalMessage, 'merchant'); + if (hasModifiedMerchant) { + return getProperSchemaForModifiedExpenseMessage(reportActionOriginalMessage.merchant, reportActionOriginalMessage.oldMerchant, 'merchant', true); + } } /** @@ -1450,6 +1450,10 @@ function getModifiedExpenseOriginalMessage(oldTransaction, transactionChanges, i originalMessage.oldCreated = TransactionUtils.getCreated(oldTransaction); originalMessage.created = transactionChanges.created; } + if (_.has(transactionChanges, 'merchant')) { + originalMessage.oldMerchant = TransactionUtils.getMerchant(oldTransaction); + originalMessage.merchant = transactionChanges.merchant; + } // The amount is always a combination of the currency and the number value so when one changes we need to store both // to match how we handle the modified expense action in oldDot diff --git a/src/libs/TransactionUtils.js b/src/libs/TransactionUtils.js index 1da59f12f77..74be61629ed 100644 --- a/src/libs/TransactionUtils.js +++ b/src/libs/TransactionUtils.js @@ -43,7 +43,7 @@ function buildOptimisticTransaction( created = '', source = '', originalTransactionID = '', - merchant = CONST.REPORT.TYPE.IOU, + merchant = CONST.TRANSACTION.DEFAULT_MERCHANT, receipt = {}, filename = '', existingTransactionID = null, @@ -66,7 +66,7 @@ function buildOptimisticTransaction( currency, reportID, comment: commentJSON, - merchant: merchant || CONST.REPORT.TYPE.IOU, + merchant: merchant || CONST.TRANSACTION.DEFAULT_MERCHANT, created: created || DateUtils.getDBTime(), pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, receipt, @@ -128,6 +128,7 @@ function getUpdatedTransaction(transaction, transactionChanges, isFromExpenseRep ...(_.has(transactionChanges, 'created') && {created: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE}), ...(_.has(transactionChanges, 'amount') && {amount: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE}), ...(_.has(transactionChanges, 'currency') && {currency: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE}), + ...(_.has(transactionChanges, 'merchant') && {merchant: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE}), }; return updatedTransaction; diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index ee9afa8b0eb..99489852104 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -1006,6 +1006,7 @@ function editMoneyRequest(transactionID, transactionThreadReportID, transactionC amount: null, created: null, currency: null, + merchant: null, }, }, }, diff --git a/src/pages/EditRequestMerchantPage.js b/src/pages/EditRequestMerchantPage.js new file mode 100644 index 00000000000..c9c4cfbdbfa --- /dev/null +++ b/src/pages/EditRequestMerchantPage.js @@ -0,0 +1,61 @@ +import React, {useRef} from 'react'; +import {View} from 'react-native'; +import PropTypes from 'prop-types'; +import TextInput from '../components/TextInput'; +import ScreenWrapper from '../components/ScreenWrapper'; +import HeaderWithBackButton from '../components/HeaderWithBackButton'; +import Form from '../components/Form'; +import ONYXKEYS from '../ONYXKEYS'; +import styles from '../styles/styles'; +import Navigation from '../libs/Navigation/Navigation'; +import CONST from '../CONST'; +import useLocalize from '../hooks/useLocalize'; + +const propTypes = { + /** Transaction default merchant value */ + defaultMerchant: PropTypes.string.isRequired, + + /** Callback to fire when the Save button is pressed */ + onSubmit: PropTypes.func.isRequired, +}; + +function EditRequestMerchantPage({defaultMerchant, onSubmit}) { + const {translate} = useLocalize(); + const merchantInputRef = useRef(null); + return ( + merchantInputRef.current && merchantInputRef.current.focus()} + > + Navigation.goBack()} + /> +
+ + (merchantInputRef.current = e)} + /> + +
+
+ ); +} + +EditRequestMerchantPage.propTypes = propTypes; +EditRequestMerchantPage.displayName = 'EditRequestMerchantPage'; + +export default EditRequestMerchantPage; diff --git a/src/pages/EditRequestPage.js b/src/pages/EditRequestPage.js index 8133acb0994..83b0019315e 100644 --- a/src/pages/EditRequestPage.js +++ b/src/pages/EditRequestPage.js @@ -12,6 +12,7 @@ import * as TransactionUtils from '../libs/TransactionUtils'; import * as Policy from '../libs/actions/Policy'; import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsPropTypes} from '../components/withCurrentUserPersonalDetails'; import EditRequestDescriptionPage from './EditRequestDescriptionPage'; +import EditRequestMerchantPage from './EditRequestMerchantPage'; import EditRequestCreatedPage from './EditRequestCreatedPage'; import EditRequestAmountPage from './EditRequestAmountPage'; import reportPropTypes from './reportPropTypes'; @@ -67,7 +68,7 @@ const defaultProps = { function EditRequestPage({report, route, parentReport, policy, session}) { const parentReportAction = ReportActionsUtils.getParentReportAction(report); const transaction = TransactionUtils.getLinkedTransaction(parentReportAction); - const {amount: transactionAmount, currency: transactionCurrency, comment: transactionDescription} = ReportUtils.getTransactionDetails(transaction); + const {amount: transactionAmount, currency: transactionCurrency, comment: transactionDescription, merchant: transactionMerchant} = ReportUtils.getTransactionDetails(transaction); const defaultCurrency = lodashGet(route, 'params.currency', '') || transactionCurrency; @@ -151,6 +152,22 @@ function EditRequestPage({report, route, parentReport, policy, session}) { ); } + if (fieldToEdit === CONST.EDIT_REQUEST_FIELD.MERCHANT) { + return ( + { + // In case the merchant hasn't been changed, do not make the API request. + if (transactionChanges.merchant.trim() === transactionMerchant) { + Navigation.dismissModal(); + return; + } + editMoneyRequest({merchant: transactionChanges.merchant.trim()}); + }} + /> + ); + } + return null; } diff --git a/tests/actions/IOUTest.js b/tests/actions/IOUTest.js index bf32c2ef8f9..6fbbe19cec8 100644 --- a/tests/actions/IOUTest.js +++ b/tests/actions/IOUTest.js @@ -293,7 +293,7 @@ describe('actions/IOU', () => { // The comment should be correct expect(transaction.comment.comment).toBe(comment); - expect(transaction.merchant).toBe(CONST.REPORT.TYPE.IOU); + expect(transaction.merchant).toBe(CONST.TRANSACTION.DEFAULT_MERCHANT); // It should be pending expect(transaction.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); @@ -477,7 +477,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.REPORT.TYPE.IOU); + expect(newTransaction.merchant).toBe(CONST.TRANSACTION.DEFAULT_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 @@ -620,7 +620,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.REPORT.TYPE.IOU); + expect(transaction.merchant).toBe(CONST.TRANSACTION.DEFAULT_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 @@ -1079,9 +1079,9 @@ describe('actions/IOU', () => { expect(vitTransaction.comment.comment).toBe(comment); expect(groupTransaction.comment.comment).toBe(comment); - expect(carlosTransaction.merchant).toBe(CONST.REPORT.TYPE.IOU); - expect(julesTransaction.merchant).toBe(CONST.REPORT.TYPE.IOU); - expect(vitTransaction.merchant).toBe(CONST.REPORT.TYPE.IOU); + 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( `Split bill with ${RORY_EMAIL}, ${CARLOS_EMAIL}, ${JULES_EMAIL}, and ${VIT_EMAIL} [${DateUtils.getDBTime().slice(0, 10)}]`, );