Skip to content

Commit

Permalink
Merge pull request Expensify#25449 from Expensify/vit-addMerchantToRe…
Browse files Browse the repository at this point in the history
…questMoney

Enable setting created and merchant fields for new requests
  • Loading branch information
luacmartins authored Aug 21, 2023
2 parents dd50e91 + 6b13565 commit 977f1fd
Show file tree
Hide file tree
Showing 17 changed files with 440 additions and 102 deletions.
3 changes: 2 additions & 1 deletion src/ONYXKEYS.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,9 @@ export default {
NEW_TASK_FORM: 'newTaskForm',
EDIT_TASK_FORM: 'editTaskForm',
MONEY_REQUEST_DESCRIPTION_FORM: 'moneyRequestDescriptionForm',
MONEY_REQUEST_MERCHANT_FORM: 'moneyRequestMerchantForm',
MONEY_REQUEST_AMOUNT_FORM: 'moneyRequestAmountForm',
MONEY_REQUEST_CREATED_FORM: 'moneyRequestCreatedForm',
MONEY_REQUEST_DATE_FORM: 'moneyRequestCreatedForm',
NEW_CONTACT_METHOD_FORM: 'newContactMethodForm',
PAYPAL_FORM: 'payPalForm',
WAYPOINT_FORM: 'waypointForm',
Expand Down
4 changes: 4 additions & 0 deletions src/ROUTES.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ export default {
MONEY_REQUEST_AMOUNT: ':iouType/new/amount/:reportID?',
MONEY_REQUEST_PARTICIPANTS: ':iouType/new/participants/:reportID?',
MONEY_REQUEST_CONFIRMATION: ':iouType/new/confirmation/:reportID?',
MONEY_REQUEST_DATE: ':iouType/new/date/:reportID?',
MONEY_REQUEST_CURRENCY: ':iouType/new/currency/:reportID?',
MONEY_REQUEST_DESCRIPTION: ':iouType/new/description/:reportID?',
MONEY_REQUEST_MERCHANT: ':iouType/new/merchant/:reportID?',
MONEY_REQUEST_MANUAL_TAB: ':iouType/new/:reportID?/manual',
MONEY_REQUEST_SCAN_TAB: ':iouType/new/:reportID?/scan',
MONEY_REQUEST_DISTANCE_TAB: ':iouType/new/:reportID?/distance',
Expand All @@ -102,8 +104,10 @@ export default {
getMoneyRequestAmountRoute: (iouType, reportID = '') => `${iouType}/new/amount/${reportID}`,
getMoneyRequestParticipantsRoute: (iouType, reportID = '') => `${iouType}/new/participants/${reportID}`,
getMoneyRequestConfirmationRoute: (iouType, reportID = '') => `${iouType}/new/confirmation/${reportID}`,
getMoneyRequestCreatedRoute: (iouType, reportID = '') => `${iouType}/new/date/${reportID}`,
getMoneyRequestCurrencyRoute: (iouType, reportID = '', currency, backTo) => `${iouType}/new/currency/${reportID}?currency=${currency}&backTo=${backTo}`,
getMoneyRequestDescriptionRoute: (iouType, reportID = '') => `${iouType}/new/description/${reportID}`,
getMoneyRequestMerchantRoute: (iouType, reportID = '') => `${iouType}/new/merchant/${reportID}`,
getMoneyRequestDistanceTabRoute: (iouType, reportID = '') => `${iouType}/new/${reportID}/distance`,
getMoneyRequestWaypointRoute: (iouType, waypointIndex) => `${iouType}/new/waypoint/${waypointIndex}`,
SPLIT_BILL_DETAILS: `r/:reportID/split/:reportActionID`,
Expand Down
16 changes: 10 additions & 6 deletions src/components/MoneyRequestConfirmationList.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, {useCallback, useMemo, useReducer, useState} from 'react';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import {format} from 'date-fns';
import _ from 'underscore';
import {View} from 'react-native';
import Str from 'expensify-common/lib/str';
Expand Down Expand Up @@ -58,7 +59,7 @@ const propTypes = {
iouType: PropTypes.string,

/** IOU date */
iouDate: PropTypes.string,
iouCreated: PropTypes.string,

/** IOU merchant */
iouMerchant: PropTypes.string,
Expand Down Expand Up @@ -125,6 +126,7 @@ function MoneyRequestConfirmationList(props) {

// A flag and a toggler for showing the rest of the form fields
const [showAllFields, toggleShowAllFields] = useReducer((state) => !state, false);
const isTypeRequest = props.iouType === CONST.IOU.MONEY_REQUEST_TYPE.REQUEST;

/**
* Returns the participants with amount
Expand Down Expand Up @@ -406,18 +408,20 @@ function MoneyRequestConfirmationList(props) {
{showAllFields && (
<>
<MenuItemWithTopDescription
title={props.iouDate}
shouldShowRightIcon={!props.isReadOnly && isTypeRequest}
title={props.iouCreated || format(new Date(), CONST.DATE.FNS_FORMAT_STRING)}
description={translate('common.date')}
style={[styles.moneyRequestMenuItem, styles.mb2]}
// Note: This component is disabled until this field is editable in next PR
disabled
onPress={() => Navigation.navigate(ROUTES.getMoneyRequestCreatedRoute(props.iouType, props.reportID))}
disabled={didConfirm || props.isReadOnly || !isTypeRequest}
/>
<MenuItemWithTopDescription
shouldShowRightIcon={!props.isReadOnly && isTypeRequest}
title={props.iouMerchant}
description={translate('common.merchant')}
style={[styles.moneyRequestMenuItem, styles.mb2]}
// Note: This component is disabled until this field is editable in next PR
disabled
onPress={() => Navigation.navigate(ROUTES.getMoneyRequestMerchantRoute(props.iouType, props.reportID))}
disabled={didConfirm || props.isReadOnly || !isTypeRequest}
/>
</>
)}
Expand Down
16 changes: 15 additions & 1 deletion src/components/ReportActionItem/MoneyRequestView.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,13 @@ function MoneyRequestView({report, parentReport, shouldShowHorizontalRule, polic
const parentReportAction = ReportActionsUtils.getParentReportAction(report);
const moneyRequestReport = parentReport;
const transaction = TransactionUtils.getLinkedTransaction(parentReportAction);
const {created: transactionDate, amount: transactionAmount, currency: transactionCurrency, comment: transactionDescription} = ReportUtils.getTransactionDetails(transaction);
const {
created: transactionDate,
amount: transactionAmount,
currency: transactionCurrency,
comment: transactionDescription,
merchant: transactionMerchant,
} = ReportUtils.getTransactionDetails(transaction);
const formattedTransactionAmount = transactionAmount && transactionCurrency && CurrencyUtils.convertToDisplayString(transactionAmount, transactionCurrency);

const isSettled = ReportUtils.isSettled(moneyRequestReport.reportID);
Expand Down Expand Up @@ -128,6 +134,14 @@ function MoneyRequestView({report, parentReport, shouldShowHorizontalRule, polic
onPress={() => Navigation.navigate(ROUTES.getEditRequestRoute(report.reportID, CONST.EDIT_REQUEST_FIELD.DATE))}
/>
</OfflineWithFeedback>
<OfflineWithFeedback pendingAction={lodashGet(transaction, 'pendingFields.merchant') || lodashGet(transaction, 'pendingAction')}>
<MenuItemWithTopDescription
description={translate('common.merchant')}
title={transactionMerchant}
shouldShowRightIcon={false}
disabled
/>
</OfflineWithFeedback>
{shouldShowHorizontalRule && <View style={styles.reportHorizontalRule} />}
</View>
);
Expand Down
14 changes: 14 additions & 0 deletions src/libs/Navigation/AppNavigator/ModalStackNavigators.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,27 @@ const MoneyRequestModalStackNavigator = createModalStackNavigator([
},
name: 'Money_Request_Currency',
},
{
getComponent: () => {
const MoneyRequestDatePage = require('../../../pages/iou/MoneyRequestDatePage').default;
return MoneyRequestDatePage;
},
name: 'Money_Request_Date',
},
{
getComponent: () => {
const MoneyRequestDescriptionPage = require('../../../pages/iou/MoneyRequestDescriptionPage').default;
return MoneyRequestDescriptionPage;
},
name: 'Money_Request_Description',
},
{
getComponent: () => {
const MoneyRequestMerchantPage = require('../../../pages/iou/MoneyRequestMerchantPage').default;
return MoneyRequestMerchantPage;
},
name: 'Money_Request_Merchant',
},
{
getComponent: () => {
const AddPersonalBankAccountPage = require('../../../pages/AddPersonalBankAccountPage').default;
Expand Down
2 changes: 2 additions & 0 deletions src/libs/Navigation/linkingConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,10 @@ export default {
Money_Request_Amount: ROUTES.MONEY_REQUEST_AMOUNT,
Money_Request_Participants: ROUTES.MONEY_REQUEST_PARTICIPANTS,
Money_Request_Confirmation: ROUTES.MONEY_REQUEST_CONFIRMATION,
Money_Request_Date: ROUTES.MONEY_REQUEST_DATE,
Money_Request_Currency: ROUTES.MONEY_REQUEST_CURRENCY,
Money_Request_Description: ROUTES.MONEY_REQUEST_DESCRIPTION,
Money_Request_Merchant: ROUTES.MONEY_REQUEST_MERCHANT,
Money_Request_Waypoint: ROUTES.MONEY_REQUEST_WAYPOINT,
IOU_Send_Enable_Payments: ROUTES.IOU_SEND_ENABLE_PAYMENTS,
IOU_Send_Add_Bank_Account: ROUTES.IOU_SEND_ADD_BANK_ACCOUNT,
Expand Down
1 change: 1 addition & 0 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,7 @@ function getTransactionDetails(transaction) {
amount: TransactionUtils.getAmount(transaction, isExpenseReport(report)),
currency: TransactionUtils.getCurrency(transaction),
comment: TransactionUtils.getDescription(transaction),
merchant: TransactionUtils.getMerchant(transaction),
};
}

Expand Down
18 changes: 15 additions & 3 deletions src/libs/TransactionUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Onyx.connect({
* @param {String} currency
* @param {String} reportID
* @param {String} [comment]
* @param {String} [created]
* @param {String} [source]
* @param {String} [originalTransactionID]
* @param {String} [merchant]
Expand All @@ -38,6 +39,7 @@ function buildOptimisticTransaction(
currency,
reportID,
comment = '',
created = '',
source = '',
originalTransactionID = '',
merchant = CONST.REPORT.TYPE.IOU,
Expand All @@ -62,8 +64,8 @@ function buildOptimisticTransaction(
currency,
reportID,
comment: commentJSON,
merchant,
created: DateUtils.getDBTime(),
merchant: merchant || CONST.REPORT.TYPE.IOU,
created: created || DateUtils.getDBTime(),
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
receipt,
};
Expand Down Expand Up @@ -172,6 +174,16 @@ function getCurrency(transaction) {
return lodashGet(transaction, 'currency', CONST.CURRENCY.USD);
}

/**
* Return the merchant field from the transaction, return the modifiedMerchant if present.
*
* @param {Object} transaction
* @returns {String}
*/
function getMerchant(transaction) {
return lodashGet(transaction, 'modifiedMerchant', null) || lodashGet(transaction, 'merchant', '');
}

/**
* Return the created field from the transaction, return the modifiedCreated if present.
*
Expand Down Expand Up @@ -203,4 +215,4 @@ function getAllReportTransactions(reportID) {
return _.filter(allTransactions, (transaction) => transaction.reportID === reportID);
}

export {buildOptimisticTransaction, getUpdatedTransaction, getTransaction, getDescription, getAmount, getCurrency, getCreated, getLinkedTransaction, getAllReportTransactions};
export {buildOptimisticTransaction, getUpdatedTransaction, getTransaction, getDescription, getAmount, getCurrency, getMerchant, getCreated, getLinkedTransaction, getAllReportTransactions};
39 changes: 34 additions & 5 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ Onyx.connect({
* @param {String} id
*/
function resetMoneyRequestInfo(id = '') {
const date = currentDate || moment().format('YYYY-MM-DD');
const created = currentDate || moment().format('YYYY-MM-DD');
Onyx.merge(ONYXKEYS.IOU, {
id,
amount: 0,
currency: lodashGet(currentUserPersonalDetails, 'localCurrencyCode', CONST.CURRENCY.USD),
comment: '',
participants: [],
merchant: '',
date,
created,
receiptPath: '',
receiptSource: '',
});
Expand Down Expand Up @@ -310,6 +310,8 @@ function buildOnyxDataForMoneyRequest(
* @param {String} comment
* @param {Number} amount
* @param {String} currency
* @param {String} created
* @param {String} merchant
* @param {Number} payeeAccountID
* @param {String} payeeEmail
* @param {Object} [receipt]
Expand All @@ -328,7 +330,7 @@ function buildOnyxDataForMoneyRequest(
* @returns {Object} data.onyxData.failureData
* @param {String} [existingTransactionID]
*/
function getMoneyRequestInformation(report, participant, comment, amount, currency, payeeAccountID, payeeEmail, receipt = undefined, existingTransactionID = null) {
function getMoneyRequestInformation(report, participant, comment, amount, currency, created, merchant, payeeAccountID, payeeEmail, receipt = undefined, existingTransactionID = null) {
const payerEmail = OptionsListUtils.addSMSDomainIfPhoneNumber(participant.login);
const payerAccountID = Number(participant.accountID);
const isPolicyExpenseChat = participant.isPolicyExpenseChat;
Expand Down Expand Up @@ -383,9 +385,10 @@ function getMoneyRequestInformation(report, participant, comment, amount, curren
currency,
iouReport.reportID,
comment,
created,
'',
'',
undefined,
merchant,
receiptObject,
existingTransactionID,
);
Expand Down Expand Up @@ -495,6 +498,8 @@ function createDistanceRequest(report, payeeEmail, payeeAccountID, participant,
comment,
0,
'USD',
created,
'',
payeeAccountID,
payeeEmail,
null,
Expand Down Expand Up @@ -526,19 +531,23 @@ function createDistanceRequest(report, payeeEmail, payeeAccountID, participant,
* @param {Object} report
* @param {Number} amount - always in the smallest unit of the currency
* @param {String} currency
* @param {String} created
* @param {String} merchant
* @param {String} payeeEmail
* @param {Number} payeeAccountID
* @param {Object} participant
* @param {String} comment
* @param {Object} [receipt]
*/
function requestMoney(report, amount, currency, payeeEmail, payeeAccountID, participant, comment, receipt = undefined) {
function requestMoney(report, amount, currency, created, merchant, payeeEmail, payeeAccountID, participant, comment, receipt = undefined) {
const {payerEmail, iouReport, chatReport, transaction, iouAction, createdChatReportActionID, createdIOUReportActionID, reportPreviewAction, onyxData} = getMoneyRequestInformation(
report,
participant,
comment,
amount,
currency,
created,
merchant,
payeeAccountID,
payeeEmail,
receipt,
Expand All @@ -551,6 +560,8 @@ function requestMoney(report, amount, currency, payeeEmail, payeeAccountID, part
amount,
currency,
comment,
created,
merchant,
iouReportID: iouReport.reportID,
chatReportID: chatReport.reportID,
transactionID: transaction.transactionID,
Expand Down Expand Up @@ -609,6 +620,7 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco
comment,
'',
'',
'',
`${Localize.translateLocal('iou.splitBill')} ${Localize.translateLocal('common.with')} ${formattedParticipants} [${DateUtils.getDBTime().slice(0, 10)}]`,
);

Expand Down Expand Up @@ -782,6 +794,7 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco
currency,
oneOnOneIOUReport.reportID,
comment,
'',
CONST.IOU.MONEY_REQUEST_TYPE.SPLIT,
splitTransaction.transactionID,
);
Expand Down Expand Up @@ -1698,6 +1711,13 @@ function setMoneyRequestAmount(amount) {
Onyx.merge(ONYXKEYS.IOU, {amount});
}

/**
* @param {String} created
*/
function setMoneyRequestCreated(created) {
Onyx.merge(ONYXKEYS.IOU, {created});
}

/**
* @param {String} currency
*/
Expand All @@ -1712,6 +1732,13 @@ function setMoneyRequestDescription(comment) {
Onyx.merge(ONYXKEYS.IOU, {comment: comment.trim()});
}

/**
* @param {String} merchant
*/
function setMoneyRequestMerchant(merchant) {
Onyx.merge(ONYXKEYS.IOU, {merchant: merchant.trim()});
}

/**
* @param {Object[]} participants
*/
Expand Down Expand Up @@ -1785,8 +1812,10 @@ export {
resetMoneyRequestInfo,
setMoneyRequestId,
setMoneyRequestAmount,
setMoneyRequestCreated,
setMoneyRequestCurrency,
setMoneyRequestDescription,
setMoneyRequestMerchant,
setMoneyRequestParticipants,
setMoneyRequestReceipt,
createEmptyTransaction,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/EditRequestCreatedPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function EditRequestCreatedPage({defaultCreated, onSubmit}) {
/>
<Form
style={[styles.flexGrow1, styles.ph5]}
formID={ONYXKEYS.FORMS.MONEY_REQUEST_CREATED_FORM}
formID={ONYXKEYS.FORMS.MONEY_REQUEST_DATE_FORM}
onSubmit={onSubmit}
submitButtonText={translate('common.save')}
enabledWhenOffline
Expand Down
Loading

0 comments on commit 977f1fd

Please sign in to comment.