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
45 changes: 40 additions & 5 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,12 @@ function MoneyReportHeader({
userBillingGraceEndPeriods,
amountOwed,
methodID: type === CONST.IOU.PAYMENT_TYPE.VBBA ? methodID : undefined,
onPaid: () => {
if (isFromSelectionMode) {
return;
}
startAnimation();
},
});
if (currentSearchQueryJSON && !isOffline) {
search({
Expand Down Expand Up @@ -801,6 +807,12 @@ function MoneyReportHeader({
userBillingGraceEndPeriods,
amountOwed,
full: true,
onApproved: () => {
if (skipAnimation) {
return;
}
startApprovedAnimation();
},
});
if (skipAnimation) {
clearSelectedTransactions(true);
Expand Down Expand Up @@ -837,10 +849,23 @@ function MoneyReportHeader({
showDWEModal();
return;
}
if (!skipAnimation) {
startSubmittingAnimation();
}
submitReport(moneyRequestReport, policy, accountID, email ?? '', hasViolations, isASAPSubmitBetaEnabled, nextStep, userBillingGraceEndPeriods, amountOwed);
submitReport({
expenseReport: moneyRequestReport,
policy,
currentUserAccountIDParam: accountID,
currentUserEmailParam: email ?? '',
hasViolations,
isASAPSubmitBetaEnabled,
expenseReportCurrentNextStepDeprecated: nextStep,
userBillingGraceEndPeriods,
amountOwed,
onSubmitted: () => {
if (skipAnimation) {
return;
}
startSubmittingAnimation();
},
});
if (currentSearchQueryJSON && !isOffline) {
search({
searchKey: currentSearchKey,
Expand Down Expand Up @@ -1676,7 +1701,17 @@ function MoneyReportHeader({
showDWEModal();
return;
}
submitReport(moneyRequestReport, policy, accountID, email ?? '', hasViolations, isASAPSubmitBetaEnabled, nextStep, userBillingGraceEndPeriods, amountOwed);
submitReport({
expenseReport: moneyRequestReport,
policy,
currentUserAccountIDParam: accountID,
currentUserEmailParam: email ?? '',
hasViolations,
isASAPSubmitBetaEnabled,
expenseReportCurrentNextStepDeprecated: nextStep,
userBillingGraceEndPeriods,
amountOwed,
});
},
},
[CONST.REPORT.SECONDARY_ACTIONS.APPROVE]: {
Expand Down
8 changes: 2 additions & 6 deletions src/components/ProcessMoneyReportHoldMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ function ProcessMoneyReportHoldMenu({
}

if (isApprove) {
if (startAnimation) {
startAnimation();
}
approveMoneyRequest({
expenseReport: moneyRequestReport,
policy: activePolicy,
Expand All @@ -115,11 +112,9 @@ function ProcessMoneyReportHoldMenu({
userBillingGraceEndPeriods,
amountOwed,
full,
onApproved: startAnimation,
});
} else if (chatReport && paymentType) {
if (startAnimation) {
startAnimation();
}
payMoneyRequest({
paymentType,
chatReport,
Expand All @@ -135,6 +130,7 @@ function ProcessMoneyReportHoldMenu({
userBillingGraceEndPeriods,
amountOwed,
methodID,
onPaid: startAnimation,
});
}
onClose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ function MoneyRequestReportPreviewContent({
} else if (hasHeldExpensesReportUtils(iouReport?.reportID)) {
setIsHoldMenuVisible(true);
} else if (chatReport && iouReport) {
startAnimation();
if (isInvoiceReportUtils(iouReport)) {
startAnimation();
payInvoice({
paymentMethodType: type,
chatReport,
Expand Down Expand Up @@ -311,6 +311,7 @@ function MoneyRequestReportPreviewContent({
isSelfTourViewed,
userBillingGraceEndPeriods,
amountOwed,
onPaid: startAnimation,
});
}
}
Expand Down Expand Up @@ -360,7 +361,6 @@ function MoneyRequestReportPreviewContent({
} else if (hasHeldExpensesReportUtils(iouReport?.reportID)) {
setIsHoldMenuVisible(true);
} else {
startApprovedAnimation();
approveMoneyRequest({
expenseReport: iouReport,
policy: activePolicy,
Expand All @@ -373,6 +373,7 @@ function MoneyRequestReportPreviewContent({
userBillingGraceEndPeriods,
amountOwed,
full: true,
onApproved: startApprovedAnimation,
});
}
};
Expand Down Expand Up @@ -753,18 +754,18 @@ function MoneyRequestReportPreviewContent({
showDEWModal();
return;
}
startSubmittingAnimation();
submitReport(
iouReport,
submitReport({
expenseReport: iouReport,
policy,
currentUserAccountID,
currentUserEmail,
currentUserAccountIDParam: currentUserAccountID,
currentUserEmailParam: currentUserEmail,
hasViolations,
isASAPSubmitBetaEnabled,
iouReportNextStep,
expenseReportCurrentNextStepDeprecated: iouReportNextStep,
userBillingGraceEndPeriods,
amountOwed,
);
onSubmitted: startSubmittingAnimation,
});
}}
isSubmittingAnimationRunning={isSubmittingAnimationRunning}
onAnimationFinish={stopAnimation}
Expand Down
107 changes: 68 additions & 39 deletions src/libs/actions/IOU/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@
};

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

Check warning on line 775 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 @@ -869,10 +869,39 @@
isSelfTourViewed: boolean | undefined;
amountOwed: OnyxEntry<number>;
methodID?: number;
onPaid?: () => void;
};

type ApproveMoneyRequestFunctionParams = {
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;
onApproved?: () => void;
};

type SubmitReportFunctionParams = {
expenseReport: OnyxEntry<OnyxTypes.Report>;
policy: OnyxEntry<OnyxTypes.Policy>;
currentUserAccountIDParam: number;
currentUserEmailParam: string;
hasViolations: boolean;
isASAPSubmitBetaEnabled: boolean;
expenseReportCurrentNextStepDeprecated: OnyxEntry<OnyxTypes.ReportNextStepDeprecated>;
userBillingGraceEndPeriods: OnyxCollection<OnyxTypes.BillingGraceEndPeriod>;
amountOwed: OnyxEntry<number>;
onSubmitted?: () => void;
};

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

Check warning on line 904 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 @@ -886,7 +915,7 @@
});

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

Check warning on line 918 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 @@ -895,7 +924,7 @@
});

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

Check warning on line 927 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 @@ -909,7 +938,7 @@
});

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

Check warning on line 941 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 @@ -922,7 +951,7 @@
});

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

Check warning on line 954 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 @@ -931,7 +960,7 @@
});

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

Check warning on line 963 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 @@ -941,7 +970,7 @@

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

Check warning on line 973 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 @@ -950,7 +979,7 @@
});

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

Check warning on line 982 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 All @@ -958,7 +987,7 @@
});

let allReportActions: OnyxCollection<OnyxTypes.ReportActions>;
Onyx.connect({

Check warning on line 990 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_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
Expand Down Expand Up @@ -9833,33 +9862,21 @@
return createdAction?.created ?? expenseReport.created;
}

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) {
function approveMoneyRequest(params: ApproveMoneyRequestFunctionParams) {
const {
expenseReport,
policy,
currentUserAccountIDParam,
currentUserEmailParam,
hasViolations,
isASAPSubmitBetaEnabled,
expenseReportCurrentNextStepDeprecated,
betas,
userBillingGraceEndPeriods,
amountOwed,
full,
onApproved,
} = params;
if (!expenseReport) {
return;
}
Expand Down Expand Up @@ -9969,7 +9986,14 @@
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${expenseReport.chatReportID}`,
value: {
hasOutstandingChildRequest: hasOutstandingChildRequest(chatReport, updatedExpenseReport, currentUserEmail, currentUserAccountIDParam, allTransactionViolations, undefined),
hasOutstandingChildRequest: hasOutstandingChildRequest(
chatReport,
updatedExpenseReport,
currentUserEmailParam,
currentUserAccountIDParam,
allTransactionViolations,
undefined,
),
},
});
}
Expand Down Expand Up @@ -10197,6 +10221,7 @@
optimisticCreatedReportForUnapprovedTransactionsActionID,
};

onApproved?.();
playSound(SOUNDS.SUCCESS);
API.write(WRITE_COMMANDS.APPROVE_MONEY_REQUEST, parameters, {optimisticData, successData, failureData});
return optimisticHoldReportID;
Expand Down Expand Up @@ -10732,17 +10757,18 @@
API.write(WRITE_COMMANDS.UNAPPROVE_EXPENSE_REPORT, parameters, {optimisticData, successData, failureData});
}

function submitReport(
expenseReport: OnyxEntry<OnyxTypes.Report>,
policy: OnyxEntry<OnyxTypes.Policy>,
currentUserAccountIDParam: number,
currentUserEmailParam: string,
hasViolations: boolean,
isASAPSubmitBetaEnabled: boolean,
expenseReportCurrentNextStepDeprecated: OnyxEntry<OnyxTypes.ReportNextStepDeprecated>,
userBillingGraceEndPeriods: OnyxCollection<OnyxTypes.BillingGraceEndPeriod>,
amountOwed: OnyxEntry<number>,
) {
function submitReport({
expenseReport,
policy,
currentUserAccountIDParam,
currentUserEmailParam,
hasViolations,
isASAPSubmitBetaEnabled,
expenseReportCurrentNextStepDeprecated,
userBillingGraceEndPeriods,
amountOwed,
onSubmitted,
}: SubmitReportFunctionParams) {
if (!expenseReport) {
return;
}
Expand Down Expand Up @@ -11003,6 +11029,7 @@
reportActionID: optimisticSubmittedReportAction.reportActionID,
};

onSubmitted?.();
API.write(WRITE_COMMANDS.SUBMIT_REPORT, parameters, {optimisticData, successData, failureData});
}

Expand Down Expand Up @@ -11279,6 +11306,7 @@
isSelfTourViewed,
amountOwed,
methodID,
onPaid,
} = params;
if (chatReport.policyID && shouldRestrictUserBillableActions(chatReport.policyID, userBillingGraceEndPeriods, amountOwed)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(chatReport.policyID));
Expand Down Expand Up @@ -11309,6 +11337,7 @@
// Expensify Wallets.
const apiCommand = paymentType === CONST.IOU.PAYMENT_TYPE.EXPENSIFY ? WRITE_COMMANDS.PAY_MONEY_REQUEST_WITH_WALLET : WRITE_COMMANDS.PAY_MONEY_REQUEST;

onPaid?.();
playSound(SOUNDS.SUCCESS);
API.write(apiCommand, payMoneyRequestParams, onyxData);
notifyNewAction(!full ? (Navigation.getTopmostReportId() ?? iouReport?.reportID) : iouReport?.reportID, undefined, true);
Expand Down
Loading
Loading