Skip to content

Commit

Permalink
Merge pull request #52297 from truph01/fix/50269
Browse files Browse the repository at this point in the history
fix: Second approver unapproval shows 'Waiting for first approver' in next steps
  • Loading branch information
Julesssss authored Feb 6, 2025
2 parents ba9e3fc + 7100109 commit 8f1d240
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/libs/NextStepUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type DeepValueOf from '@src/types/utils/DeepValueOf';
import {getNextApproverAccountID} from './actions/IOU';
import DateUtils from './DateUtils';
import EmailUtils from './EmailUtils';
import {getLoginsByAccountIDs} from './PersonalDetailsUtils';
import {getCorrectedAutoReportingFrequency, getReimburserAccountID} from './PolicyUtils';
import {getDisplayNameForParticipant, getPersonalDetailsForAccountID, isExpenseReport, isInvoiceReport, isPayer} from './ReportUtils';

Expand Down Expand Up @@ -66,8 +67,8 @@ function parseMessage(messages: Message[] | undefined) {
return `<next-step>${formattedHtml}</next-step>`;
}

function getNextApproverDisplayName(report: OnyxEntry<Report>) {
const approverAccountID = getNextApproverAccountID(report);
function getNextApproverDisplayName(report: OnyxEntry<Report>, isUnapprove?: boolean) {
const approverAccountID = getNextApproverAccountID(report, isUnapprove);

return getDisplayNameForParticipant({accountID: approverAccountID}) ?? getPersonalDetailsForAccountID(approverAccountID).login;
}
Expand All @@ -80,7 +81,7 @@ function getNextApproverDisplayName(report: OnyxEntry<Report>) {
* @param parameters.isPaidWithExpensify - Whether a report has been paid with Expensify or outside
* @returns nextStep
*/
function buildNextStep(report: OnyxEntry<Report>, predictedNextStatus: ValueOf<typeof CONST.REPORT.STATUS_NUM>): ReportNextStep | null {
function buildNextStep(report: OnyxEntry<Report>, predictedNextStatus: ValueOf<typeof CONST.REPORT.STATUS_NUM>, isUnapprove?: boolean): ReportNextStep | null {
if (!isExpenseReport(report)) {
return null;
}
Expand All @@ -90,7 +91,9 @@ function buildNextStep(report: OnyxEntry<Report>, predictedNextStatus: ValueOf<t
const {harvesting, autoReportingOffset} = policy;
const autoReportingFrequency = getCorrectedAutoReportingFrequency(policy);
const ownerDisplayName = getDisplayNameForParticipant({accountID: ownerAccountID});
const nextApproverDisplayName = getNextApproverDisplayName(report);
const nextApproverDisplayName = getNextApproverDisplayName(report, isUnapprove);
const approverAccountID = getNextApproverAccountID(report, isUnapprove);
const approvers = getLoginsByAccountIDs([approverAccountID ?? CONST.DEFAULT_NUMBER_ID]);

const reimburserAccountID = getReimburserAccountID(policy);
const hasValidAccount = !!policy?.achAccount?.accountNumber;
Expand Down Expand Up @@ -232,6 +235,7 @@ function buildNextStep(report: OnyxEntry<Report>, predictedNextStatus: ValueOf<t
{
text: nextApproverDisplayName,
type: 'strong',
clickToCopyText: approvers.at(0),
},
{
text: ' to ',
Expand Down
12 changes: 10 additions & 2 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8092,11 +8092,19 @@ function isLastApprover(approvalChain: string[]): boolean {
return approvalChain.at(-1) === currentUserEmail;
}

function getNextApproverAccountID(report: OnyxEntry<OnyxTypes.Report>) {
function getNextApproverAccountID(report: OnyxEntry<OnyxTypes.Report>, isUnapproved = false) {
const policy = getPolicy(report?.policyID);
const approvalChain = getApprovalChain(policy, report);
const submitToAccountID = getSubmitToAccountID(policy, report);

if (isUnapproved) {
if (approvalChain.includes(currentUserEmail)) {
return userAccountID;
}

return report?.managerID;
}

if (approvalChain.length === 0) {
return submitToAccountID;
}
Expand Down Expand Up @@ -8284,7 +8292,7 @@ function unapproveExpenseReport(expenseReport: OnyxEntry<OnyxTypes.Report>) {
const currentNextStep = allNextSteps[`${ONYXKEYS.COLLECTION.NEXT_STEP}${expenseReport.reportID}`] ?? null;

const optimisticUnapprovedReportAction = buildOptimisticUnapprovedReportAction(expenseReport.total ?? 0, expenseReport.currency ?? '', expenseReport.reportID);
const optimisticNextStep = buildNextStep(expenseReport, CONST.REPORT.STATUS_NUM.SUBMITTED);
const optimisticNextStep = buildNextStep(expenseReport, CONST.REPORT.STATUS_NUM.SUBMITTED, true);

const optimisticReportActionData: OnyxUpdate = {
onyxMethod: Onyx.METHOD.MERGE,
Expand Down

0 comments on commit 8f1d240

Please sign in to comment.