Skip to content

Commit

Permalink
fix: move function to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
dominictb committed Jul 22, 2024
1 parent c5132fb commit 5b8a940
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
8 changes: 8 additions & 0 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,13 @@ function isDeletedPolicyEmployee(policyEmployee: PolicyEmployee, isOffline: bool
return !isOffline && policyEmployee.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && isEmptyObject(policyEmployee.errors);
}

function hasNoPolicyOtherThanPersonalType() {
return (
Object.values(allPolicies ?? {}).filter((policy) => policy && policy.type !== CONST.POLICY.TYPE.PERSONAL && policy.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE)
.length === 0
);
}

export {
canEditTaxRate,
extractPolicyIDFromPath,
Expand Down Expand Up @@ -837,6 +844,7 @@ export {
getNameFromNetSuiteCustomField,
isNetSuiteCustomFieldPropertyEditable,
getCurrentSageIntacctEntityName,
hasNoPolicyOtherThanPersonalType,
};

export type {MemberEmailsToAccountIDs};
25 changes: 7 additions & 18 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 {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
Expand All @@ -21,6 +21,7 @@ import * as IOUUtils from '@libs/IOUUtils';
import Log from '@libs/Log';
import Navigation from '@libs/Navigation/Navigation';
import * as OptionsListUtils from '@libs/OptionsListUtils';
import * as PolicyUtils from '@libs/PolicyUtils';
import * as ReportUtils from '@libs/ReportUtils';
import playSound, {SOUNDS} from '@libs/Sound';
import * as TransactionUtils from '@libs/TransactionUtils';
Expand All @@ -36,13 +37,10 @@ import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage';
import type {Receipt} from '@src/types/onyx/Transaction';
import type {WithFullTransactionOrNotFoundProps} from './withFullTransactionOrNotFound';
import withFullTransactionOrNotFound from './withFullTransactionOrNotFound';
import withWritableReportOrNotFound from './withWritableReportOrNotFound';
import type {WithWritableReportOrNotFoundProps} from './withWritableReportOrNotFound';
import withWritableReportOrNotFound from './withWritableReportOrNotFound';

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

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

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

function IOURequestStepConfirmation({
allPolicies,
policy: policyReal,
policyDraft,
policyTags,
Expand Down Expand Up @@ -196,14 +193,9 @@ 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,
).length === 0
) {
// If the action is categorize and there's no policies other than personal one, we simply call goBack(), i.e: dismiss the whole flow together
// We don't need to subscribe to policy_ collection as we only need to check on the latest collection value
if (action === CONST.IOU.ACTION.CATEGORIZE && PolicyUtils.hasNoPolicyOtherThanPersonalType()) {
Navigation.goBack();
return;
}
Expand All @@ -215,7 +207,7 @@ function IOURequestStepConfirmation({
return;
}
IOUUtils.navigateToStartMoneyRequestStep(requestType, iouType, transactionID, reportID, action);
}, [transaction, iouType, requestType, transactionID, reportID, action, allPolicies]);
}, [transaction, iouType, requestType, transactionID, reportID, action]);

const navigateToAddReceipt = useCallback(() => {
Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_SCAN.getRoute(action, iouType, transactionID, reportID, Navigation.getActiveRouteWithoutParams()));
Expand Down Expand Up @@ -647,9 +639,6 @@ 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

0 comments on commit 5b8a940

Please sign in to comment.