Skip to content

Commit

Permalink
Fix - IOU - To field is empty and Amount is $NaN when opening confirm…
Browse files Browse the repository at this point in the history
…ation page in another tab
  • Loading branch information
tgolen committed Nov 28, 2023
1 parent 6cff8ba commit 968f39f
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 88 deletions.
13 changes: 2 additions & 11 deletions src/pages/iou/request/step/IOURequestStepAmount.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {useFocusEffect} from '@react-navigation/native';
import lodashGet from 'lodash/get';
import React, {useCallback, useRef} from 'react';
import {withOnyx} from 'react-native-onyx';
import transactionPropTypes from '@components/transactionPropTypes';
import useLocalize from '@hooks/useLocalize';
import compose from '@libs/compose';
Expand All @@ -12,10 +10,10 @@ import MoneyRequestAmountForm from '@pages/iou/steps/MoneyRequestAmountForm';
import reportPropTypes from '@pages/reportPropTypes';
import * as IOU from '@userActions/IOU';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import IOURequestStepRoutePropTypes from './IOURequestStepRoutePropTypes';
import StepScreenWrapper from './StepScreenWrapper';
import withFullTransactionOrNotFound from './withFullTransactionOrNotFound';
import withWritableReportOrNotFound from './withWritableReportOrNotFound';

const propTypes = {
Expand Down Expand Up @@ -118,11 +116,4 @@ IOURequestStepAmount.propTypes = propTypes;
IOURequestStepAmount.defaultProps = defaultProps;
IOURequestStepAmount.displayName = 'IOURequestStepAmount';

export default compose(
withWritableReportOrNotFound,
withOnyx({
transaction: {
key: ({route}) => `${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${lodashGet(route, 'params.transactionID', '0')}`,
},
}),
)(IOURequestStepAmount);
export default compose(withWritableReportOrNotFound, withFullTransactionOrNotFound)(IOURequestStepAmount);
13 changes: 2 additions & 11 deletions src/pages/iou/request/step/IOURequestStepCategory.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import lodashGet from 'lodash/get';
import React from 'react';
import {withOnyx} from 'react-native-onyx';
import CategoryPicker from '@components/CategoryPicker';
import Text from '@components/Text';
import transactionPropTypes from '@components/transactionPropTypes';
Expand All @@ -10,10 +8,10 @@ import Navigation from '@libs/Navigation/Navigation';
import reportPropTypes from '@pages/reportPropTypes';
import useThemeStyles from '@styles/useThemeStyles';
import * as IOU from '@userActions/IOU';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import IOURequestStepRoutePropTypes from './IOURequestStepRoutePropTypes';
import StepScreenWrapper from './StepScreenWrapper';
import withFullTransactionOrNotFound from './withFullTransactionOrNotFound';
import withWritableReportOrNotFound from './withWritableReportOrNotFound';

const propTypes = {
Expand Down Expand Up @@ -77,11 +75,4 @@ IOURequestStepCategory.displayName = 'IOURequestStepCategory';
IOURequestStepCategory.propTypes = propTypes;
IOURequestStepCategory.defaultProps = defaultProps;

export default compose(
withWritableReportOrNotFound,
withOnyx({
transaction: {
key: ({route}) => `${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${lodashGet(route, 'params.transactionID', 0)}`,
},
}),
)(IOURequestStepCategory);
export default compose(withWritableReportOrNotFound, withFullTransactionOrNotFound)(IOURequestStepCategory);
5 changes: 2 additions & 3 deletions src/pages/iou/request/step/IOURequestStepConfirmation.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import IOURequestStepRoutePropTypes from './IOURequestStepRoutePropTypes';
import withFullTransactionOrNotFound from './withFullTransactionOrNotFound';
import withWritableReportOrNotFound from './withWritableReportOrNotFound';

const propTypes = {
Expand Down Expand Up @@ -347,13 +348,11 @@ IOURequestStepConfirmation.displayName = 'IOURequestStepConfirmation';
export default compose(
withCurrentUserPersonalDetails,
withWritableReportOrNotFound,
withFullTransactionOrNotFound,
withOnyx({
personalDetails: {
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
},
transaction: {
key: ({route}) => `${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${lodashGet(route, 'params.transactionID', '0')}`,
},
}),
// eslint-disable-next-line rulesdir/no-multiple-onyx-in-file
withOnyx({
Expand Down
15 changes: 8 additions & 7 deletions src/pages/iou/request/step/IOURequestStepCurrency.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Str from 'expensify-common/lib/str';
import lodashGet from 'lodash/get';
import PropTypes from 'prop-types';
import React, {useMemo, useRef, useState} from 'react';
import {Keyboard} from 'react-native';
Expand All @@ -8,13 +7,15 @@ import _ from 'underscore';
import SelectionList from '@components/SelectionList';
import transactionPropTypes from '@components/transactionPropTypes';
import useLocalize from '@hooks/useLocalize';
import compose from '@libs/compose';
import * as CurrencyUtils from '@libs/CurrencyUtils';
import Navigation from '@libs/Navigation/Navigation';
import * as IOU from '@userActions/IOU';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES, {getUrlWithBackToParam} from '@src/ROUTES';
import IOURequestStepRoutePropTypes from './IOURequestStepRoutePropTypes';
import StepScreenWrapper from './StepScreenWrapper';
import withFullTransactionOrNotFound from './withFullTransactionOrNotFound';

/**
* IOU Currency selection for selecting currency
Expand Down Expand Up @@ -147,9 +148,9 @@ IOURequestStepCurrency.displayName = 'IOURequestStepCurrency';
IOURequestStepCurrency.propTypes = propTypes;
IOURequestStepCurrency.defaultProps = defaultProps;

export default withOnyx({
currencyList: {key: ONYXKEYS.CURRENCY_LIST},
transaction: {
key: ({route}) => `${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${lodashGet(route, 'params.transactionID', '0')}`,
},
})(IOURequestStepCurrency);
export default compose(
withFullTransactionOrNotFound,
withOnyx({
currencyList: {key: ONYXKEYS.CURRENCY_LIST},
}),
)(IOURequestStepCurrency);
12 changes: 2 additions & 10 deletions src/pages/iou/request/step/IOURequestStepDate.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import dateAdd from 'date-fns/add';
import dateSubtract from 'date-fns/sub';
import lodashGet from 'lodash/get';
import React from 'react';
import {withOnyx} from 'react-native-onyx';
import FormProvider from '@components/Form/FormProvider';
import NewDatePicker from '@components/NewDatePicker';
import transactionPropTypes from '@components/transactionPropTypes';
Expand All @@ -16,6 +14,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import IOURequestStepRoutePropTypes from './IOURequestStepRoutePropTypes';
import StepScreenWrapper from './StepScreenWrapper';
import withFullTransactionOrNotFound from './withFullTransactionOrNotFound';
import withWritableReportOrNotFound from './withWritableReportOrNotFound';

const propTypes = {
Expand Down Expand Up @@ -84,11 +83,4 @@ IOURequestStepDate.propTypes = propTypes;
IOURequestStepDate.defaultProps = defaultProps;
IOURequestStepDate.displayName = 'IOURequestStepDate';

export default compose(
withWritableReportOrNotFound,
withOnyx({
transaction: {
key: ({route}) => `${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${lodashGet(route, 'params.transactionID', 0)}`,
},
}),
)(IOURequestStepDate);
export default compose(withWritableReportOrNotFound, withFullTransactionOrNotFound)(IOURequestStepDate);
11 changes: 2 additions & 9 deletions src/pages/iou/request/step/IOURequestStepDescription.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {useFocusEffect} from '@react-navigation/native';
import lodashGet from 'lodash/get';
import React, {useCallback, useRef} from 'react';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import FormProvider from '@components/Form/FormProvider';
import InputWrapperWithRef from '@components/Form/InputWrapper';
import TextInput from '@components/TextInput';
Expand All @@ -19,6 +18,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import IOURequestStepRoutePropTypes from './IOURequestStepRoutePropTypes';
import StepScreenWrapper from './StepScreenWrapper';
import withFullTransactionOrNotFound from './withFullTransactionOrNotFound';
import withWritableReportOrNotFound from './withWritableReportOrNotFound';

const propTypes = {
Expand Down Expand Up @@ -119,11 +119,4 @@ IOURequestStepDescription.propTypes = propTypes;
IOURequestStepDescription.defaultProps = defaultProps;
IOURequestStepDescription.displayName = 'IOURequestStepDescription';

export default compose(
withWritableReportOrNotFound,
withOnyx({
transaction: {
key: ({route}) => `${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${lodashGet(route, 'params.transactionID', '0')}`,
},
}),
)(IOURequestStepDescription);
export default compose(withWritableReportOrNotFound, withFullTransactionOrNotFound)(IOURequestStepDescription);
12 changes: 2 additions & 10 deletions src/pages/iou/request/step/IOURequestStepDistance.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import lodashGet from 'lodash/get';
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
import Button from '@components/Button';
import DistanceRequestFooter from '@components/DistanceRequest/DistanceRequestFooter';
Expand All @@ -22,10 +21,10 @@ import variables from '@styles/variables';
import * as IOU from '@userActions/IOU';
import * as MapboxToken from '@userActions/MapboxToken';
import * as Transaction from '@userActions/Transaction';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import IOURequestStepRoutePropTypes from './IOURequestStepRoutePropTypes';
import StepScreenWrapper from './StepScreenWrapper';
import withFullTransactionOrNotFound from './withFullTransactionOrNotFound';
import withWritableReportOrNotFound from './withWritableReportOrNotFound';

const propTypes = {
Expand Down Expand Up @@ -231,11 +230,4 @@ IOURequestStepDistance.displayName = 'IOURequestStepDistance';
IOURequestStepDistance.propTypes = propTypes;
IOURequestStepDistance.defaultProps = defaultProps;

export default compose(
withWritableReportOrNotFound,
withOnyx({
transaction: {
key: ({route}) => `${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${lodashGet(route, 'params.transactionID', '0')}`,
},
}),
)(IOURequestStepDistance);
export default compose(withWritableReportOrNotFound, withFullTransactionOrNotFound)(IOURequestStepDistance);
12 changes: 2 additions & 10 deletions src/pages/iou/request/step/IOURequestStepMerchant.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import lodashGet from 'lodash/get';
import React, {useCallback} from 'react';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
import FormProvider from '@components/Form/FormProvider';
import InputWrapper from '@components/Form/InputWrapper';
Expand All @@ -18,6 +16,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import IOURequestStepRoutePropTypes from './IOURequestStepRoutePropTypes';
import StepScreenWrapper from './StepScreenWrapper';
import withFullTransactionOrNotFound from './withFullTransactionOrNotFound';
import withWritableReportOrNotFound from './withWritableReportOrNotFound';

const propTypes = {
Expand Down Expand Up @@ -107,11 +106,4 @@ IOURequestStepMerchant.propTypes = propTypes;
IOURequestStepMerchant.defaultProps = defaultProps;
IOURequestStepMerchant.displayName = 'IOURequestStepMerchant';

export default compose(
withWritableReportOrNotFound,
withOnyx({
transaction: {
key: ({route}) => `${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${lodashGet(route, 'params.transactionID', '0')}`,
},
}),
)(IOURequestStepMerchant);
export default compose(withWritableReportOrNotFound, withFullTransactionOrNotFound)(IOURequestStepMerchant);
12 changes: 2 additions & 10 deletions src/pages/iou/request/step/IOURequestStepParticipants.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import lodashGet from 'lodash/get';
import React, {useCallback, useEffect, useRef} from 'react';
import {withOnyx} from 'react-native-onyx';
import transactionPropTypes from '@components/transactionPropTypes';
import useLocalize from '@hooks/useLocalize';
import compose from '@libs/compose';
Expand All @@ -10,10 +9,10 @@ import * as TransactionUtils from '@libs/TransactionUtils';
import MoneyRequestParticipantsSelector from '@pages/iou/request/MoneyTemporaryForRefactorRequestParticipantsSelector';
import * as IOU from '@userActions/IOU';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import IOURequestStepRoutePropTypes from './IOURequestStepRoutePropTypes';
import StepScreenWrapper from './StepScreenWrapper';
import withFullTransactionOrNotFound from './withFullTransactionOrNotFound';
import withWritableReportOrNotFound from './withWritableReportOrNotFound';

const propTypes = {
Expand Down Expand Up @@ -101,11 +100,4 @@ IOURequestStepParticipants.displayName = 'IOURequestStepParticipants';
IOURequestStepParticipants.propTypes = propTypes;
IOURequestStepParticipants.defaultProps = defaultProps;

export default compose(
withWritableReportOrNotFound,
withOnyx({
transaction: {
key: ({route}) => `${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${lodashGet(route, 'params.transactionID', 0)}`,
},
}),
)(IOURequestStepParticipants);
export default compose(withWritableReportOrNotFound, withFullTransactionOrNotFound)(IOURequestStepParticipants);
6 changes: 2 additions & 4 deletions src/pages/iou/request/step/IOURequestStepTag.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import lodashGet from 'lodash/get';
import React from 'react';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
Expand All @@ -17,6 +16,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import IOURequestStepRoutePropTypes from './IOURequestStepRoutePropTypes';
import StepScreenWrapper from './StepScreenWrapper';
import withFullTransactionOrNotFound from './withFullTransactionOrNotFound';
import withWritableReportOrNotFound from './withWritableReportOrNotFound';

const propTypes = {
Expand Down Expand Up @@ -96,12 +96,10 @@ IOURequestStepTag.defaultProps = defaultProps;

export default compose(
withWritableReportOrNotFound,
withFullTransactionOrNotFound,
withOnyx({
policyTags: {
key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${report ? report.policyID : '0'}`,
},
transaction: {
key: ({route}) => `${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${lodashGet(route, 'params.transactionID', 0)}`,
},
}),
)(IOURequestStepTag);
5 changes: 2 additions & 3 deletions src/pages/iou/request/step/IOURequestStepWaypoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import IOURequestStepRoutePropTypes from './IOURequestStepRoutePropTypes';
import withFullTransactionOrNotFound from './withFullTransactionOrNotFound';
import withWritableReportOrNotFound from './withWritableReportOrNotFound';

const propTypes = {
Expand Down Expand Up @@ -254,10 +255,8 @@ IOURequestStepWaypoint.defaultProps = defaultProps;

export default compose(
withWritableReportOrNotFound,
withFullTransactionOrNotFound,
withOnyx({
transaction: {
key: ({route}) => `${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${lodashGet(route, 'params.transactionID', 0)}`,
},
recentWaypoints: {
key: ONYXKEYS.NVP_RECENT_WAYPOINTS,

Expand Down
68 changes: 68 additions & 0 deletions src/pages/iou/request/step/withFullTransactionOrNotFound.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import lodashGet from 'lodash/get';
import PropTypes from 'prop-types';
import React from 'react';
import {withOnyx} from 'react-native-onyx';
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView';
import transactionPropTypes from '@components/transactionPropTypes';
import getComponentDisplayName from '@libs/getComponentDisplayName';
import ONYXKEYS from '@src/ONYXKEYS';
import IOURequestStepRoutePropTypes from './IOURequestStepRoutePropTypes';

const propTypes = {
/** The HOC takes an optional ref as a prop and passes it as a ref to the wrapped component.
* That way, if a ref is passed to a component wrapped in the HOC, the ref is a reference to the wrapped component, not the HOC. */
forwardedRef: PropTypes.func,

/** The report corresponding to the reportID in the route params */
transaction: transactionPropTypes,

route: IOURequestStepRoutePropTypes.isRequired,
};

const defaultProps = {
forwardedRef: () => {},
transaction: {},
};

export default function (WrappedComponent) {
// eslint-disable-next-line rulesdir/no-negated-variables
function WithFullTransactionOrNotFound({forwardedRef, ...props}) {
const {
transaction: {transactionID},
} = props;

// If the transaction does not have a transactionID, then the transaction no longer exists in Onyx as a full transaction and the not-found page should be shown
if (!transactionID) {
return <FullPageNotFoundView shouldShow />;
}

return (
<WrappedComponent
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
ref={forwardedRef}
/>
);
}

WithFullTransactionOrNotFound.propTypes = propTypes;
WithFullTransactionOrNotFound.defaultProps = defaultProps;
WithFullTransactionOrNotFound.displayName = `withFullTransactionOrNotFound(${getComponentDisplayName(WrappedComponent)})`;

// eslint-disable-next-line rulesdir/no-negated-variables
const WithFullTransactionOrNotFoundWithRef = React.forwardRef((props, ref) => (
<WithFullTransactionOrNotFound
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
forwardedRef={ref}
/>
));

WithFullTransactionOrNotFoundWithRef.displayName = 'WithFullTransactionOrNotFoundWithRef';

return withOnyx({
transaction: {
key: ({route}) => `${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${lodashGet(route, 'params.transactionID', 0)}`,
},
})(WithFullTransactionOrNotFoundWithRef);
}

0 comments on commit 968f39f

Please sign in to comment.