Skip to content

Commit

Permalink
Merge pull request #28893 from DylanDylann/fix/28347
Browse files Browse the repository at this point in the history
Fix/28347 Navaigate back when reloading in scan receipt
  • Loading branch information
luacmartins authored Oct 17, 2023
2 parents 9390cf1 + 6c9c98f commit c498ab5
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/pages/iou/steps/MoneyRequestConfirmPage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useCallback, useEffect, useMemo, useRef} from 'react';
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import {View} from 'react-native';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
Expand Down Expand Up @@ -67,6 +67,7 @@ function MoneyRequestConfirmPage(props) {
const isDistanceRequest = MoneyRequestUtils.isDistanceRequest(iouType.current, props.selectedTab);
const isScanRequest = MoneyRequestUtils.isScanRequest(props.selectedTab);
const reportID = useRef(lodashGet(props.route, 'params.reportID', ''));
const [receiptFile, setReceiptFile] = useState();
const participants = useMemo(
() =>
_.map(props.iou.participants, (participant) => {
Expand Down Expand Up @@ -94,6 +95,21 @@ function MoneyRequestConfirmPage(props) {
}
}, [isOffline, participants, props.iou.billable, props.policy]);

useEffect(() => {
if (!props.iou.receiptPath || !props.iou.receiptFilename) {
return;
}
FileUtils.readFileAsync(props.iou.receiptPath, props.iou.receiptFilename).then((file) => {
if (!file) {
Navigation.goBack(ROUTES.MONEY_REQUEST.getRoute(iouType.current, reportID.current));
} else {
const receipt = file;
receipt.state = file && isManualRequestDM ? CONST.IOU.RECEIPT_STATE.OPEN : CONST.IOU.RECEIPT_STATE.SCANREADY;
setReceiptFile(receipt);
}
});
}, [props.iou.receiptPath, props.iou.receiptFilename, isManualRequestDM]);

useEffect(() => {
// ID in Onyx could change by initiating a new request in a separate browser tab or completing a request
if (!isDistanceRequest && prevMoneyRequestId.current !== props.iou.id) {
Expand Down Expand Up @@ -240,12 +256,8 @@ function MoneyRequestConfirmPage(props) {
return;
}

if (props.iou.receiptPath && props.iou.receiptFilename) {
FileUtils.readFileAsync(props.iou.receiptPath, props.iou.receiptFilename).then((file) => {
const receipt = file;
receipt.state = file && isManualRequestDM ? CONST.IOU.RECEIPT_STATE.OPEN : CONST.IOU.RECEIPT_STATE.SCANREADY;
requestMoney(selectedParticipants, trimmedComment, receipt);
});
if (receiptFile) {
requestMoney(selectedParticipants, trimmedComment, receiptFile);
return;
}

Expand All @@ -268,7 +280,7 @@ function MoneyRequestConfirmPage(props) {
isDistanceRequest,
requestMoney,
createDistanceRequest,
isManualRequestDM,
receiptFile,
],
);

Expand Down

0 comments on commit c498ab5

Please sign in to comment.