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

fix: Second approver unapproval shows 'Waiting for first approver' in next steps #52297

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
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
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(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(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 @@ -8048,11 +8048,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 @@ -8240,7 +8248,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