Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions src/components/AttachmentModal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Str} from 'expensify-common';
import React, {memo, useCallback, useEffect, useMemo, useRef, useState} from 'react';
import {InteractionManager, Keyboard, View} from 'react-native';
import {Keyboard, View} from 'react-native';
import {GestureHandlerRootView} from 'react-native-gesture-handler';
import {useOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
Expand Down Expand Up @@ -198,6 +198,7 @@ function AttachmentModal({
const [isConfirmButtonDisabled, setIsConfirmButtonDisabled] = useState(false);
const [isDownloadButtonReadyToBeShown, setIsDownloadButtonReadyToBeShown] = React.useState(true);
const isPDFLoadError = useRef(false);
const isReplaceReceipt = useRef(false);
const {windowWidth} = useWindowDimensions();
const {shouldUseNarrowLayout} = useResponsiveLayout();
const nope = useSharedValue(false);
Expand Down Expand Up @@ -447,22 +448,15 @@ function AttachmentModal({

const menuItems = [];
if (canEditReceipt) {
// linter keep complain about accessing ref during render
// eslint-disable-next-line react-compiler/react-compiler
menuItems.push({
icon: Expensicons.Camera,
text: translate('common.replace'),
onSelected: () => {
closeModal(true);
InteractionManager.runAfterInteractions(() => {
Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_SCAN.getRoute(
iouAction ?? CONST.IOU.ACTION.EDIT,
iouType,
draftTransactionID ?? transaction?.transactionID,
report?.reportID,
Navigation.getActiveRouteWithoutParams(),
),
);
});
// Set the ref to true, so when the modal is hidden, we will navigate to the scan receipt screen
isReplaceReceipt.current = true;
},
});
}
Expand Down Expand Up @@ -534,6 +528,19 @@ function AttachmentModal({
setIsAttachmentInvalid(true);
setAttachmentInvalidReasonTitle('attachmentPicker.attachmentError');
setAttachmentInvalidReason('attachmentPicker.errorWhileSelectingCorruptedAttachment');
return;
}

if (isReplaceReceipt.current) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we put it in the bottom to ensure everything else is ran before nativgate?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't matter. The PDF error logic was added in #47832. I don't think there is a case where the PDF load error happens when adding attachment in a chat and the user press the replace option which is only available on the IOU confirm page at the same time.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, I still do it to keep it clean by using early return.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but at least, it should be put after setShouldLoadAttachment(false);. Btw, do we really need the early return above? As you mentioned, I think either is true, not both at the same time.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think putting the return early making it clearer. So, anyone reading this code will know that if isPDFLoadError is true, it will stop there.

Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_SCAN.getRoute(
iouAction ?? CONST.IOU.ACTION.EDIT,
iouType,
draftTransactionID ?? transaction?.transactionID,
report?.reportID,
Navigation.getActiveRouteWithoutParams(),
),
);
}
}}
propagateSwipe
Expand Down