Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 15 additions & 1 deletion src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,19 @@ function MoneyReportHeader({
}
} else if (isInvoiceReport) {
startAnimation();
payInvoice(type, chatReport, moneyRequestReport, introSelected, payAsBusiness, existingB2BInvoiceReport, methodID, paymentMethod, activePolicy);
payInvoice({
paymentMethodType: type,
chatReport,
invoiceReport: moneyRequestReport,
introSelected,
currentUserAccountIDParam: accountID,
currentUserEmailParam: email ?? '',
payAsBusiness,
existingB2BInvoiceReport,
methodID,
paymentMethod,
activePolicy,
});
} else {
startAnimation();
payMoneyRequest(type, chatReport, moneyRequestReport, introSelected, undefined, true, activePolicy);
Expand Down Expand Up @@ -534,6 +546,8 @@ function MoneyReportHeader({
currentSearchKey,
isOffline,
currentSearchResults?.search?.isLoading,
accountID,
email,
],
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ function MoneyRequestReportPreviewContent({
const {isOffline} = useNetwork();
const {shouldUseNarrowLayout} = useResponsiveLayout();
const currentUserDetails = useCurrentUserPersonalDetails();
const currentUserAccountID = currentUserDetails.accountID;
const currentUserEmail = currentUserDetails.email ?? '';
const expensifyIcons = useMemoizedLazyExpensifyIcons(['ArrowRight', 'BackArrow', 'Location', 'ReceiptPlus']);

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

const getCanIOUBePaid = useCallback(
(shouldShowOnlyPayElsewhere = false) => canIOUBePaidIOUActions(iouReport, chatReport, policy, transactions, shouldShowOnlyPayElsewhere),
Expand Down Expand Up @@ -248,13 +250,36 @@ function MoneyRequestReportPreviewContent({
} else if (chatReport && iouReport) {
startAnimation();
if (isInvoiceReportUtils(iouReport)) {
payInvoice(type, chatReport, iouReport, introSelected, payAsBusiness, existingB2BInvoiceReport, methodID, paymentMethod, activePolicy);
payInvoice({
paymentMethodType: type,
chatReport,
invoiceReport: iouReport,
introSelected,
currentUserAccountIDParam: currentUserAccountID,
currentUserEmailParam: currentUserEmail,
payAsBusiness,
existingB2BInvoiceReport,
methodID,
paymentMethod,
activePolicy,
});
} else {
payMoneyRequest(type, chatReport, iouReport, introSelected, undefined, true, activePolicy);
}
}
},
[isDelegateAccessRestricted, iouReport, chatReport, showDelegateNoAccessModal, startAnimation, introSelected, existingB2BInvoiceReport, activePolicy],
[
isDelegateAccessRestricted,
iouReport,
chatReport,
showDelegateNoAccessModal,
startAnimation,
introSelected,
existingB2BInvoiceReport,
activePolicy,
currentUserAccountID,
currentUserEmail,
],
);

const confirmApproval = () => {
Expand All @@ -269,7 +294,7 @@ function MoneyRequestReportPreviewContent({
setIsHoldMenuVisible(true);
} else {
startApprovedAnimation();
approveMoneyRequest(iouReport, activePolicy, currentUserDetails.accountID, currentUserDetails.email ?? '', hasViolations, isASAPSubmitBetaEnabled, iouReportNextStep, true);
approveMoneyRequest(iouReport, activePolicy, currentUserAccountID, currentUserEmail, hasViolations, isASAPSubmitBetaEnabled, iouReportNextStep, true);
}
};

Expand Down Expand Up @@ -493,15 +518,15 @@ function MoneyRequestReportPreviewContent({
const reportPreviewAction = useMemo(() => {
return getReportPreviewAction(
isIouReportArchived || isChatReportArchived,
currentUserDetails.accountID,
currentUserAccountID,
iouReport,
policy,
transactions,
invoiceReceiverPolicy,
isPaidAnimationRunning,
isApprovedAnimationRunning,
isSubmittingAnimationRunning,
{currentUserEmail: currentUserDetails.email ?? '', violations: transactionViolations},
{currentUserEmail, violations: transactionViolations},
);
}, [
isPaidAnimationRunning,
Expand All @@ -513,8 +538,8 @@ function MoneyRequestReportPreviewContent({
isIouReportArchived,
invoiceReceiverPolicy,
isChatReportArchived,
currentUserDetails.accountID,
currentUserDetails.email,
currentUserEmail,
currentUserAccountID,
transactionViolations,
]);

Expand All @@ -537,7 +562,7 @@ function MoneyRequestReportPreviewContent({
return;
}
startSubmittingAnimation();
submitReport(iouReport, policy, currentUserDetails.accountID, currentUserDetails.email ?? '', hasViolations, isASAPSubmitBetaEnabled, iouReportNextStep);
submitReport(iouReport, policy, currentUserAccountID, currentUserEmail, hasViolations, isASAPSubmitBetaEnabled, iouReportNextStep);
}}
isSubmittingAnimationRunning={isSubmittingAnimationRunning}
onAnimationFinish={stopAnimation}
Expand Down
49 changes: 39 additions & 10 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,20 @@
reimbursable?: boolean;
};

type PayInvoiceArgs = {
Comment thread
DylanDylann marked this conversation as resolved.
paymentMethodType: PaymentMethodType;
chatReport: OnyxTypes.Report;
invoiceReport: OnyxEntry<OnyxTypes.Report>;
introSelected: OnyxEntry<OnyxTypes.IntroSelected>;
currentUserAccountIDParam: number;
currentUserEmailParam: string;
payAsBusiness?: boolean;
existingB2BInvoiceReport?: OnyxEntry<OnyxTypes.Report>;
methodID?: number;
paymentMethod?: PaymentMethod;
activePolicy?: OnyxTypes.Policy;
};

type RejectMoneyRequestData = {
optimisticData: OnyxUpdate[];
successData: OnyxUpdate[];
Expand Down Expand Up @@ -743,7 +757,7 @@
};

let allPersonalDetails: OnyxTypes.PersonalDetailsList = {};
Onyx.connect({

Check warning on line 760 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
allPersonalDetails = value ?? {};
Expand Down Expand Up @@ -839,7 +853,7 @@
};

let allTransactions: NonNullable<OnyxCollection<OnyxTypes.Transaction>> = {};
Onyx.connect({

Check warning on line 856 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -853,7 +867,7 @@
});

let allTransactionDrafts: NonNullable<OnyxCollection<OnyxTypes.Transaction>> = {};
Onyx.connect({

Check warning on line 870 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_DRAFT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -862,7 +876,7 @@
});

let allTransactionViolations: NonNullable<OnyxCollection<OnyxTypes.TransactionViolations>> = {};
Onyx.connect({

Check warning on line 879 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -876,7 +890,7 @@
});

let allNextSteps: NonNullable<OnyxCollection<OnyxTypes.ReportNextStepDeprecated>> = {};
Onyx.connect({

Check warning on line 893 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.NEXT_STEP,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -888,14 +902,14 @@
// `allRecentlyUsedTags` was moved here temporarily from `src/libs/actions/Policy/Tag.ts` during the `Deprecate Onyx.connect` refactor.
// All uses of this variable should be replaced with `useOnyx`.
let allRecentlyUsedTags: OnyxCollection<RecentlyUsedTags> = {};
Onyx.connect({

Check warning on line 905 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS,
waitForCollectionCallback: true,
callback: (val) => (allRecentlyUsedTags = val),
});

let allReports: OnyxCollection<OnyxTypes.Report>;
Onyx.connect({

Check warning on line 912 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -904,7 +918,7 @@
});

let allReportNameValuePairs: OnyxCollection<OnyxTypes.ReportNameValuePairs>;
Onyx.connect({

Check warning on line 921 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -914,7 +928,7 @@

let userAccountID = -1;
let currentUserEmail = '';
Onyx.connect({

Check warning on line 931 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
currentUserEmail = value?.email ?? '';
Expand All @@ -923,7 +937,7 @@
});

let deprecatedCurrentUserPersonalDetails: OnyxEntry<OnyxTypes.PersonalDetails>;
Onyx.connect({

Check warning on line 940 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
deprecatedCurrentUserPersonalDetails = value?.[userAccountID] ?? undefined;
Expand Down Expand Up @@ -10326,6 +10340,9 @@
full,
payAsBusiness,
bankAccountID,
currentUserAccountIDParam,
currentUserEmailParam,
introSelectedParam,
paymentPolicyID,
lastUsedPaymentMethod,
existingB2BInvoiceReport,
Expand All @@ -10342,6 +10359,9 @@
lastUsedPaymentMethod?: OnyxTypes.LastPaymentMethodType;
existingB2BInvoiceReport?: OnyxEntry<OnyxTypes.Report>;
activePolicy?: OnyxEntry<OnyxTypes.Policy>;
currentUserAccountIDParam?: number;
currentUserEmailParam?: string;
introSelectedParam?: OnyxEntry<OnyxTypes.IntroSelected>;
}): PayMoneyRequestData {
const isInvoiceReport = isInvoiceReportReportUtils(iouReport);
let payerPolicyID = activePolicy?.id;
Expand All @@ -10363,6 +10383,10 @@
policyOwnerEmail: currentUserEmail,
makeMeAdmin: true,
policyID: payerPolicyID,
currentUserAccountIDParam,
currentUserEmailParam,
introSelectedParam,
activePolicyIDParam: activePolicy?.id,
});
const {adminsChatReportID, adminsCreatedReportActionID, expenseChatReportID, expenseCreatedReportActionID, customUnitRateID, customUnitID, ownerEmail, policyName} = params;

Expand Down Expand Up @@ -12090,17 +12114,19 @@
notifyNewAction(!full ? (Navigation.getTopmostReportId() ?? iouReport?.reportID) : iouReport?.reportID, userAccountID);
}

function payInvoice(
paymentMethodType: PaymentMethodType,
chatReport: OnyxTypes.Report,
invoiceReport: OnyxEntry<OnyxTypes.Report>,
introSelected: OnyxEntry<OnyxTypes.IntroSelected>,
function payInvoice({
paymentMethodType,
chatReport,
invoiceReport,
introSelected,
currentUserAccountIDParam,
currentUserEmailParam,
payAsBusiness = false,
existingB2BInvoiceReport?: OnyxEntry<OnyxTypes.Report>,
methodID?: number,
paymentMethod?: PaymentMethod,
activePolicy?: OnyxTypes.Policy,
) {
existingB2BInvoiceReport,
methodID,
paymentMethod,
activePolicy,
}: PayInvoiceArgs) {
const recipient = {accountID: invoiceReport?.ownerAccountID ?? CONST.DEFAULT_NUMBER_ID};
const {
optimisticData,
Expand Down Expand Up @@ -12128,6 +12154,9 @@
bankAccountID: methodID,
existingB2BInvoiceReport,
activePolicy,
currentUserAccountIDParam,
currentUserEmailParam,
introSelectedParam: introSelected,
});

const paymentSelected = paymentMethodType === CONST.IOU.PAYMENT_TYPE.VBBA ? CONST.IOU.PAYMENT_SELECTED.BBA : CONST.IOU.PAYMENT_SELECTED.PBA;
Expand Down
Loading