-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix - IOU - To field is empty and Amount is $NaN when opening confirm…
…ation page in another tab
- Loading branch information
Showing
12 changed files
with
96 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/pages/iou/request/step/withFullTransactionOrNotFound.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |