Skip to content

Show not found for invalid report or transaction in review duplicates confirmation page #45965

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
6 changes: 6 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5500,6 +5500,11 @@ function canAccessReport(report: OnyxEntry<Report>, policies: OnyxCollection<Pol
return true;
}

// eslint-disable-next-line rulesdir/no-negated-variables
function isReportNotFound(report: OnyxEntry<Report>): boolean {
return !!report?.errorFields?.notFound;
}

/**
* Check if the report is the parent report of the currently viewed report or at least one child report has report action
*/
Expand Down Expand Up @@ -7449,6 +7454,7 @@ export {
buildParticipantsFromAccountIDs,
buildTransactionThread,
canAccessReport,
isReportNotFound,
canAddTransaction,
canDeleteTransaction,
canBeAutoReimbursed,
Expand Down
37 changes: 32 additions & 5 deletions src/pages/TransactionDuplicate/Confirmation.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import type {RouteProp} from '@react-navigation/native';
import {useRoute} from '@react-navigation/native';
import React, {useCallback, useMemo} from 'react';
import {useNavigation, useRoute} from '@react-navigation/native';
import React, {useCallback, useEffect, useMemo, useState} from 'react';
import {View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import {useOnyx} from 'react-native-onyx';
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView';
import Button from '@components/Button';
import FixedFooter from '@components/FixedFooter';
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import MoneyRequestView from '@components/ReportActionItem/MoneyRequestView';
import ScreenWrapper from '@components/ScreenWrapper';
Expand All @@ -20,19 +21,24 @@ import type {TransactionDuplicateNavigatorParamList} from '@libs/Navigation/type
import variables from '@styles/variables';
import * as IOU from '@src/libs/actions/IOU';
import * as ReportActionsUtils from '@src/libs/ReportActionsUtils';
import * as ReportUtils from '@src/libs/ReportUtils';
import * as TransactionUtils from '@src/libs/TransactionUtils';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import type {Transaction} from '@src/types/onyx';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue';

function Confirmation() {
const styles = useThemeStyles();
const {translate} = useLocalize();
const navigation = useNavigation();
const route = useRoute<RouteProp<TransactionDuplicateNavigatorParamList, typeof SCREENS.TRANSACTION_DUPLICATE.REVIEW>>();
const [reviewDuplicates] = useOnyx(ONYXKEYS.REVIEW_DUPLICATES);
const [isExitingPage, setIsExitingPage] = useState(false);
const [reviewDuplicates, reviewDuplicatesResult] = useOnyx(ONYXKEYS.REVIEW_DUPLICATES);
const transaction = useMemo(() => TransactionUtils.buildNewTransactionAfterReviewingDuplicates(reviewDuplicates), [reviewDuplicates]);
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${route.params.threadReportID}`);
const [report, reportResult] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${route.params.threadReportID}`);
const [reportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transaction?.reportID}`);
const reportAction = Object.values(reportActions ?? {}).find(
(action) => ReportActionsUtils.isMoneyRequestAction(action) && ReportActionsUtils.getOriginalMessage(action)?.IOUTransactionID === reviewDuplicates?.transactionID,
Expand All @@ -56,13 +62,34 @@ function Confirmation() {
[report, reportAction],
);

useEffect(() => {
const unsubscribeBeforeRemove = navigation.addListener('beforeRemove', () => {
setIsExitingPage(true);
});

return unsubscribeBeforeRemove;
}, [navigation]);

const doesTransactionBelongToReport = TransactionUtils.getTransactionID(report?.reportID ?? '') === transaction.transactionID;
Copy link
Contributor Author

@gijoe0295 gijoe0295 Aug 1, 2024

Choose a reason for hiding this comment

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

When you replaced the reportID in URL with any valid transaction thread report ID, it would still show transaction data from that thread report (which is not the correct transaction from reviewDuplicates. We should check if the transaction from reviewDuplicates matches/belongs to report.


// eslint-disable-next-line rulesdir/no-negated-variables
const shouldShowNotFoundPage =
isEmptyObject(report) ||
!ReportUtils.isValidReport(report) ||
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When report has been loaded from Onyx but was still loading from the BE, it's prefilled with reportName without reportID.

ReportUtils.isReportNotFound(report) ||
(!isExitingPage && reviewDuplicatesResult.status === 'loaded' && (!transaction?.transactionID || !doesTransactionBelongToReport));

if (isLoadingOnyxValue(reviewDuplicatesResult, reportResult)) {
return <FullScreenLoadingIndicator />;
}

return (
<ScreenWrapper
testID={Confirmation.displayName}
shouldShowOfflineIndicator
>
{({safeAreaPaddingBottomStyle}) => (
<FullPageNotFoundView shouldShow={!reviewDuplicates}>
<FullPageNotFoundView shouldShow={shouldShowNotFoundPage}>
<View style={[styles.flex1, safeAreaPaddingBottomStyle]}>
<HeaderWithBackButton title={translate('iou.reviewDuplicates')} />
<ScrollView>
Expand Down
Loading