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: change message when reimbursementChoice is reimburseNo #49837

52 changes: 19 additions & 33 deletions src/libs/NextStepUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ function buildNextStep(report: OnyxEntry<Report>, predictedNextStatus: ValueOf<t
const type: ReportNextStep['type'] = 'neutral';
let optimisticNextStep: ReportNextStep | null;

const noActionRequired = {
icon: CONST.NEXT_STEP.ICONS.CHECKMARK,
type,
message: [
{
text: 'No further action required!',
srikarparsi marked this conversation as resolved.
Show resolved Hide resolved
},
],
};

switch (predictedNextStatus) {
// Generates an optimistic nextStep once a report has been opened
case CONST.REPORT.STATUS_NUM.OPEN:
Expand Down Expand Up @@ -217,15 +227,13 @@ function buildNextStep(report: OnyxEntry<Report>, predictedNextStatus: ValueOf<t

// Generates an optimistic nextStep once a report has been closed for example in the case of Submit and Close approval flow
case CONST.REPORT.STATUS_NUM.CLOSED:
optimisticNextStep = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add optimisticNextStep = noActionRequired and the break. I think it would improve readability a little.

icon: CONST.NEXT_STEP.ICONS.CHECKMARK,
type,
message: [
{
text: 'No further action required!',
},
],
};
optimisticNextStep = noActionRequired;

break;

// Generates an optimistic nextStep once a report has been paid
case CONST.REPORT.STATUS_NUM.REIMBURSED:
optimisticNextStep = noActionRequired;

break;

Expand All @@ -241,15 +249,8 @@ function buildNextStep(report: OnyxEntry<Report>, predictedNextStatus: ValueOf<t
report,
)
) {
optimisticNextStep = {
type,
icon: CONST.NEXT_STEP.ICONS.CHECKMARK,
message: [
{
text: 'No further action required!',
},
],
};
optimisticNextStep = noActionRequired;

break;
}
// Self review
Expand Down Expand Up @@ -281,21 +282,6 @@ function buildNextStep(report: OnyxEntry<Report>, predictedNextStatus: ValueOf<t
};
break;

// Generates an optimistic nextStep once a report has been paid
case CONST.REPORT.STATUS_NUM.REIMBURSED:
// Paid with wallet
optimisticNextStep = {
type,
icon: CONST.NEXT_STEP.ICONS.CHECKMARK,
message: [
{
text: 'No further action required!',
},
],
};

break;

// Resets a nextStep
default:
optimisticNextStep = null;
Expand Down
34 changes: 30 additions & 4 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4484,6 +4484,35 @@ function buildOptimisticInvoiceReport(chatReportID: string, policyID: string, re
};
}

/**
* Returns the stateNum and statusNum for an expense report based on the policy settings
* @param policy
*/
function getExpenseReportStateAndStatus(policy: OnyxEntry<Policy>) {
const isInstantSubmitEnabled = PolicyUtils.isInstantSubmitEnabled(policy);
const isSubmitAndClose = PolicyUtils.isSubmitAndClose(policy);
const arePaymentsDisabled = policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_NO;

if (isInstantSubmitEnabled && arePaymentsDisabled && isSubmitAndClose) {
return {
stateNum: CONST.REPORT.STATE_NUM.APPROVED,
statusNum: CONST.REPORT.STATUS_NUM.CLOSED,
};
}

if (isInstantSubmitEnabled) {
return {
stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED,
};
}

return {
stateNum: CONST.REPORT.STATE_NUM.OPEN,
statusNum: CONST.REPORT.STATUS_NUM.OPEN,
};
}

/**
* Builds an optimistic Expense report with a randomly generated reportID
*
Expand All @@ -4510,10 +4539,7 @@ function buildOptimisticExpenseReport(
const formattedTotal = CurrencyUtils.convertToDisplayString(storedTotal, currency);
const policy = getPolicy(policyID);

const isInstantSubmitEnabled = PolicyUtils.isInstantSubmitEnabled(policy);

const stateNum = isInstantSubmitEnabled ? CONST.REPORT.STATE_NUM.SUBMITTED : CONST.REPORT.STATE_NUM.OPEN;
const statusNum = isInstantSubmitEnabled ? CONST.REPORT.STATUS_NUM.SUBMITTED : CONST.REPORT.STATUS_NUM.OPEN;
const {stateNum, statusNum} = getExpenseReportStateAndStatus(policy);

const expenseReport: OptimisticExpenseReport = {
reportID: generateReportID(),
Expand Down
Loading