Skip to content

Commit 0e531e7

Browse files
committed
fix(react-compiler): tag workspace-policy PAY sub-items with policy data
1 parent e92c41b commit 0e531e7

3 files changed

Lines changed: 24 additions & 19 deletions

File tree

src/components/MoneyReportHeaderActions/MoneyReportHeaderSecondaryActions.tsx

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
3636
import getPlatform from '@libs/getPlatform';
3737
import {getTotalAmountForIOUReportPreviewButton} from '@libs/MoneyRequestReportUtils';
3838
import Navigation from '@libs/Navigation/Navigation';
39-
import type {KYCFlowEvent, TriggerKYCFlow} from '@libs/PaymentUtils';
39+
import type {KYCFlowEvent, TriggerKYCFlow, WorkspacePolicyPaymentOption} from '@libs/PaymentUtils';
4040
import {selectPaymentType} from '@libs/PaymentUtils';
4141
import {sortPoliciesByName} from '@libs/PolicyUtils';
4242
import {getFilteredReportActionsForReportView, hasRequestFromCurrentAccount} from '@libs/ReportActionsUtils';
@@ -55,7 +55,6 @@ import {canApproveIOU, canIOUBePaid as canIOUBePaidAction} from '@userActions/IO
5555
import CONST from '@src/CONST';
5656
import ONYXKEYS from '@src/ONYXKEYS';
5757
import type {Route} from '@src/ROUTES';
58-
import type * as OnyxTypes from '@src/types/onyx';
5958
import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage';
6059

6160
type MoneyReportHeaderSecondaryActionsProps = {
@@ -232,25 +231,26 @@ function MoneyReportHeaderSecondaryActions({reportID, primaryAction, isReportInS
232231

233232
const expensifyIcons = useMemoizedLazyExpensifyIcons(['Info', 'Cash', 'ArrowRight', 'Building']);
234233

235-
const buildPaymentSubMenuItems = (onWorkspaceSelected: (workspacePolicy: OnyxTypes.Policy) => void): PopoverMenuItem[] => {
236-
if (!workspacePolicyOptions.length) {
237-
return Object.values(paymentButtonOptions);
238-
}
239-
const result: PopoverMenuItem[] = [];
234+
// Build PAY action sub-items. Workspace-policy entries carry the policy as data and have no onSelected;
235+
// MoneyReportHeaderKYCDropdown picks them up via onSubItemSelected where triggerKYCFlow is in scope.
236+
const paymentSubMenuItems: PopoverMenuItem[] = [];
237+
if (!workspacePolicyOptions.length) {
238+
paymentSubMenuItems.push(...Object.values(paymentButtonOptions));
239+
} else {
240240
for (const opt of Object.values(paymentButtonOptions)) {
241-
result.push(opt);
241+
paymentSubMenuItems.push(opt);
242242
if (opt.value === CONST.IOU.PAYMENT_TYPE.EXPENSIFY) {
243243
for (const wp of workspacePolicyOptions) {
244-
result.push({
244+
const workspacePolicyItem: WorkspacePolicyPaymentOption = {
245245
text: translate('iou.payWithPolicy', truncate(wp.name, {length: CONST.ADDITIONAL_ALLOWED_CHARACTERS}), ''),
246246
icon: expensifyIcons.Building,
247-
onSelected: () => onWorkspaceSelected(wp),
248-
});
247+
workspacePolicy: wp,
248+
};
249+
paymentSubMenuItems.push(workspacePolicyItem);
249250
}
250251
}
251252
}
252-
return result;
253-
};
253+
}
254254

255255
// Domain hooks
256256
const lifecycleActions = useLifecycleActions({
@@ -337,10 +337,7 @@ function MoneyReportHeaderSecondaryActions({reportID, primaryAction, isReportInS
337337
value: CONST.REPORT.SECONDARY_ACTIONS.PAY,
338338
backButtonText: translate('iou.settlePayment', totalAmount),
339339
sentryLabel: CONST.SENTRY_LABEL.MORE_MENU.PAY,
340-
// eslint-disable-next-line react-hooks/refs -- ref is only accessed inside the callback (event handler), not during render
341-
subMenuItems: buildPaymentSubMenuItems((wp) => {
342-
kycWallRef.current?.continueAction?.({policy: wp});
343-
}),
340+
subMenuItems: paymentSubMenuItems,
344341
},
345342
};
346343

src/components/MoneyReportHeaderKYCDropdown.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import useLocalize from '@hooks/useLocalize';
44
import useNetwork from '@hooks/useNetwork';
55
import useResponsiveLayout from '@hooks/useResponsiveLayout';
66
import useThemeStyles from '@hooks/useThemeStyles';
7-
import {isSecondaryActionAPaymentOption} from '@libs/PaymentUtils';
7+
import {isSecondaryActionAPaymentOption, isSecondaryActionAWorkspacePolicyOption} from '@libs/PaymentUtils';
88
import type {KYCFlowEvent, TriggerKYCFlow} from '@libs/PaymentUtils';
99
import shouldPopoverUseScrollView from '@libs/shouldPopoverUseScrollView';
1010
import CONST from '@src/CONST';
@@ -76,6 +76,10 @@ function MoneyReportHeaderKYCDropdown({
7676
success={shouldShowSuccessStyle ?? false}
7777
onPress={() => {}}
7878
onSubItemSelected={(item, index, event) => {
79+
if (isSecondaryActionAWorkspacePolicyOption(item)) {
80+
triggerKYCFlow({policy: item.workspacePolicy});
81+
return;
82+
}
7983
if (!isSecondaryActionAPaymentOption(item)) {
8084
return;
8185
}

src/libs/PaymentUtils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ type ApproveActionType = Extract<ValueOf<typeof CONST.IOU.REPORT_ACTION_TYPE>, '
284284
type PaymentOption = PopoverMenuItem & DropdownOption<ValueOf<typeof CONST.IOU.PAYMENT_TYPE>>;
285285
type PaymentOrApproveOption = Merge<PaymentOption, {value?: PaymentOption['value'] | ApproveActionType}>;
286286
type SecondaryActionOption = DropdownOption<ValueOf<typeof CONST.REPORT.SECONDARY_ACTIONS>>;
287+
type WorkspacePolicyPaymentOption = PopoverMenuItem & {workspacePolicy: Policy};
287288

288289
const isSecondaryActionAPaymentOption = (item: PopoverMenuItem): item is PaymentOption => {
289290
if (!('value' in item)) {
@@ -294,6 +295,8 @@ const isSecondaryActionAPaymentOption = (item: PopoverMenuItem): item is Payment
294295
return isPaymentInArray.length > 0;
295296
};
296297

298+
const isSecondaryActionAWorkspacePolicyOption = (item: PopoverMenuItem): item is WorkspacePolicyPaymentOption => 'workspacePolicy' in item && !!item.workspacePolicy;
299+
297300
/**
298301
* Get the appropriate payment type, policy from context (policy related to payment type), policy from payment method, and whether a payment method should be selected
299302
* based on the provided payment method, active admin policies, and valid business bank account options.
@@ -362,7 +365,8 @@ export {
362365
handleUnvalidatedAccount,
363366
selectPaymentType,
364367
isSecondaryActionAPaymentOption,
368+
isSecondaryActionAWorkspacePolicyOption,
365369
getActivePaymentType,
366370
getBankAccountLastFourDigits,
367371
};
368-
export type {KYCFlowEvent, TriggerKYCFlow, PaymentOrApproveOption, PaymentOption, SelectPaymentTypeParams, BusinessBankAccountOption};
372+
export type {KYCFlowEvent, TriggerKYCFlow, PaymentOrApproveOption, PaymentOption, SelectPaymentTypeParams, BusinessBankAccountOption, WorkspacePolicyPaymentOption};

0 commit comments

Comments
 (0)