diff --git a/src/pages/iou/MoneyRequestDescriptionPage.js b/src/pages/iou/MoneyRequestDescriptionPage.js index 17cfa139fe0d..2e6e459f1d96 100644 --- a/src/pages/iou/MoneyRequestDescriptionPage.js +++ b/src/pages/iou/MoneyRequestDescriptionPage.js @@ -88,7 +88,7 @@ function MoneyRequestDescriptionPage({iou, route}) { inputRef && inputRef.focus()} + onEntryTransitionEnd={() => inputRef.current && inputRef.current.focus()} > { + const moneyRequestId = `${iouType}${reportID}`; + const shouldReset = iou.id !== moneyRequestId; if (shouldReset) { IOU.resetMoneyRequestInfo(moneyRequestId); } - if (_.isEmpty(this.props.iou.participants) || (this.props.iou.amount === 0 && !this.props.iou.receiptPath) || shouldReset) { - Navigation.goBack(ROUTES.getMoneyRequestRoute(this.iouType, this.reportID), true); + if (_.isEmpty(iou.participants) || (iou.amount === 0 && !iou.receiptPath) || shouldReset) { + Navigation.goBack(ROUTES.getMoneyRequestRoute(iouType, reportID), true); } - } + }, [iou.id, iou.participants, iou.amount, iou.receiptPath, iouType, reportID]); - // eslint-disable-next-line rulesdir/prefer-early-return - componentDidUpdate(prevProps) { - // ID in Onyx could change by initiating a new request in a separate browser tab or completing a request - if (_.isEmpty(this.props.iou.participants) || (this.props.iou.amount === 0 && !this.props.iou.receiptPath) || prevProps.iou.id !== this.props.iou.id) { - // The ID is cleared on completing a request. In that case, we will do nothing. - if (this.props.iou.id) { - Navigation.goBack(ROUTES.getMoneyRequestRoute(this.iouType, this.reportID), true); - } - } - } - - navigateBack() { - Navigation.goBack(ROUTES.getMoneyRequestConfirmationRoute(this.iouType, this.reportID)); + function navigateBack() { + Navigation.goBack(ROUTES.getMoneyRequestConfirmationRoute(iouType, reportID)); } /** @@ -86,52 +68,49 @@ class MoneyRequestMerchantPage extends Component { * @param {Object} value * @param {String} value.moneyRequestMerchant */ - updateMerchant(value) { + function updateMerchant(value) { IOU.setMoneyRequestMerchant(value.moneyRequestMerchant); - this.navigateBack(); + navigateBack(); } - render() { - return ( - this.merchantInputRef && this.merchantInputRef.focus()} + return ( + inputRef.current && inputRef.current.focus()} + > + navigateBack()} + /> +
updateMerchant(value)} + submitButtonText={translate('common.save')} + enabledWhenOffline > - - - - (this.merchantInputRef = el)} - /> - - -
- ); - } + + (inputRef.current = el)} + /> + + +
+ ); } MoneyRequestMerchantPage.propTypes = propTypes; MoneyRequestMerchantPage.defaultProps = defaultProps; -export default compose( - withLocalize, - withOnyx({ - iou: {key: ONYXKEYS.IOU}, - }), -)(MoneyRequestMerchantPage); +export default withOnyx({ + iou: { + key: ONYXKEYS.IOU, + }, +})(MoneyRequestMerchantPage);