Skip to content

Commit 88cbac4

Browse files
authored
Merge pull request Expensify#65753 from Expensify/cmartins-fixreview
Generate thread if needed
2 parents 5b0b4d1 + a0d17fe commit 88cbac4

2 files changed

Lines changed: 41 additions & 6 deletions

File tree

src/components/MoneyReportHeader.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import useSelectedTransactionsActions from '@hooks/useSelectedTransactionsAction
1717
import useTheme from '@hooks/useTheme';
1818
import useThemeStyles from '@hooks/useThemeStyles';
1919
import {turnOffMobileSelectionMode} from '@libs/actions/MobileSelectionMode';
20-
import {deleteAppReport, downloadReportPDF, exportReportToCSV, exportReportToPDF, exportToIntegration, markAsManuallyExported, openUnreportedExpense} from '@libs/actions/Report';
20+
import {deleteAppReport, downloadReportPDF, exportReportToCSV, exportReportToPDF, exportToIntegration, markAsManuallyExported, openReport, openUnreportedExpense} from '@libs/actions/Report';
2121
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
2222
import {getThreadReportIDsForTransactions, getTotalAmountForIOUReportPreviewButton} from '@libs/MoneyRequestReportUtils';
2323
import Navigation from '@libs/Navigation/Navigation';
@@ -27,10 +27,11 @@ import {buildOptimisticNextStepForPreventSelfApprovalsEnabled} from '@libs/NextS
2727
import {isSecondaryActionAPaymentOption, selectPaymentType} from '@libs/PaymentUtils';
2828
import type {KYCFlowEvent, TriggerKYCFlow} from '@libs/PaymentUtils';
2929
import {getConnectedIntegration, getValidConnectedIntegration} from '@libs/PolicyUtils';
30-
import {getOriginalMessage, getReportAction, isMoneyRequestAction} from '@libs/ReportActionsUtils';
30+
import {getIOUActionForReportID, getOriginalMessage, getReportAction, isMoneyRequestAction} from '@libs/ReportActionsUtils';
3131
import {getAllExpensesToHoldIfApplicable, getReportPrimaryAction} from '@libs/ReportPrimaryActionUtils';
3232
import {getSecondaryExportReportActions, getSecondaryReportActions} from '@libs/ReportSecondaryActionUtils';
3333
import {
34+
buildTransactionThread,
3435
changeMoneyRequestHoldStatus,
3536
getArchiveReason,
3637
getIntegrationExportIcon,
@@ -678,9 +679,14 @@ function MoneyReportHeader({
678679
success
679680
text={translate('iou.reviewDuplicates')}
680681
onPress={() => {
681-
const threadID = transactionThreadReportID ?? getFirstDuplicateThreadID(transactions, reportActions);
682+
let threadID = transactionThreadReportID ?? getFirstDuplicateThreadID(transactions, reportActions);
682683
if (!threadID) {
683-
return;
684+
const duplicateTransaction = transactions.find((reportTransaction) => isDuplicate(reportTransaction));
685+
const transactionID = duplicateTransaction?.transactionID;
686+
const iouAction = getIOUActionForReportID(moneyRequestReport?.reportID, transactionID);
687+
const optimisticTransactionThread = buildTransactionThread(iouAction, moneyRequestReport);
688+
threadID = optimisticTransactionThread.reportID;
689+
openReport(threadID, undefined, session?.email ? [session?.email] : [], optimisticTransactionThread, iouAction?.reportActionID);
684690
}
685691
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_PAGE.getRoute(threadID));
686692
}}

src/pages/TransactionDuplicate/Review.tsx

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import {useRoute} from '@react-navigation/native';
2-
import React, {useMemo} from 'react';
2+
import React, {useEffect, useMemo} from 'react';
33
import {View} from 'react-native';
44
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView';
55
import Button from '@components/Button';
66
import HeaderWithBackButton from '@components/HeaderWithBackButton';
7+
import ReportActionsSkeletonView from '@components/ReportActionsSkeletonView';
8+
import ReportHeaderSkeletonView from '@components/ReportHeaderSkeletonView';
79
import ScreenWrapper from '@components/ScreenWrapper';
810
import Text from '@components/Text';
911
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
1012
import useLocalize from '@hooks/useLocalize';
1113
import useOnyx from '@hooks/useOnyx';
1214
import useThemeStyles from '@hooks/useThemeStyles';
1315
import useTransactionViolations from '@hooks/useTransactionViolations';
16+
import {openReport} from '@libs/actions/Report';
1417
import {dismissDuplicateTransactionViolation} from '@libs/actions/Transaction';
1518
import Navigation from '@libs/Navigation/Navigation';
1619
import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types';
@@ -28,6 +31,7 @@ function TransactionDuplicateReview() {
2831
const route = useRoute<PlatformStackRouteProp<TransactionDuplicateNavigatorParamList, typeof SCREENS.TRANSACTION_DUPLICATE.REVIEW>>();
2932
const currentPersonalDetails = useCurrentUserPersonalDetails();
3033
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${route.params.threadReportID}`, {canBeMissing: true});
34+
const [reportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${route.params.threadReportID}`, {canBeMissing: true});
3135
const reportAction = getReportAction(report?.parentReportID, report?.parentReportActionID);
3236
const transactionID = getLinkedTransactionID(reportAction, report?.reportID) ?? undefined;
3337
const transactionViolations = useTransactionViolations(transactionID);
@@ -56,9 +60,34 @@ function TransactionDuplicateReview() {
5660

5761
const hasSettledOrApprovedTransaction = transactions?.some((transaction) => isSettled(transaction?.reportID) || isReportIDApproved(transaction?.reportID));
5862

63+
useEffect(() => {
64+
if (!route.params.threadReportID || report?.reportID) {
65+
return;
66+
}
67+
openReport(route.params.threadReportID);
68+
}, [report?.reportID, route.params.threadReportID]);
69+
70+
const isLoadingPage = (!report?.reportID && reportMetadata?.isLoadingInitialReportActions !== false) || !reportAction?.reportActionID;
71+
72+
// eslint-disable-next-line rulesdir/no-negated-variables
73+
const shouldShowNotFound = !isLoadingPage && !transactionID;
74+
75+
if (isLoadingPage) {
76+
return (
77+
<ScreenWrapper testID={TransactionDuplicateReview.displayName}>
78+
<View style={[styles.flex1]}>
79+
<View style={[styles.appContentHeader, styles.borderBottom]}>
80+
<ReportHeaderSkeletonView onBackButtonPress={() => {}} />
81+
</View>
82+
<ReportActionsSkeletonView />
83+
</View>
84+
</ScreenWrapper>
85+
);
86+
}
87+
5988
return (
6089
<ScreenWrapper testID={TransactionDuplicateReview.displayName}>
61-
<FullPageNotFoundView shouldShow={!transactionID}>
90+
<FullPageNotFoundView shouldShow={shouldShowNotFound}>
6291
<HeaderWithBackButton
6392
title={translate('iou.reviewDuplicates')}
6493
onBackButtonPress={() => Navigation.goBack(route.params.backTo)}

0 commit comments

Comments
 (0)