Skip to content

Commit a233517

Browse files
committed
fix(react-compiler): expose triggerKYCFlow via onWorkspacePolicySelect
1 parent 0e531e7 commit a233517

3 files changed

Lines changed: 38 additions & 46 deletions

File tree

Mobile-Expensify

src/components/MoneyReportHeaderActions/MoneyReportHeaderSelectionDropdown.tsx

Lines changed: 23 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {useRoute} from '@react-navigation/native';
22
import {delegateEmailSelector, isUserValidatedSelector} from '@selectors/Account';
33
import {hasSeenTourSelector} from '@selectors/Onboarding';
44
import truncate from 'lodash/truncate';
5-
import React, {useContext, useEffect, useRef} from 'react';
5+
import React, {useContext} from 'react';
66
import type {StyleProp, ViewStyle} from 'react-native';
77
import type {ValueOf} from 'type-fest';
88
import ButtonWithDropdownMenu from '@components/ButtonWithDropdownMenu';
@@ -39,7 +39,7 @@ import useTransactionThreadReport from '@hooks/useTransactionThreadReport';
3939
import {search} from '@libs/actions/Search';
4040
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
4141
import {getTotalAmountForIOUReportPreviewButton} from '@libs/MoneyRequestReportUtils';
42-
import type {KYCFlowEvent, TriggerKYCFlow} from '@libs/PaymentUtils';
42+
import type {KYCFlowEvent, TriggerKYCFlow, WorkspacePolicyPaymentOption} from '@libs/PaymentUtils';
4343
import {handleUnvalidatedAccount, selectPaymentType} from '@libs/PaymentUtils';
4444
import {sortPoliciesByName} from '@libs/PolicyUtils';
4545
import {hasRequestFromCurrentAccount} from '@libs/ReportActionsUtils';
@@ -53,7 +53,6 @@ import CONST from '@src/CONST';
5353
import ONYXKEYS from '@src/ONYXKEYS';
5454
import ROUTES from '@src/ROUTES';
5555
import type {Route} from '@src/ROUTES';
56-
import type * as OnyxTypes from '@src/types/onyx';
5756
import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage';
5857

5958
const PAYMENT_ICONS = ['Send', 'ThumbsUp', 'Cash', 'ArrowRight', 'Building'] as const;
@@ -136,15 +135,6 @@ function MoneyReportHeaderSelectionDropdown({reportID, primaryAction, isReportIn
136135

137136
const {showConfirmModal} = useConfirmModal();
138137

139-
const isSelectionModePaymentRef = useRef(false);
140-
141-
useEffect(() => {
142-
if (selectedTransactionIDs.length !== 0) {
143-
return;
144-
}
145-
isSelectionModePaymentRef.current = false;
146-
}, [selectedTransactionIDs.length]);
147-
148138
const expensifyIcons = useMemoizedLazyExpensifyIcons(PAYMENT_ICONS);
149139

150140
const {beginExportWithTemplate, showOfflineModal, showDownloadErrorModal} = useExportActions({
@@ -229,7 +219,6 @@ function MoneyReportHeaderSelectionDropdown({reportID, primaryAction, isReportIn
229219
if (!type || !chatReport) {
230220
return;
231221
}
232-
isSelectionModePaymentRef.current = true;
233222

234223
if (isDelegateAccessRestricted) {
235224
showDelegateNoAccessModal();
@@ -318,25 +307,26 @@ function MoneyReportHeaderSelectionDropdown({reportID, primaryAction, isReportIn
318307
? sortPoliciesByName(activeAdminPolicies, localeCompare)
319308
: [];
320309

321-
const buildPaymentSubMenuItems = (onWorkspaceSelected: (workspacePolicy: OnyxTypes.Policy) => void): PopoverMenuItem[] => {
322-
if (!workspacePolicyOptions.length) {
323-
return Object.values(paymentButtonOptions);
324-
}
325-
const result: PopoverMenuItem[] = [];
310+
// Workspace-policy entries carry the policy as data with no onSelected.
311+
// MoneyReportHeaderKYCDropdown picks them up via onSubItemSelected where triggerKYCFlow is in scope
312+
const paymentSubMenuItems: PopoverMenuItem[] = [];
313+
if (!workspacePolicyOptions.length) {
314+
paymentSubMenuItems.push(...Object.values(paymentButtonOptions));
315+
} else {
326316
for (const opt of Object.values(paymentButtonOptions)) {
327-
result.push(opt);
317+
paymentSubMenuItems.push(opt);
328318
if (opt.value === CONST.IOU.PAYMENT_TYPE.EXPENSIFY) {
329319
for (const wp of workspacePolicyOptions) {
330-
result.push({
320+
const workspacePolicyItem: WorkspacePolicyPaymentOption = {
331321
text: translate('iou.payWithPolicy', truncate(wp.name, {length: CONST.ADDITIONAL_ALLOWED_CHARACTERS}), ''),
332322
icon: expensifyIcons.Building,
333-
onSelected: () => onWorkspaceSelected(wp),
334-
});
323+
workspacePolicy: wp,
324+
};
325+
paymentSubMenuItems.push(workspacePolicyItem);
335326
}
336327
}
337328
}
338-
return result;
339-
};
329+
}
340330

341331
const showDeleteModal = () => {
342332
showConfirmModal({
@@ -385,10 +375,7 @@ function MoneyReportHeaderSelectionDropdown({reportID, primaryAction, isReportIn
385375
text: translate('iou.approve'),
386376
icon: expensifyIcons.ThumbsUp,
387377
value: CONST.REPORT.PRIMARY_ACTIONS.APPROVE,
388-
onSelected: () => {
389-
isSelectionModePaymentRef.current = true;
390-
confirmApproval(true);
391-
},
378+
onSelected: () => confirmApproval(true),
392379
},
393380
]
394381
: []),
@@ -400,16 +387,7 @@ function MoneyReportHeaderSelectionDropdown({reportID, primaryAction, isReportIn
400387
value: CONST.REPORT.PRIMARY_ACTIONS.PAY as string,
401388
rightIcon: expensifyIcons.ArrowRight,
402389
backButtonText: translate('iou.settlePayment', totalAmount),
403-
subMenuItems: buildPaymentSubMenuItems((wp) => {
404-
isSelectionModePaymentRef.current = true;
405-
if (checkForNecessaryAction()) {
406-
return;
407-
}
408-
kycWallRef.current?.continueAction?.({policy: wp});
409-
}),
410-
onSelected: () => {
411-
isSelectionModePaymentRef.current = true;
412-
},
390+
subMenuItems: paymentSubMenuItems,
413391
},
414392
]
415393
: []),
@@ -446,7 +424,6 @@ function MoneyReportHeaderSelectionDropdown({reportID, primaryAction, isReportIn
446424
const hasPayInSelectionMode = allExpensesSelected && hasPayAction && hasActualPaymentOptions;
447425

448426
const onSelectionModePaymentSelect = (event: KYCFlowEvent, iouPaymentType: PaymentMethodType, triggerKYCFlow: TriggerKYCFlow) => {
449-
isSelectionModePaymentRef.current = true;
450427
if (checkForNecessaryAction(iouPaymentType)) {
451428
return;
452429
}
@@ -473,10 +450,7 @@ function MoneyReportHeaderSelectionDropdown({reportID, primaryAction, isReportIn
473450
});
474451
};
475452

476-
const selectionModeKYCSuccess = (type?: PaymentMethodType) => {
477-
isSelectionModePaymentRef.current = true;
478-
confirmPayment({paymentType: type});
479-
};
453+
const selectionModeKYCSuccess = (type?: PaymentMethodType) => confirmPayment({paymentType: type});
480454

481455
if (!selectedTransactionsOptions.length || transactionThreadReportID) {
482456
return null;
@@ -501,6 +475,12 @@ function MoneyReportHeaderSelectionDropdown({reportID, primaryAction, isReportIn
501475
chatReportID={chatReport?.reportID}
502476
iouReport={moneyRequestReport}
503477
onPaymentSelect={onSelectionModePaymentSelect}
478+
onWorkspacePolicySelect={(selectedPolicy, triggerKYCFlow) => {
479+
if (checkForNecessaryAction()) {
480+
return;
481+
}
482+
triggerKYCFlow({policy: selectedPolicy});
483+
}}
504484
onSuccessfulKYC={selectionModeKYCSuccess}
505485
primaryAction={primaryAction}
506486
applicableSecondaryActions={selectedTransactionsOptions}

src/components/MoneyReportHeaderKYCDropdown.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type {KYCFlowEvent, TriggerKYCFlow} from '@libs/PaymentUtils';
99
import shouldPopoverUseScrollView from '@libs/shouldPopoverUseScrollView';
1010
import CONST from '@src/CONST';
1111
import ROUTES from '@src/ROUTES';
12+
import type {Policy} from '@src/types/onyx';
1213
import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage';
1314
import ButtonWithDropdownMenu from './ButtonWithDropdownMenu';
1415
import type {ButtonWithDropdownMenuRef, DropdownOption} from './ButtonWithDropdownMenu/types';
@@ -22,6 +23,12 @@ type MoneyReportHeaderKYCDropdownProps = Omit<KYCWallProps, 'children' | 'enable
2223

2324
onPaymentSelect: (event: KYCFlowEvent, iouPaymentType: PaymentMethodType, triggerKYCFlow: TriggerKYCFlow) => void;
2425

26+
/**
27+
* Called when a workspace-policy sub-item is picked. The parent owns the full flow (guards, telemetry,
28+
* then invoking `triggerKYCFlow({policy})` when ready). If omitted, defaults to `triggerKYCFlow({policy})`.
29+
*/
30+
onWorkspacePolicySelect?: (policy: Policy, triggerKYCFlow: TriggerKYCFlow) => void;
31+
2532
customText?: string;
2633

2734
shouldShowSuccessStyle?: boolean;
@@ -40,6 +47,7 @@ function MoneyReportHeaderKYCDropdown({
4047
applicableSecondaryActions,
4148
iouReport,
4249
onPaymentSelect,
50+
onWorkspacePolicySelect,
4351
customText,
4452
shouldShowSuccessStyle,
4553
dropdownMenuRef,
@@ -75,9 +83,13 @@ function MoneyReportHeaderKYCDropdown({
7583
ref={dropdownMenuRef}
7684
success={shouldShowSuccessStyle ?? false}
7785
onPress={() => {}}
78-
onSubItemSelected={(item, index, event) => {
86+
onSubItemSelected={(item, _index, event) => {
7987
if (isSecondaryActionAWorkspacePolicyOption(item)) {
80-
triggerKYCFlow({policy: item.workspacePolicy});
88+
if (onWorkspacePolicySelect) {
89+
onWorkspacePolicySelect(item.workspacePolicy, triggerKYCFlow);
90+
} else {
91+
triggerKYCFlow({policy: item.workspacePolicy});
92+
}
8193
return;
8294
}
8395
if (!isSecondaryActionAPaymentOption(item)) {

0 commit comments

Comments
 (0)