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

54 changes: 21 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 @@ -125,6 +135,12 @@ function buildNextStep(report: OnyxEntry<Report>, predictedNextStatus: ValueOf<t
],
};

if (!PolicyUtils.arePaymentsEnabled(policy)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry one more thing, @koko57 do you think you could explain why you added this? If payments are disabled and there is some non instant auto reporting frequency (weekly, monthly, etc.), the next steps should still be "Waiting for x's expenses to automatically submit" (below text). cc @trjExpensify for confirmation.

Copy link
Contributor

Choose a reason for hiding this comment

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

A delayed submission frequency other than manually, yes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@srikarparsi I understood that it also must be that way. So I will remove it

optimisticNextStep = noActionRequired;

break;
}

// Scheduled submit enabled
if (harvesting?.enabled && autoReportingFrequency !== CONST.POLICY.AUTO_REPORTING_FREQUENCIES.MANUAL) {
optimisticNextStep.message = [
Expand Down Expand Up @@ -216,16 +232,10 @@ 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
// or when a report has been paid
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!',
},
],
};
case CONST.REPORT.STATUS_NUM.REIMBURSED:
optimisticNextStep = noActionRequired;

break;

Expand All @@ -241,15 +251,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 +284,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