Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle optimistic data when creating new expenses in Control w/ Instant Submit #49677

Merged
merged 6 commits into from
Oct 23, 2024
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
15 changes: 15 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,16 @@ function isProcessingReport(report: OnyxEntry<Report>): boolean {
return report?.stateNum === CONST.REPORT.STATE_NUM.SUBMITTED && report?.statusNum === CONST.REPORT.STATUS_NUM.SUBMITTED;
}

function isAwaitingFirstLevelApproval(report: OnyxEntry<Report>): boolean {
if (!report) {
return false;
}

const submitsToAccountID = PolicyUtils.getSubmitToAccountID(getPolicy(report.policyID), report.ownerAccountID ?? -1);

return isProcessingReport(report) && submitsToAccountID === report.managerID;
}

/**
* Check if the report is a single chat report that isn't a thread
* and personal detail of participant is optimistic data
Expand Down Expand Up @@ -1739,6 +1749,10 @@ function canAddOrDeleteTransactions(moneyRequestReport: OnyxEntry<Report>): bool
return false;
}

if (PolicyUtils.isInstantSubmitEnabled(policy) && isProcessingReport(moneyRequestReport)) {
return isAwaitingFirstLevelApproval(moneyRequestReport);
}

if (isReportApproved(moneyRequestReport) || isSettled(moneyRequestReport?.reportID)) {
return false;
}
Expand Down Expand Up @@ -8492,6 +8506,7 @@ export {
isPolicyExpenseChat,
isPolicyExpenseChatAdmin,
isProcessingReport,
isAwaitingFirstLevelApproval,
isPublicAnnounceRoom,
isPublicRoom,
isReportApproved,
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -691,13 +691,21 @@ describe('ReportUtils', () => {
owner: '',
outputCurrency: '',
isPolicyExpenseChatEnabled: false,
employeeList: {
[currentUserEmail]: {
email: currentUserEmail,
submitsTo: currentUserEmail,
},
},
};
Promise.all([
Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${paidPolicy.id}`, paidPolicy),
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}101`, {
reportID: '101',
chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT,
isOwnPolicyExpenseChat: true,
policyID: paidPolicy.id,
ownerAccountID: currentUserAccountID,
}),
]).then(() => {
const report = {
Expand All @@ -708,6 +716,7 @@ describe('ReportUtils', () => {
parentReportID: '101',
policyID: paidPolicy.id,
managerID: currentUserAccountID,
ownerAccountID: currentUserAccountID,
};
const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, paidPolicy, [currentUserAccountID, participantsAccountIDs.at(0) ?? -1]);
expect(moneyRequestOptions.length).toBe(2);
Expand Down
Loading