Skip to content
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

fix: remove categorize page from navigation stack #45560

Merged
merged 4 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions src/pages/iou/request/step/IOURequestStepCategory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ function IOURequestStepCategory({
IOU.setMoneyRequestCategory(transactionID, updatedCategory);

if (action === CONST.IOU.ACTION.CATEGORIZE) {
Navigation.goBack();
Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(action, iouType, transactionID, report?.reportID ?? '-1'));
return;
}
Expand Down
22 changes: 20 additions & 2 deletions src/pages/iou/request/step/IOURequestStepConfirmation.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import {View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
Expand Down Expand Up @@ -40,6 +40,9 @@ import withWritableReportOrNotFound from './withWritableReportOrNotFound';
import type {WithWritableReportOrNotFoundProps} from './withWritableReportOrNotFound';

type IOURequestStepConfirmationOnyxProps = {
/** The policy collection */
allPolicies: OnyxEntry<OnyxCollection<Policy>>;

/** The policy of the report */
policy: OnyxEntry<Policy>;

Expand All @@ -61,6 +64,7 @@ type IOURequestStepConfirmationProps = IOURequestStepConfirmationOnyxProps &
WithFullTransactionOrNotFoundProps<typeof SCREENS.MONEY_REQUEST.STEP_CONFIRMATION>;

function IOURequestStepConfirmation({
allPolicies,
policy: policyReal,
policyDraft,
policyTags,
Expand Down Expand Up @@ -192,6 +196,17 @@ function IOURequestStepConfirmation({
}, [transactionID, requestType, defaultCategory]);

const navigateBack = useCallback(() => {
// If the action is categorize and there's no policies except personal one, we simply call goBack(), i.e: dismiss the whole flow together
if (
action === CONST.IOU.ACTION.CATEGORIZE &&
Object.values(allPolicies ?? {}).filter(
(individualPolicy) =>
individualPolicy && individualPolicy.type !== CONST.POLICY.TYPE.PERSONAL && individualPolicy.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's move this to PolicyUtils with something like hasOnlyPersonalPolicy or something.

Also, let's rename the individualPolicy to policy

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved!

).length === 0
) {
Navigation.goBack();
return;
}
// If there is not a report attached to the IOU with a reportID, then the participants were manually selected and the user needs taken
// back to the participants step
if (!transaction?.participantsAutoAssigned) {
Expand All @@ -200,7 +215,7 @@ function IOURequestStepConfirmation({
return;
}
IOUUtils.navigateToStartMoneyRequestStep(requestType, iouType, transactionID, reportID, action);
}, [transaction, iouType, requestType, transactionID, reportID, action]);
}, [transaction, iouType, requestType, transactionID, reportID, action, allPolicies]);

const navigateToAddReceipt = useCallback(() => {
Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_SCAN.getRoute(action, iouType, transactionID, reportID, Navigation.getActiveRouteWithoutParams()));
Expand Down Expand Up @@ -632,6 +647,9 @@ function IOURequestStepConfirmation({
IOURequestStepConfirmation.displayName = 'IOURequestStepConfirmation';

const IOURequestStepConfirmationWithOnyx = withOnyx<IOURequestStepConfirmationProps, IOURequestStepConfirmationOnyxProps>({
allPolicies: {
key: ONYXKEYS.COLLECTION.POLICY,
},
policy: {
key: ({report, transaction}) => `${ONYXKEYS.COLLECTION.POLICY}${IOU.getIOURequestPolicyID(transaction, report)}`,
},
Expand Down
Loading