Skip to content

Commit 68d90e4

Browse files
authored
Merge pull request #77345 from DylanDylann/refactor-661
[Part 2]: Refactor buildPolicyData to pass Onyx value via param
2 parents 7d75039 + 1a9ea4c commit 68d90e4

3 files changed

Lines changed: 88 additions & 20 deletions

File tree

src/components/MoneyReportHeader.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,19 @@ function MoneyReportHeader({
502502
}
503503
} else if (isInvoiceReport) {
504504
startAnimation();
505-
payInvoice(type, chatReport, moneyRequestReport, introSelected, payAsBusiness, existingB2BInvoiceReport, methodID, paymentMethod, activePolicy);
505+
payInvoice({
506+
paymentMethodType: type,
507+
chatReport,
508+
invoiceReport: moneyRequestReport,
509+
introSelected,
510+
currentUserAccountIDParam: accountID,
511+
currentUserEmailParam: email ?? '',
512+
payAsBusiness,
513+
existingB2BInvoiceReport,
514+
methodID,
515+
paymentMethod,
516+
activePolicy,
517+
});
506518
} else {
507519
startAnimation();
508520
payMoneyRequest(type, chatReport, moneyRequestReport, introSelected, undefined, true, activePolicy);
@@ -534,6 +546,8 @@ function MoneyReportHeader({
534546
currentSearchKey,
535547
isOffline,
536548
currentSearchResults?.search?.isLoading,
549+
accountID,
550+
email,
537551
],
538552
);
539553

src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ function MoneyRequestReportPreviewContent({
143143
const {isOffline} = useNetwork();
144144
const {shouldUseNarrowLayout} = useResponsiveLayout();
145145
const currentUserDetails = useCurrentUserPersonalDetails();
146+
const currentUserAccountID = currentUserDetails.accountID;
147+
const currentUserEmail = currentUserDetails.email ?? '';
146148
const expensifyIcons = useMemoizedLazyExpensifyIcons(['ArrowRight', 'BackArrow', 'Location', 'ReceiptPlus']);
147149

148150
const {areAllRequestsBeingSmartScanned, hasNonReimbursableTransactions} = useMemo(
@@ -168,7 +170,7 @@ function MoneyRequestReportPreviewContent({
168170
const {isBetaEnabled} = usePermissions();
169171
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true});
170172
const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT);
171-
const hasViolations = hasViolationsReportUtils(iouReport?.reportID, transactionViolations, currentUserDetails.accountID, currentUserDetails.email ?? '');
173+
const hasViolations = hasViolationsReportUtils(iouReport?.reportID, transactionViolations, currentUserAccountID, currentUserEmail);
172174

173175
const getCanIOUBePaid = useCallback(
174176
(shouldShowOnlyPayElsewhere = false) => canIOUBePaidIOUActions(iouReport, chatReport, policy, transactions, shouldShowOnlyPayElsewhere),
@@ -248,13 +250,36 @@ function MoneyRequestReportPreviewContent({
248250
} else if (chatReport && iouReport) {
249251
startAnimation();
250252
if (isInvoiceReportUtils(iouReport)) {
251-
payInvoice(type, chatReport, iouReport, introSelected, payAsBusiness, existingB2BInvoiceReport, methodID, paymentMethod, activePolicy);
253+
payInvoice({
254+
paymentMethodType: type,
255+
chatReport,
256+
invoiceReport: iouReport,
257+
introSelected,
258+
currentUserAccountIDParam: currentUserAccountID,
259+
currentUserEmailParam: currentUserEmail,
260+
payAsBusiness,
261+
existingB2BInvoiceReport,
262+
methodID,
263+
paymentMethod,
264+
activePolicy,
265+
});
252266
} else {
253267
payMoneyRequest(type, chatReport, iouReport, introSelected, undefined, true, activePolicy);
254268
}
255269
}
256270
},
257-
[isDelegateAccessRestricted, iouReport, chatReport, showDelegateNoAccessModal, startAnimation, introSelected, existingB2BInvoiceReport, activePolicy],
271+
[
272+
isDelegateAccessRestricted,
273+
iouReport,
274+
chatReport,
275+
showDelegateNoAccessModal,
276+
startAnimation,
277+
introSelected,
278+
existingB2BInvoiceReport,
279+
activePolicy,
280+
currentUserAccountID,
281+
currentUserEmail,
282+
],
258283
);
259284

260285
const confirmApproval = () => {
@@ -269,7 +294,7 @@ function MoneyRequestReportPreviewContent({
269294
setIsHoldMenuVisible(true);
270295
} else {
271296
startApprovedAnimation();
272-
approveMoneyRequest(iouReport, activePolicy, currentUserDetails.accountID, currentUserDetails.email ?? '', hasViolations, isASAPSubmitBetaEnabled, iouReportNextStep, true);
297+
approveMoneyRequest(iouReport, activePolicy, currentUserAccountID, currentUserEmail, hasViolations, isASAPSubmitBetaEnabled, iouReportNextStep, true);
273298
}
274299
};
275300

@@ -493,15 +518,15 @@ function MoneyRequestReportPreviewContent({
493518
const reportPreviewAction = useMemo(() => {
494519
return getReportPreviewAction(
495520
isIouReportArchived || isChatReportArchived,
496-
currentUserDetails.accountID,
521+
currentUserAccountID,
497522
iouReport,
498523
policy,
499524
transactions,
500525
invoiceReceiverPolicy,
501526
isPaidAnimationRunning,
502527
isApprovedAnimationRunning,
503528
isSubmittingAnimationRunning,
504-
{currentUserEmail: currentUserDetails.email ?? '', violations: transactionViolations},
529+
{currentUserEmail, violations: transactionViolations},
505530
);
506531
}, [
507532
isPaidAnimationRunning,
@@ -513,8 +538,8 @@ function MoneyRequestReportPreviewContent({
513538
isIouReportArchived,
514539
invoiceReceiverPolicy,
515540
isChatReportArchived,
516-
currentUserDetails.accountID,
517-
currentUserDetails.email,
541+
currentUserEmail,
542+
currentUserAccountID,
518543
transactionViolations,
519544
]);
520545

@@ -537,7 +562,7 @@ function MoneyRequestReportPreviewContent({
537562
return;
538563
}
539564
startSubmittingAnimation();
540-
submitReport(iouReport, policy, currentUserDetails.accountID, currentUserDetails.email ?? '', hasViolations, isASAPSubmitBetaEnabled, iouReportNextStep);
565+
submitReport(iouReport, policy, currentUserAccountID, currentUserEmail, hasViolations, isASAPSubmitBetaEnabled, iouReportNextStep);
541566
}}
542567
isSubmittingAnimationRunning={isSubmittingAnimationRunning}
543568
onAnimationFinish={stopAnimation}

src/libs/actions/IOU.ts

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,20 @@ type MoneyRequestInformation = {
319319
reimbursable?: boolean;
320320
};
321321

322+
type PayInvoiceArgs = {
323+
paymentMethodType: PaymentMethodType;
324+
chatReport: OnyxTypes.Report;
325+
invoiceReport: OnyxEntry<OnyxTypes.Report>;
326+
introSelected: OnyxEntry<OnyxTypes.IntroSelected>;
327+
currentUserAccountIDParam: number;
328+
currentUserEmailParam: string;
329+
payAsBusiness?: boolean;
330+
existingB2BInvoiceReport?: OnyxEntry<OnyxTypes.Report>;
331+
methodID?: number;
332+
paymentMethod?: PaymentMethod;
333+
activePolicy?: OnyxTypes.Policy;
334+
};
335+
322336
type RejectMoneyRequestData = {
323337
optimisticData: OnyxUpdate[];
324338
successData: OnyxUpdate[];
@@ -10326,6 +10340,9 @@ function getPayMoneyRequestParams({
1032610340
full,
1032710341
payAsBusiness,
1032810342
bankAccountID,
10343+
currentUserAccountIDParam,
10344+
currentUserEmailParam,
10345+
introSelectedParam,
1032910346
paymentPolicyID,
1033010347
lastUsedPaymentMethod,
1033110348
existingB2BInvoiceReport,
@@ -10342,6 +10359,9 @@ function getPayMoneyRequestParams({
1034210359
lastUsedPaymentMethod?: OnyxTypes.LastPaymentMethodType;
1034310360
existingB2BInvoiceReport?: OnyxEntry<OnyxTypes.Report>;
1034410361
activePolicy?: OnyxEntry<OnyxTypes.Policy>;
10362+
currentUserAccountIDParam?: number;
10363+
currentUserEmailParam?: string;
10364+
introSelectedParam?: OnyxEntry<OnyxTypes.IntroSelected>;
1034510365
}): PayMoneyRequestData {
1034610366
const isInvoiceReport = isInvoiceReportReportUtils(iouReport);
1034710367
let payerPolicyID = activePolicy?.id;
@@ -10363,6 +10383,10 @@ function getPayMoneyRequestParams({
1036310383
policyOwnerEmail: currentUserEmail,
1036410384
makeMeAdmin: true,
1036510385
policyID: payerPolicyID,
10386+
currentUserAccountIDParam,
10387+
currentUserEmailParam,
10388+
introSelectedParam,
10389+
activePolicyIDParam: activePolicy?.id,
1036610390
});
1036710391
const {adminsChatReportID, adminsCreatedReportActionID, expenseChatReportID, expenseCreatedReportActionID, customUnitRateID, customUnitID, ownerEmail, policyName} = params;
1036810392

@@ -12096,17 +12120,19 @@ function payMoneyRequest(
1209612120
notifyNewAction(!full ? (Navigation.getTopmostReportId() ?? iouReport?.reportID) : iouReport?.reportID, userAccountID);
1209712121
}
1209812122

12099-
function payInvoice(
12100-
paymentMethodType: PaymentMethodType,
12101-
chatReport: OnyxTypes.Report,
12102-
invoiceReport: OnyxEntry<OnyxTypes.Report>,
12103-
introSelected: OnyxEntry<OnyxTypes.IntroSelected>,
12123+
function payInvoice({
12124+
paymentMethodType,
12125+
chatReport,
12126+
invoiceReport,
12127+
introSelected,
12128+
currentUserAccountIDParam,
12129+
currentUserEmailParam,
1210412130
payAsBusiness = false,
12105-
existingB2BInvoiceReport?: OnyxEntry<OnyxTypes.Report>,
12106-
methodID?: number,
12107-
paymentMethod?: PaymentMethod,
12108-
activePolicy?: OnyxTypes.Policy,
12109-
) {
12131+
existingB2BInvoiceReport,
12132+
methodID,
12133+
paymentMethod,
12134+
activePolicy,
12135+
}: PayInvoiceArgs) {
1211012136
const recipient = {accountID: invoiceReport?.ownerAccountID ?? CONST.DEFAULT_NUMBER_ID};
1211112137
const {
1211212138
optimisticData,
@@ -12134,6 +12160,9 @@ function payInvoice(
1213412160
bankAccountID: methodID,
1213512161
existingB2BInvoiceReport,
1213612162
activePolicy,
12163+
currentUserAccountIDParam,
12164+
currentUserEmailParam,
12165+
introSelectedParam: introSelected,
1213712166
});
1213812167

1213912168
const paymentSelected = paymentMethodType === CONST.IOU.PAYMENT_TYPE.VBBA ? CONST.IOU.PAYMENT_SELECTED.BBA : CONST.IOU.PAYMENT_SELECTED.PBA;

0 commit comments

Comments
 (0)