Skip to content

Commit 1c550a3

Browse files
authored
Merge pull request Expensify#67479 from nkdengineer/fix/67142-1
Fix creating second scan expense unexpected error is shown
2 parents feae7c5 + 8ad0014 commit 1c550a3

8 files changed

Lines changed: 66 additions & 5 deletions
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import {useMemo} from 'react';
2+
import type {ValueOf} from 'type-fest';
3+
import {canEditFieldOfMoneyRequest} from '@libs/ReportUtils';
4+
import type {IOUAction, IOUType} from '@src/CONST';
5+
import CONST from '@src/CONST';
6+
import ONYXKEYS from '@src/ONYXKEYS';
7+
import type {OnyxInputOrEntry, Report} from '@src/types/onyx';
8+
import useOnyx from './useOnyx';
9+
10+
// eslint-disable-next-line rulesdir/no-negated-variables
11+
const useShowNotFoundPageInIOUStep = (action: IOUAction, iouType: IOUType, report: OnyxInputOrEntry<Report>, fieldToEdit: ValueOf<typeof CONST.EDIT_REQUEST_FIELD>) => {
12+
const isEditing = action === CONST.IOU.ACTION.EDIT;
13+
const reportActionsReportID = useMemo(() => {
14+
let actionsReportID;
15+
if (isEditing) {
16+
actionsReportID = iouType === CONST.IOU.TYPE.SPLIT ? report?.reportID : report?.parentReportID;
17+
}
18+
return actionsReportID;
19+
}, [isEditing, iouType, report?.reportID, report?.parentReportID]);
20+
21+
const [reportAction] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportActionsReportID}`, {
22+
canEvict: false,
23+
canBeMissing: true,
24+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
25+
selector: (reportActions) => reportActions?.[`${report?.parentReportActionID}`],
26+
});
27+
return isEditing && !canEditFieldOfMoneyRequest(reportAction, fieldToEdit);
28+
};
29+
30+
export default useShowNotFoundPageInIOUStep;

src/pages/iou/request/step/IOURequestEditReportCommon.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,19 @@ type Props = {
4848
removeFromReport?: () => void;
4949
isEditing?: boolean;
5050
isUnreported?: boolean;
51+
shouldShowNotFoundPage?: boolean;
5152
};
5253

53-
function IOURequestEditReportCommon({backTo, transactionsReports, selectReport, policyID: policyIDFromProps, removeFromReport, isEditing = false, isUnreported}: Props) {
54+
function IOURequestEditReportCommon({
55+
backTo,
56+
transactionsReports,
57+
selectReport,
58+
policyID: policyIDFromProps,
59+
removeFromReport,
60+
isEditing = false,
61+
isUnreported,
62+
shouldShowNotFoundPage = false,
63+
}: Props) {
5464
const {translate, localeCompare} = useLocalize();
5565
const {options} = useOptionsList();
5666
const [allReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {selector: (reports) => mapOnyxCollectionItems(reports, reportSelector), canBeMissing: true});
@@ -119,7 +129,7 @@ function IOURequestEditReportCommon({backTo, transactionsReports, selectReport,
119129
shouldShowWrapper
120130
testID="IOURequestEditReportCommon"
121131
includeSafeAreaPaddingBottom
122-
shouldShowNotFoundPage={expenseReports.length === 0}
132+
shouldShowNotFoundPage={expenseReports.length === 0 || shouldShowNotFoundPage}
123133
>
124134
<SelectionList
125135
sections={[{data: reportOptions}]}

src/pages/iou/request/step/IOURequestStepAmount.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {WithCurrentUserPersonalDetailsProps} from '@components/withCurrentU
77
import useDuplicateTransactionsAndViolations from '@hooks/useDuplicateTransactionsAndViolations';
88
import useLocalize from '@hooks/useLocalize';
99
import useOnyx from '@hooks/useOnyx';
10+
import useShowNotFoundPageInIOUStep from '@hooks/useShowNotFoundPageInIOUStep';
1011
import {createDraftTransaction, removeDraftTransaction} from '@libs/actions/TransactionEdit';
1112
import {convertToBackendAmount, isValidCurrencyCode} from '@libs/CurrencyUtils';
1213
import {navigateToParticipantPage} from '@libs/IOUUtils';
@@ -92,6 +93,8 @@ function IOURequestStepAmount({
9293
const {amount: transactionAmount} = getTransactionDetails(currentTransaction) ?? {amount: 0};
9394
const {currency: originalCurrency} = getTransactionDetails(isEditing && !isEmptyObject(draftTransaction) ? draftTransaction : transaction) ?? {currency: CONST.CURRENCY.USD};
9495
const currency = isValidCurrencyCode(selectedCurrency) ? selectedCurrency : originalCurrency;
96+
// eslint-disable-next-line rulesdir/no-negated-variables
97+
const shouldShowNotFoundPage = useShowNotFoundPageInIOUStep(action, iouType, report, CONST.EDIT_REQUEST_FIELD.AMOUNT);
9598

9699
// For quick button actions, we'll skip the confirmation page unless the report is archived or this is a workspace request, as
97100
// the user will have to add a merchant.
@@ -315,6 +318,7 @@ function IOURequestStepAmount({
315318
testID={IOURequestStepAmount.displayName}
316319
shouldShowWrapper={!!backTo || isEditing}
317320
includeSafeAreaPaddingBottom
321+
shouldShowNotFoundPage={shouldShowNotFoundPage}
318322
>
319323
<MoneyRequestAmountForm
320324
isEditing={!!backTo || isEditing}

src/pages/iou/request/step/IOURequestStepDate.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ function IOURequestStepDate({
8181
shouldShowNotFound = !canEditMoneyRequest && !canEditingSplitBill;
8282
} else if (isSplitExpense) {
8383
shouldShowNotFound = !canEditSplitExpense;
84+
} else {
85+
shouldShowNotFound = !canEditMoneyRequest;
8486
}
8587
}
8688

src/pages/iou/request/step/IOURequestStepDistance.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import useNetwork from '@hooks/useNetwork';
1919
import useOnyx from '@hooks/useOnyx';
2020
import usePolicy from '@hooks/usePolicy';
2121
import usePrevious from '@hooks/usePrevious';
22+
import useShowNotFoundPageInIOUStep from '@hooks/useShowNotFoundPageInIOUStep';
2223
import useThemeStyles from '@hooks/useThemeStyles';
2324
import {
2425
createDistanceRequest,
@@ -139,6 +140,8 @@ function IOURequestStepDistance({
139140
const [recentWaypoints, {status: recentWaypointsStatus}] = useOnyx(ONYXKEYS.NVP_RECENT_WAYPOINTS, {canBeMissing: true});
140141
const iouRequestType = getRequestType(transaction);
141142
const customUnitRateID = getRateID(transaction);
143+
// eslint-disable-next-line rulesdir/no-negated-variables
144+
const shouldShowNotFoundPage = useShowNotFoundPageInIOUStep(action, iouType, report, CONST.EDIT_REQUEST_FIELD.DISTANCE);
142145

143146
// Sets `amount` and `split` share data before moving to the next step to avoid briefly showing `0.00` as the split share for participants
144147
const setDistanceRequestData = useCallback(
@@ -529,7 +532,7 @@ function IOURequestStepDistance({
529532
headerTitle={translate('common.distance')}
530533
onBackButtonPress={navigateBack}
531534
testID={IOURequestStepDistance.displayName}
532-
shouldShowNotFoundPage={isEditing && !transaction?.comment?.waypoints}
535+
shouldShowNotFoundPage={(isEditing && !transaction?.comment?.waypoints) || shouldShowNotFoundPage}
533536
shouldShowWrapper={!isCreatingNewRequest}
534537
>
535538
<>

src/pages/iou/request/step/IOURequestStepDistanceRate.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import RadioListItem from '@components/SelectionList/RadioListItem';
55
import Text from '@components/Text';
66
import useLocalize from '@hooks/useLocalize';
77
import useOnyx from '@hooks/useOnyx';
8+
import useShowNotFoundPageInIOUStep from '@hooks/useShowNotFoundPageInIOUStep';
89
import useThemeStyles from '@hooks/useThemeStyles';
910
import {getIOURequestPolicyID, setMoneyRequestDistanceRate, setMoneyRequestTaxAmount, setMoneyRequestTaxRate, updateMoneyRequestDistanceRate} from '@libs/actions/IOU';
1011
import {convertToBackendAmount} from '@libs/CurrencyUtils';
@@ -32,7 +33,7 @@ function IOURequestStepDistanceRate({
3233
report,
3334
reportDraft,
3435
route: {
35-
params: {action, reportID, backTo, transactionID},
36+
params: {action, reportID, backTo, transactionID, iouType},
3637
},
3738
transaction,
3839
}: IOURequestStepDistanceRateProps) {
@@ -74,6 +75,8 @@ function IOURequestStepDistanceRate({
7475
isSelected,
7576
};
7677
});
78+
// eslint-disable-next-line rulesdir/no-negated-variables
79+
const shouldShowNotFoundPage = useShowNotFoundPageInIOUStep(action, iouType, report, CONST.EDIT_REQUEST_FIELD.DISTANCE_RATE);
7780

7881
const initiallyFocusedOption = sections.find((item) => item.isSelected)?.keyForList;
7982

@@ -108,6 +111,7 @@ function IOURequestStepDistanceRate({
108111
onBackButtonPress={navigateBack}
109112
shouldShowWrapper
110113
testID={IOURequestStepDistanceRate.displayName}
114+
shouldShowNotFoundPage={shouldShowNotFoundPage}
111115
>
112116
<Text style={[styles.mh5, styles.mv4]}>{translate('iou.chooseARate')}</Text>
113117

src/pages/iou/request/step/IOURequestStepMerchant.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import useAutoFocusInput from '@hooks/useAutoFocusInput';
88
import useLocalize from '@hooks/useLocalize';
99
import useOnyx from '@hooks/useOnyx';
1010
import usePolicy from '@hooks/usePolicy';
11+
import useShowNotFoundPageInIOUStep from '@hooks/useShowNotFoundPageInIOUStep';
1112
import useThemeStyles from '@hooks/useThemeStyles';
1213
import Navigation from '@libs/Navigation/Navigation';
1314
import {getTransactionDetails, isExpenseRequest, isPolicyExpenseChat} from '@libs/ReportUtils';
@@ -43,7 +44,8 @@ function IOURequestStepMerchant({
4344
const {translate} = useLocalize();
4445
const {inputCallbackRef} = useAutoFocusInput();
4546
const isEditing = action === CONST.IOU.ACTION.EDIT;
46-
47+
// eslint-disable-next-line rulesdir/no-negated-variables
48+
const shouldShowNotFoundPage = useShowNotFoundPageInIOUStep(action, iouType, report, CONST.EDIT_REQUEST_FIELD.MERCHANT);
4749
// In the split flow, when editing we use SPLIT_TRANSACTION_DRAFT to save draft value
4850
const isEditingSplitBill = iouType === CONST.IOU.TYPE.SPLIT && isEditing;
4951
const merchant = getTransactionDetails(isEditingSplitBill && !isEmptyObject(splitDraftTransaction) ? splitDraftTransaction : transaction)?.merchant;
@@ -114,6 +116,7 @@ function IOURequestStepMerchant({
114116
onBackButtonPress={navigateBack}
115117
shouldShowWrapper
116118
testID={IOURequestStepMerchant.displayName}
119+
shouldShowNotFoundPage={shouldShowNotFoundPage}
117120
>
118121
<FormProvider
119122
style={[styles.flexGrow1, styles.ph5]}

src/pages/iou/request/step/IOURequestStepReport.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import {InteractionManager} from 'react-native';
33
import type {ListItem} from '@components/SelectionList/types';
44
import useOnyx from '@hooks/useOnyx';
5+
import useShowNotFoundPageInIOUStep from '@hooks/useShowNotFoundPageInIOUStep';
56
import {changeTransactionsReport, setTransactionReport} from '@libs/actions/Transaction';
67
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
78
import Navigation from '@libs/Navigation/Navigation';
@@ -126,6 +127,9 @@ function IOURequestStepReport({route, transaction}: IOURequestStepReportProps) {
126127
Navigation.dismissModal();
127128
};
128129

130+
// eslint-disable-next-line rulesdir/no-negated-variables
131+
const shouldShowNotFoundPage = useShowNotFoundPageInIOUStep(action, iouType, reportOrDraftReport, CONST.EDIT_REQUEST_FIELD.REPORT);
132+
129133
return (
130134
<IOURequestEditReportCommon
131135
backTo={backTo}
@@ -135,6 +139,7 @@ function IOURequestStepReport({route, transaction}: IOURequestStepReportProps) {
135139
removeFromReport={removeFromReport}
136140
isEditing={isEditing}
137141
isUnreported={isUnreported}
142+
shouldShowNotFoundPage={shouldShowNotFoundPage}
138143
/>
139144
);
140145
}

0 commit comments

Comments
 (0)