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
14 changes: 13 additions & 1 deletion src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,19 @@
setIsHoldMenuVisible(true);
} else {
startApprovedAnimation();
approveMoneyRequest(moneyRequestReport, policy, accountID, email ?? '', hasViolations, isASAPSubmitBetaEnabled, nextStep, betas, userBillingGraceEndPeriods, true);
approveMoneyRequest({
expenseReport: moneyRequestReport,
policy,
currentUserAccountIDParam: accountID,
currentUserEmailParam: email ?? '',
hasViolations,
isASAPSubmitBetaEnabled,
expenseReportCurrentNextStepDeprecated: nextStep,
betas,
userBillingGraceEndPeriods,
amountOwed,
full: true,
});
}
};

Expand All @@ -741,7 +753,7 @@
}, [iouTransactionID, requestParentReportAction, transactionThreadReport?.reportID, transactionViolations]);

const [allPolicyTags] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS);
const targetPolicyTags = defaultExpensePolicy ? (allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${defaultExpensePolicy.id}`] ?? {}) : {};

Check warning on line 756 in src/components/MoneyReportHeader.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

The 'targetPolicyTags' conditional could make the dependencies of useCallback Hook (at line 795) change on every render. Move it inside the useCallback callback. Alternatively, wrap the initialization of 'targetPolicyTags' in its own useMemo() Hook

Check warning on line 756 in src/components/MoneyReportHeader.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

The 'targetPolicyTags' conditional could make the dependencies of useCallback Hook (at line 795) change on every render. Move it inside the useCallback callback. Alternatively, wrap the initialization of 'targetPolicyTags' in its own useMemo() Hook

const duplicateExpenseTransaction = useCallback(
(transactionList: OnyxTypes.Transaction[]) => {
Expand Down
16 changes: 9 additions & 7 deletions src/components/ProcessMoneyReportHoldMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function ProcessMoneyReportHoldMenu({
const {isSmallScreenWidth} = useResponsiveLayout();
const [userBillingGraceEndPeriods] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END);
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID);
const [amountOwed] = useOnyx(ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED);
const activePolicy = usePolicy(activePolicyID);
const policy = usePolicy(moneyRequestReport?.policyID);
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
Expand All @@ -98,18 +99,19 @@ function ProcessMoneyReportHoldMenu({
if (startAnimation) {
startAnimation();
}
approveMoneyRequest(
moneyRequestReport,
activePolicy,
currentUserDetails.accountID,
currentUserDetails.email ?? '',
approveMoneyRequest({
expenseReport: moneyRequestReport,
policy: activePolicy,
currentUserAccountIDParam: currentUserDetails.accountID,
currentUserEmailParam: currentUserDetails.email ?? '',
hasViolations,
isASAPSubmitBetaEnabled,
moneyRequestReportNextStep,
expenseReportCurrentNextStepDeprecated: moneyRequestReportNextStep,
betas,
userBillingGraceEndPeriods,
amountOwed,
full,
);
});
} else if (chatReport && paymentType) {
if (startAnimation) {
startAnimation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,18 +351,19 @@ function MoneyRequestReportPreviewContent({
setIsHoldMenuVisible(true);
} else {
startApprovedAnimation();
approveMoneyRequest(
iouReport,
activePolicy,
currentUserAccountID,
currentUserEmail,
approveMoneyRequest({
expenseReport: iouReport,
policy: activePolicy,
currentUserAccountIDParam: currentUserAccountID,
currentUserEmailParam: currentUserEmail,
hasViolations,
isASAPSubmitBetaEnabled,
iouReportNextStep,
expenseReportCurrentNextStepDeprecated: iouReportNextStep,
betas,
userBillingGraceEndPeriods,
true,
);
amountOwed,
full: true,
});
}
};

Expand Down
15 changes: 14 additions & 1 deletion src/components/SettlementButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ function SettlementButton({
const [conciergeReportID = ''] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
const [iouReportNextStep] = useOnyx(`${ONYXKEYS.COLLECTION.NEXT_STEP}${iouReport?.reportID}`);
const [isUserValidated] = useOnyx(ONYXKEYS.ACCOUNT, {selector: isUserValidatedSelector});
const [amountOwed] = useOnyx(ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED);
const policyEmployeeAccountIDs = getPolicyEmployeeAccountIDs(policy, accountID);
const reportBelongsToWorkspace = policyID ? doesReportBelongToWorkspace(chatReport, policyEmployeeAccountIDs, policyID, conciergeReportID) : false;
const policyIDKey = reportBelongsToWorkspace ? policyID : (iouReport?.policyID ?? CONST.POLICY.ID_FAKE);
Expand Down Expand Up @@ -426,7 +427,19 @@ function SettlementButton({
if (confirmApproval) {
confirmApproval();
} else {
approveMoneyRequest(iouReport, policy, accountID, email ?? '', hasViolations, isASAPSubmitBetaEnabled, iouReportNextStep, betas, userBillingGraceEndPeriods, false);
approveMoneyRequest({
expenseReport: iouReport,
policy,
currentUserAccountIDParam: accountID,
currentUserEmailParam: email ?? '',
hasViolations,
isASAPSubmitBetaEnabled,
expenseReportCurrentNextStepDeprecated: iouReportNextStep,
betas,
userBillingGraceEndPeriods,
amountOwed,
full: false,
});
}
return;
}
Expand Down
14 changes: 13 additions & 1 deletion src/libs/PaymentUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,19 @@ const selectPaymentType = (params: SelectPaymentTypeParams) => {
if (confirmApproval) {
confirmApproval();
} else {
approveMoneyRequest(iouReport, policy, currentAccountID, currentEmail, hasViolations, isASAPSubmitBetaEnabled, iouReportNextStep, betas, userBillingGraceEndPeriods, true);
approveMoneyRequest({
expenseReport: iouReport,
policy,
currentUserAccountIDParam: currentAccountID,
currentUserEmailParam: currentEmail,
hasViolations,
isASAPSubmitBetaEnabled,
expenseReportCurrentNextStepDeprecated: iouReportNextStep,
betas,
userBillingGraceEndPeriods,
amountOwed,
full: true,
});
}
return;
}
Expand Down
41 changes: 28 additions & 13 deletions src/libs/actions/IOU/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@
};

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

Check warning on line 818 in src/libs/actions/IOU/index.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 @@ -913,7 +913,7 @@
};

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

Check warning on line 916 in src/libs/actions/IOU/index.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 @@ -927,7 +927,7 @@
});

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

Check warning on line 930 in src/libs/actions/IOU/index.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 @@ -936,7 +936,7 @@
});

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

Check warning on line 939 in src/libs/actions/IOU/index.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 @@ -950,7 +950,7 @@
});

let allPolicyTags: OnyxCollection<OnyxTypes.PolicyTagLists> = {};
Onyx.connect({

Check warning on line 953 in src/libs/actions/IOU/index.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_TAGS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -963,7 +963,7 @@
});

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

Check warning on line 966 in src/libs/actions/IOU/index.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 @@ -972,7 +972,7 @@
});

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

Check warning on line 975 in src/libs/actions/IOU/index.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 @@ -982,7 +982,7 @@

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

Check warning on line 985 in src/libs/actions/IOU/index.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 @@ -991,7 +991,7 @@
});

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

Check warning on line 994 in src/libs/actions/IOU/index.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 @@ -10602,23 +10602,38 @@
return createdAction?.created ?? expenseReport.created;
}

function approveMoneyRequest(
expenseReport: OnyxEntry<OnyxTypes.Report>,
policy: OnyxEntry<OnyxTypes.Policy>,
currentUserAccountIDParam: number,
currentUserEmailParam: string,
hasViolations: boolean,
isASAPSubmitBetaEnabled: boolean,
expenseReportCurrentNextStepDeprecated: OnyxEntry<OnyxTypes.ReportNextStepDeprecated>,
betas: OnyxEntry<OnyxTypes.Beta[]>,
userBillingGraceEndPeriods: OnyxCollection<OnyxTypes.BillingGraceEndPeriod>,
full?: boolean,
) {
type ApproveMoneyRequestParam = {
expenseReport: OnyxEntry<OnyxTypes.Report>;
policy: OnyxEntry<OnyxTypes.Policy>;
currentUserAccountIDParam: number;
currentUserEmailParam: string;
hasViolations: boolean;
isASAPSubmitBetaEnabled: boolean;
expenseReportCurrentNextStepDeprecated: OnyxEntry<OnyxTypes.ReportNextStepDeprecated>;
betas: OnyxEntry<OnyxTypes.Beta[]>;
userBillingGraceEndPeriods: OnyxCollection<OnyxTypes.BillingGraceEndPeriod>;
amountOwed: OnyxEntry<number>;
full?: boolean;
};

function approveMoneyRequest({
expenseReport,
policy,
currentUserAccountIDParam,
currentUserEmailParam,
hasViolations,
isASAPSubmitBetaEnabled,
expenseReportCurrentNextStepDeprecated,
betas,
userBillingGraceEndPeriods,
amountOwed,
full,
}: ApproveMoneyRequestParam) {
if (!expenseReport) {
return;
}

if (expenseReport.policyID && shouldRestrictUserBillableActions(expenseReport.policyID, userBillingGraceEndPeriods)) {
if (expenseReport.policyID && shouldRestrictUserBillableActions(expenseReport.policyID, userBillingGraceEndPeriods, amountOwed)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(expenseReport.policyID));
return;
}
Expand Down
105 changes: 97 additions & 8 deletions tests/actions/IOUTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13864,7 +13864,18 @@ describe('actions/IOU', () => {
});

// Admin approves the report
approveMoneyRequest(expenseReport, policy, adminAccountID, adminEmail, false, false, undefined, [CONST.BETAS.ALL], undefined);
approveMoneyRequest({
expenseReport,
policy,
currentUserAccountIDParam: adminAccountID,
currentUserEmailParam: adminEmail,
hasViolations: false,
isASAPSubmitBetaEnabled: false,
expenseReportCurrentNextStepDeprecated: undefined,
betas: [CONST.BETAS.ALL],
userBillingGraceEndPeriods: undefined,
amountOwed: 0,
});
await waitForBatchedUpdates();

// Should be approved since admin took control and is the last approver
Expand Down Expand Up @@ -13902,7 +13913,18 @@ describe('actions/IOU', () => {
});

// Manager approves the report
approveMoneyRequest(expenseReport, policy, managerAccountID, managerEmail, false, false, undefined, [CONST.BETAS.ALL], undefined);
approveMoneyRequest({
expenseReport,
policy,
currentUserAccountIDParam: managerAccountID,
currentUserEmailParam: managerEmail,
hasViolations: false,
isASAPSubmitBetaEnabled: false,
expenseReportCurrentNextStepDeprecated: undefined,
betas: [CONST.BETAS.ALL],
userBillingGraceEndPeriods: undefined,
amountOwed: 0,
});
await waitForBatchedUpdates();

// Should be submitted to senior manager (normal flow) since take control was invalidated
Expand Down Expand Up @@ -13936,7 +13958,18 @@ describe('actions/IOU', () => {
});

// Admin approves the report
approveMoneyRequest(expenseReport, policy, adminAccountID, adminEmail, false, false, undefined, [CONST.BETAS.ALL], undefined);
approveMoneyRequest({
expenseReport,
policy,
currentUserAccountIDParam: adminAccountID,
currentUserEmailParam: adminEmail,
hasViolations: false,
isASAPSubmitBetaEnabled: false,
expenseReportCurrentNextStepDeprecated: undefined,
betas: [CONST.BETAS.ALL],
userBillingGraceEndPeriods: undefined,
amountOwed: 0,
});
await waitForBatchedUpdates();

// Get the optimistic next step
Expand Down Expand Up @@ -14046,7 +14079,18 @@ describe('actions/IOU', () => {
});

// Manager approves the report (no take control actions)
approveMoneyRequest(expenseReport, policy, managerAccountID, managerEmail, false, false, undefined, [CONST.BETAS.ALL], undefined);
approveMoneyRequest({
expenseReport,
policy,
currentUserAccountIDParam: managerAccountID,
currentUserEmailParam: managerEmail,
hasViolations: false,
isASAPSubmitBetaEnabled: false,
expenseReportCurrentNextStepDeprecated: undefined,
betas: [CONST.BETAS.ALL],
userBillingGraceEndPeriods: undefined,
amountOwed: 0,
});
await waitForBatchedUpdates();

// Should be submitted to admin (next in approval chain) since manager is not the final approver
Expand All @@ -14063,7 +14107,18 @@ describe('actions/IOU', () => {
accountID: managerAccountID,
});

approveMoneyRequest(expenseReport, policy, managerAccountID, managerEmail, false, false, undefined, [CONST.BETAS.ALL], undefined);
approveMoneyRequest({
expenseReport,
policy,
currentUserAccountIDParam: managerAccountID,
currentUserEmailParam: managerEmail,
hasViolations: false,
isASAPSubmitBetaEnabled: false,
expenseReportCurrentNextStepDeprecated: undefined,
betas: [CONST.BETAS.ALL],
userBillingGraceEndPeriods: undefined,
amountOwed: 0,
});
await waitForBatchedUpdates();

// Should be submitted to admin
Expand All @@ -14078,7 +14133,18 @@ describe('actions/IOU', () => {
accountID: adminAccountID,
});

approveMoneyRequest(updatedReport, policy, adminAccountID, adminEmail, false, false, undefined, [CONST.BETAS.ALL], undefined);
approveMoneyRequest({
expenseReport: updatedReport,
policy,
currentUserAccountIDParam: adminAccountID,
currentUserEmailParam: adminEmail,
hasViolations: false,
isASAPSubmitBetaEnabled: false,
expenseReportCurrentNextStepDeprecated: undefined,
betas: [CONST.BETAS.ALL],
userBillingGraceEndPeriods: undefined,
amountOwed: 0,
});
await waitForBatchedUpdates();

// Should be fully approved
Expand Down Expand Up @@ -14123,7 +14189,18 @@ describe('actions/IOU', () => {
});

// Manager approves the report
approveMoneyRequest(singleApproverReport, singleApproverPolicy, managerAccountID, managerEmail, false, false, undefined, [CONST.BETAS.ALL], undefined);
approveMoneyRequest({
expenseReport: singleApproverReport,
policy: singleApproverPolicy,
currentUserAccountIDParam: managerAccountID,
currentUserEmailParam: managerEmail,
hasViolations: false,
isASAPSubmitBetaEnabled: false,
expenseReportCurrentNextStepDeprecated: undefined,
betas: [CONST.BETAS.ALL],
userBillingGraceEndPeriods: undefined,
amountOwed: 0,
});
await waitForBatchedUpdates();

// Should be fully approved since manager is the final approver in the chain
Expand Down Expand Up @@ -14224,7 +14301,19 @@ describe('actions/IOU', () => {
accountID: adminAccountID,
});

const newExpenseReportID = approveMoneyRequest(expenseReport, policy, adminAccountID, adminEmail, false, false, undefined, [CONST.BETAS.ALL], undefined, false);
const newExpenseReportID = approveMoneyRequest({
expenseReport,
policy,
currentUserAccountIDParam: adminAccountID,
currentUserEmailParam: adminEmail,
hasViolations: false,
isASAPSubmitBetaEnabled: false,
expenseReportCurrentNextStepDeprecated: undefined,
betas: [CONST.BETAS.ALL],
userBillingGraceEndPeriods: undefined,
amountOwed: 0,
full: false,
});
await waitForBatchedUpdates();

const newExpenseReport = await getOnyxValue(`${ONYXKEYS.COLLECTION.REPORT}${newExpenseReportID}`);
Expand Down
Loading
Loading