Skip to content

Commit

Permalink
Merge pull request #16976 from Expensify/jack-cleanMoneyRequestModal
Browse files Browse the repository at this point in the history
Clean up MoneyRequestModal
  • Loading branch information
thienlnam authored May 12, 2023
2 parents 1de10c2 + 5b409ab commit 3fba7dc
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 29 deletions.
29 changes: 1 addition & 28 deletions src/pages/iou/MoneyRequestModal.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import _ from 'underscore';
import React, {useState, useEffect, useRef, useCallback, useMemo} from 'react';
import React, {useState, useEffect, useCallback, useMemo} from 'react';
import {View} from 'react-native';
import PropTypes from 'prop-types';
import lodashGet from 'lodash/get';
Expand All @@ -10,7 +10,6 @@ import MoneyRequestConfirmPage from './steps/MoneyRequestConfirmPage';
import ModalHeader from './ModalHeader';
import styles from '../../styles/styles';
import * as IOU from '../../libs/actions/IOU';
import Navigation from '../../libs/Navigation/Navigation';
import ONYXKEYS from '../../ONYXKEYS';
import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize';
import compose from '../../libs/compose';
Expand Down Expand Up @@ -44,9 +43,6 @@ const propTypes = {

// Holds data related to request view state, rather than the underlying request data.
iou: PropTypes.shape({
/** Whether or not transaction creation has started */
creatingIOUTransaction: PropTypes.bool,

/** Whether or not transaction creation has resulted to error */
error: PropTypes.bool,

Expand Down Expand Up @@ -86,7 +82,6 @@ const defaultProps = {
},
personalDetails: {},
iou: {
creatingIOUTransaction: false,
error: false,
selectedCurrencyCode: null,
},
Expand All @@ -106,7 +101,6 @@ const MoneyRequestModal = (props) => {
() => (reportParticipants.length ? [Steps.MoneyRequestAmount, Steps.MoneyRequestConfirm] : [Steps.MoneyRequestAmount, Steps.MoneyRequestParticipants, Steps.MoneyRequestConfirm]),
[reportParticipants.length],
);
const prevCreatingIOUTransactionStatusRef = useRef(lodashGet(props.iou, 'creatingIOUTransaction'));

const [previousStepIndex, setPreviousStepIndex] = useState(-1);
const [currentStepIndex, setCurrentStepIndex] = useState(0);
Expand All @@ -124,28 +118,9 @@ const MoneyRequestModal = (props) => {
// eslint-disable-next-line react-hooks/exhaustive-deps -- props.currentUserPersonalDetails will always exist from Onyx and we don't want this effect to run again
}, []);

useEffect(() => {
// We only want to check if we just finished creating an IOU transaction
// We check it within this effect because we're sending the request optimistically but if an error occurs from the API, we will update the iou state with the error later
if (!prevCreatingIOUTransactionStatusRef.current || lodashGet(props.iou, 'creatingIOUTransaction')) {
return;
}

if (lodashGet(props.iou, 'error') === true) {
setCurrentStepIndex(0);
} else {
Navigation.dismissModal();
}
}, [props.iou]);

// User came back online, so let's refetch the currency details based on location
useOnNetworkReconnect(PersonalDetails.openMoneyRequestModalPage);

useEffect(() => {
// Used to store previous prop values to compare on next render
prevCreatingIOUTransactionStatusRef.current = lodashGet(props.iou, 'creatingIOUTransaction');
});

/**
* Decides our animation type based on whether we're increasing or decreasing
* our step index.
Expand Down Expand Up @@ -374,12 +349,10 @@ const MoneyRequestModal = (props) => {
{modalHeader}
<MoneyRequestConfirmPage
onConfirm={(selectedParticipants) => {
// TODO: ADD HANDLING TO DISABLE BUTTON FUNCTIONALITY WHILE REQUEST IS IN FLIGHT
createTransaction(selectedParticipants);
ReportScrollManager.scrollToBottom();
}}
onSendMoney={(paymentMethodType) => {
// TODO: ADD HANDLING TO DISABLE BUTTON FUNCTIONALITY WHILE REQUEST IS IN FLIGHT
sendMoney(paymentMethodType);
ReportScrollManager.scrollToBottom();
}}
Expand Down
1 change: 0 additions & 1 deletion src/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export default function () {
[ONYXKEYS.IOU]: {
loading: false,
error: false,
creatingIOUTransaction: false,
},
[ONYXKEYS.IS_SIDEBAR_LOADED]: false,
[ONYXKEYS.SHOULD_SHOW_COMPOSE_INPUT]: true,
Expand Down

0 comments on commit 3fba7dc

Please sign in to comment.