Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add merchant and date fields to manual requests #23648

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 48 additions & 2 deletions src/components/MoneyRequestConfirmationList.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, {useState, useCallback, useMemo} from 'react';
import React, {useCallback, useMemo, useReducer, useState} from 'react';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
import {View} from 'react-native';
import Str from 'expensify-common/lib/str';
import styles from '../styles/styles';
import * as ReportUtils from '../libs/ReportUtils';
Expand All @@ -14,12 +15,15 @@ import ButtonWithDropdownMenu from './ButtonWithDropdownMenu';
import Log from '../libs/Log';
import SettlementButton from './SettlementButton';
import ROUTES from '../ROUTES';
import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsPropTypes, withCurrentUserPersonalDetailsDefaultProps} from './withCurrentUserPersonalDetails';
import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsDefaultProps, withCurrentUserPersonalDetailsPropTypes} from './withCurrentUserPersonalDetails';
import * as IOUUtils from '../libs/IOUUtils';
import MenuItemWithTopDescription from './MenuItemWithTopDescription';
import Navigation from '../libs/Navigation/Navigation';
import optionPropTypes from './optionPropTypes';
import * as CurrencyUtils from '../libs/CurrencyUtils';
import Button from './Button';
import * as Expensicons from './Icon/Expensicons';
import themeColors from '../styles/themes/default';
import Image from './Image';
import ReceiptHTML from '../../assets/images/receipt-html.png';
import ReceiptDoc from '../../assets/images/receipt-doc.png';
Expand Down Expand Up @@ -53,6 +57,12 @@ const propTypes = {
/** IOU type */
iouType: PropTypes.string,

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

/** IOU merchant */
iouMerchant: PropTypes.string,

/** Selected participants from MoneyRequestModal with login / accountID */
selectedParticipants: PropTypes.arrayOf(optionPropTypes).isRequired,

Expand Down Expand Up @@ -113,6 +123,9 @@ function MoneyRequestConfirmationList(props) {
const {onSendMoney, onConfirm, onSelectParticipant} = props;
const {translate} = useLocalize();

// A flag and a toggler for showing the rest of the form fields
const [showAllFields, toggleShowAllFields] = useReducer((state) => !state, false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not useState here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this approach as it exposes a bool flag and a toggle function in one line. With useState you have declare a separate function to toggle the flag. Nice and clean.


/**
* Returns the participants with amount
* @param {Array} participants
Expand Down Expand Up @@ -371,6 +384,39 @@ function MoneyRequestConfirmationList(props) {
style={[styles.moneyRequestMenuItem, styles.mb2]}
disabled={didConfirm || props.isReadOnly}
/>
{!showAllFields && (
<View style={[styles.flexRow, styles.justifyContentBetween, styles.mh3, styles.alignItemsCenter]}>
<View style={[styles.shortTermsHorizontalRule, styles.flex1, styles.mr0]} />
<Button
small
onPress={toggleShowAllFields}
text={translate('common.showMore')}
shouldShowRightIcon
iconRight={Expensicons.DownArrow}
iconFill={themeColors.icon}
style={styles.mh0}
/>
<View style={[styles.shortTermsHorizontalRule, styles.flex1, styles.ml0]} />
</View>
)}
{showAllFields && (
<>
<MenuItemWithTopDescription
title={props.iouDate}
description={translate('common.date')}
style={[styles.moneyRequestMenuItem, styles.mb2]}
// Note: This component is disabled until this field is editable in next PR
disabled
/>
<MenuItemWithTopDescription
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
/>
</>
)}
</OptionsSelector>
);
}
Expand Down
2 changes: 2 additions & 0 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ export default {
someone: 'Someone',
total: 'Total',
edit: 'Edit',
showMore: 'Show more',
merchant: 'Merchant',
},
anonymousReportFooter: {
logoTagline: 'Join in on the discussion.',
Expand Down
2 changes: 2 additions & 0 deletions src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ export default {
someone: 'Alguien',
total: 'Total',
edit: 'Editar',
showMore: 'Mostrar más',
merchant: 'Comerciante',
},
anonymousReportFooter: {
logoTagline: 'Únete a la discussion.',
Expand Down
12 changes: 12 additions & 0 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Onyx from 'react-native-onyx';
import _ from 'underscore';
import lodashGet from 'lodash/get';
import Str from 'expensify-common/lib/str';
import moment from 'moment';
import CONST from '../../CONST';
import ROUTES from '../../ROUTES';
import ONYXKEYS from '../../ONYXKEYS';
Expand Down Expand Up @@ -57,17 +58,28 @@ Onyx.connect({
},
});

let currentDate = '';
Onyx.connect({
key: ONYXKEYS.CURRENT_DATE,
callback: (val) => {
currentDate = val;
},
});

/**
* Reset money request info from the store with its initial value
* @param {String} id
*/
function resetMoneyRequestInfo(id = '') {
const date = currentDate || moment().format('YYYY-MM-DD');
Onyx.merge(ONYXKEYS.IOU, {
id,
amount: 0,
currency: lodashGet(currentUserPersonalDetails, 'localCurrencyCode', CONST.CURRENCY.USD),
comment: '',
participants: [],
merchant: '',
date,
receiptPath: '',
receiptSource: '',
});
Expand Down
5 changes: 4 additions & 1 deletion src/pages/iou/steps/MoneyRequestConfirmPage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useCallback, useEffect, useRef, useMemo} from 'react';
import React, {useCallback, useEffect, useMemo, useRef} from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same ^

import {View} from 'react-native';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
Expand Down Expand Up @@ -219,6 +219,9 @@ function MoneyRequestConfirmPage(props) {
canModifyParticipants={!_.isEmpty(reportID.current)}
policyID={props.report.policyID}
bankAccountRoute={ReportUtils.getBankAccountRoute(props.report)}
iouMerchant={props.iou.merchant}
iouModifiedMerchant={props.iou.modifiedMerchant}
iouDate={props.iou.date}
/>
</View>
)}
Expand Down
4 changes: 4 additions & 0 deletions src/styles/utilities/spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ export default {
marginLeft: 'auto',
},

ml0: {
marginLeft: 0,
},

ml1: {
marginLeft: 4,
},
Expand Down