Skip to content
Draft
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
43 changes: 28 additions & 15 deletions src/libs/actions/IOU/RejectMoneyRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@
urlToNavigateBack: Route | undefined;
};

type RejectMoneyRequestOptions = {
sharedRejectedToReportID?: string;
existingRejectedReport?: OnyxEntry<OnyxTypes.Report>;
};

function dismissRejectUseExplanation() {
const parameters: SetNameValuePairParams = {
name: ONYXKEYS.NVP_DISMISSED_REJECT_USE_EXPLANATION,
Expand Down Expand Up @@ -108,7 +113,7 @@
currentUserAccountIDParam: number,
currentUserLogin: string,
betas: OnyxEntry<OnyxTypes.Beta[]>,
options?: {sharedRejectedToReportID?: string},
options?: RejectMoneyRequestOptions,
shouldUseBulkAction?: boolean,
): RejectMoneyRequestData | undefined {
const allTransactions = getAllTransactions();
Expand Down Expand Up @@ -348,17 +353,25 @@
// 1. Update report total
// 2. Remove expense from report
// 3. Add to existing draft report or create new one
const existingOpenReport = Object.values(allReports ?? {}).find(
(r) =>
r?.reportID !== reportID &&
r?.chatReportID === report.chatReportID &&
r?.type === CONST.REPORT.TYPE.EXPENSE &&
isOpenReport(r) &&
r?.ownerAccountID === report.ownerAccountID,
);
const existingOpenReport =
options?.existingRejectedReport ??
Object.values(allReports ?? {}).find(
(r) =>
r?.reportID !== reportID &&
r?.chatReportID === report.chatReportID &&
r?.type === CONST.REPORT.TYPE.EXPENSE &&
isOpenReport(r) &&
r?.ownerAccountID === report.ownerAccountID,
);

if (existingOpenReport) {
movedToReport = existingOpenReport;
movedToReport = {
...existingOpenReport,
total: (existingOpenReport?.total ?? 0) - transactionAmount,
};
if (options) {
options.existingRejectedReport = movedToReport;

Check failure on line 373 in src/libs/actions/IOU/RejectMoneyRequest.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Assignment to property of function parameter 'options'

Check failure on line 373 in src/libs/actions/IOU/RejectMoneyRequest.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Assignment to property of function parameter 'options'
}
rejectedToReportID = existingOpenReport.reportID;

const [, , iouAction] = buildOptimisticMoneyRequestEntities({
Expand All @@ -380,10 +393,7 @@
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${movedToReport?.reportID}`,
value: {
...movedToReport,
total: (movedToReport?.total ?? 0) - transactionAmount,
},
value: movedToReport,
},
{
onyxMethod: Onyx.METHOD.MERGE,
Expand Down Expand Up @@ -473,6 +483,9 @@
expenseMovedReportActionID = movedTransactionAction.reportActionID;
expenseCreatedReportActionID = createdActionForExpenseReport.reportActionID;
newExpenseReport.parentReportActionID = reportPreviewAction.reportActionID;
if (options) {
options.existingRejectedReport = newExpenseReport;

Check failure on line 487 in src/libs/actions/IOU/RejectMoneyRequest.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Assignment to property of function parameter 'options'

Check failure on line 487 in src/libs/actions/IOU/RejectMoneyRequest.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Assignment to property of function parameter 'options'
}
optimisticData.push(
{
onyxMethod: Onyx.METHOD.MERGE,
Expand Down Expand Up @@ -886,7 +899,7 @@
currentUserAccountIDParam: number,
currentUserLogin: string,
betas: OnyxEntry<OnyxTypes.Beta[]>,
options?: {sharedRejectedToReportID?: string},
options?: RejectMoneyRequestOptions,
): Route | undefined {
const data = prepareRejectMoneyRequestData(transactionID, reportID, comment, policy, currentUserAccountIDParam, currentUserLogin, betas, options);
if (!data) {
Expand Down
4 changes: 2 additions & 2 deletions src/libs/actions/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1088,9 +1088,9 @@ function rejectMoneyRequestsOnSearch(
rejectMoneyRequestInBulk(reportID, comment, policy, selectedTransactionIDs, currentUserAccountIDParam, currentUserLogin, betas, hash);
} else {
// Share a single destination ID across all rejections from the same source report
const sharedRejectedToReportID = generateReportID();
const sharedRejectOptions = {sharedRejectedToReportID: generateReportID()};
for (const transactionID of selectedTransactionIDs) {
rejectMoneyRequest(transactionID, reportID, comment, policy, currentUserAccountIDParam, currentUserLogin, betas, {sharedRejectedToReportID});
rejectMoneyRequest(transactionID, reportID, comment, policy, currentUserAccountIDParam, currentUserLogin, betas, sharedRejectOptions);
}
}
if (isSingleReport && areAllExpensesSelected && !isPolicyDelayedSubmissionEnabled) {
Expand Down
Loading