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 6 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 @@ -5377,6 +5377,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 @@ -7287,6 +7292,7 @@ export {
buildParticipantsFromAccountIDs,
buildTransactionThread,
canAccessReport,
isReportNotFound,
canAddOrDeleteTransactions,
canBeAutoReimbursed,
canCreateRequest,
Expand Down
28 changes: 24 additions & 4 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,17 +21,21 @@ 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';

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 [isExiting, setIsExiting] = useState(false);
const [reviewDuplicates, {status}] = useOnyx(ONYXKEYS.REVIEW_DUPLICATES);
const transaction = useMemo(() => TransactionUtils.buildNewTransactionAfterReviewingDuplicates(reviewDuplicates), [reviewDuplicates]);
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${route.params.threadReportID}`);
const [reportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transaction?.reportID}`);
Expand All @@ -56,13 +61,28 @@ function Confirmation() {
[report, reportAction],
);

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

return unsubscribeBeforeRemove;
}, [navigation]);

if (status === 'loading') {
return <FullScreenLoadingIndicator />;
Copy link
Contributor Author

@gijoe0295 gijoe0295 Jul 25, 2024

Choose a reason for hiding this comment

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

Due to the isExiting check as explained above, we should show a loading indicator when the data is loading, otherwise we would have empty data shows briefly.

}

// eslint-disable-next-line rulesdir/no-negated-variables
const shouldShowNotFoundPage = isEmptyObject(report) || ReportUtils.isReportNotFound(report) || (!isExiting && status === 'loaded' && !transaction?.transactionID);
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 reportID is invalid, report can either be undefined or have errorFields.notFound (on large screens only since the underneath ReportScreen would fetch report data by OpenReport).

REVIEW_DUPLICATES entry takes a long time to load, we need to wait for it by status.

When we close the confirmation page RHP, it would be reset due to:

abandonReviewDuplicateTransactions();

so not found page would briefly show when the RHP is closing. isExiting check was added for that.

Copy link
Member

Choose a reason for hiding this comment

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

I see. Is there a better way to manage the abandonReviewDuplicateTransactions(); without mixing navigation logic on this component? Maybe we delegate this function call when navigation is completed. For example, using transitionEnd event instead of blur if that go hand-in-hand replacement for that.

Copy link
Contributor Author

@gijoe0295 gijoe0295 Jul 31, 2024

Choose a reason for hiding this comment

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

@parasharrajat As you've reviewed the duplicate confirmation PR, could you let me know what these lines are for?

if (
// @ts-expect-error There is something wrong with a types here and it's don't see the params list
navigation.getState().routes.find((routes) => routes.name === NAVIGATORS.RIGHT_MODAL_NAVIGATOR)?.params?.screen ===
SCREENS.RIGHT_MODAL.TRANSACTION_DUPLICATE ||
route.params?.screen !== SCREENS.RIGHT_MODAL.TRANSACTION_DUPLICATE
) {
return;
}

In other words, when exactly should abandonReviewDuplicateTransactions be called?

I just want to confirm if transitionEnd could replace blur.

Copy link
Member

@parasharrajat parasharrajat Jul 31, 2024

Choose a reason for hiding this comment

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

This tells that If user is leaving from TRANSACTION_DUPLICATE Modal Stack from RHN view.

Copy link
Contributor Author

@gijoe0295 gijoe0295 Jul 31, 2024

Choose a reason for hiding this comment

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

@parasharrajat transitionEnd does not fire when closing the RHP. Last resort may be setTimeout?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Even if transitionEnd worked, the page would unmount then so we couldn't find it in navigation state.

Copy link
Member

Choose a reason for hiding this comment

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

OK. I am fine with the approach for now.


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