Skip to content

Commit

Permalink
Merge pull request #49837 from koko57/fix/49333-show-different-messag…
Browse files Browse the repository at this point in the history
…e-for-optimistic-update

fix: change message when reimbursementChoice is reimburseNo
  • Loading branch information
srikarparsi authored Oct 11, 2024
2 parents 4c90d62 + 177dd5e commit b7c1e1e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 37 deletions.
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!',
},
],
};

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 = {
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 @@ -4491,6 +4491,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 @@ -4517,10 +4546,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

0 comments on commit b7c1e1e

Please sign in to comment.