Skip to content
Merged
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
24 changes: 22 additions & 2 deletions src/libs/NextStepUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ function buildOptimisticNextStep(params: BuildNextStepNewParams): ReportNextStep
const approverAccountID = bypassNextApproverID ?? getNextApproverAccountID(report, isUnapprove);
const reimburserAccountID = getReimburserAccountID(policy);
const hasValidAccount = !!policy?.achAccount?.accountNumber || policy?.reimbursementChoice !== CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES;
const {reimbursableSpend} = getMoneyRequestSpendBreakdown(report);

const nextStepFixOrPayExpense: ReportNextStep = {
messageKey: shouldShowFixMessage ? CONST.NEXT_STEP.MESSAGE_KEY.WAITING_TO_FIX_ISSUES : CONST.NEXT_STEP.MESSAGE_KEY.WAITING_TO_PAY,
Expand Down Expand Up @@ -210,7 +211,7 @@ function buildOptimisticNextStep(params: BuildNextStepNewParams): ReportNextStep
// Generates an optimistic nextStep once a report has been submitted
case CONST.REPORT.STATUS_NUM.SUBMITTED: {
if (policy?.approvalMode === CONST.POLICY.APPROVAL_MODE.OPTIONAL) {
nextStep = nextStepFixOrPayExpense;
nextStep = reimbursableSpend === 0 ? nextStepNoActionRequired : nextStepFixOrPayExpense;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

} else {

@marufsharifi just checking- does the report slip through these checks?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, it can. getActions() correctly removes PAY for a $0 report, but before this change the section builders could still render the row based on status/type alone, so it could still appear in Ready to Pay.

break;
}

Expand Down Expand Up @@ -244,7 +245,7 @@ function buildOptimisticNextStep(params: BuildNextStepNewParams): ReportNextStep

// Generates an optimistic nextStep once a report has been approved
case CONST.REPORT.STATUS_NUM.APPROVED:
if (isInvoiceReport(report) || !isPayer(currentUserAccountIDParam, currentUserEmailParam, report, undefined)) {
if (isInvoiceReport(report) || !isPayer(currentUserAccountIDParam, currentUserEmailParam, report, undefined) || reimbursableSpend === 0) {
nextStep = nextStepNoActionRequired;
break;
}
Expand Down Expand Up @@ -363,6 +364,12 @@ function getReportNextStep(
currentUserEmail: string,
currentUserAccountID: number,
) {
const {reimbursableSpend} = getMoneyRequestSpendBreakdown(moneyRequestReport);
const shouldShowNoFurtherAction =
reimbursableSpend === 0 &&
(moneyRequestReport?.statusNum === CONST.REPORT.STATUS_NUM.APPROVED ||
(moneyRequestReport?.statusNum === CONST.REPORT.STATUS_NUM.SUBMITTED && policy?.approvalMode === CONST.POLICY.APPROVAL_MODE.OPTIONAL));
Comment on lines +368 to +371
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

does this need to be hardcoded? has was it shown before

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, I think this override is needed. The header still reads from the deprecated nextStep object via getReportNextStep(), so fixing only buildOptimisticNextStep() would not update a stale "Waiting to pay" value. This just overrides that stale case for $0 submitted/approved reports while still using the existing legacy builder for the message shape


if (
isOpenExpenseReport(moneyRequestReport) &&
transactions.length > 0 &&
Expand All @@ -381,6 +388,19 @@ function getReportNextStep(
return buildOptimisticNextStepForPreventSelfApprovalsEnabled();
}

if (shouldShowNoFurtherAction) {
// eslint-disable-next-line @typescript-eslint/no-deprecated -- The report header still consumes the deprecated nextStep shape, so we intentionally reuse the legacy builder here to override stale server nextStep data for $0 reports.
return buildNextStepNew({
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Lint issue

report: moneyRequestReport,
policy,
currentUserAccountIDParam: currentUserAccountID,
currentUserEmailParam: currentUserEmail,
hasViolations: false,
isASAPSubmitBetaEnabled: false,
predictedNextStatus: moneyRequestReport?.statusNum ?? CONST.REPORT.STATUS_NUM.OPEN,
});
}

return currentNextStep;
}
function buildOptimisticNextStepForDynamicExternalWorkflowSubmitError(iconFill?: string) {
Expand Down
18 changes: 18 additions & 0 deletions src/libs/SearchUIUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,16 @@ type TransactionWeekGroupSorting = ColumnSortMapping<TransactionWeekGroupListIte
type TransactionYearGroupSorting = ColumnSortMapping<TransactionYearGroupListItemType>;
type TransactionQuarterGroupSorting = ColumnSortMapping<TransactionQuarterGroupListItemType>;

function isPayActionSearch(queryJSON: SearchQueryJSON | undefined): boolean {
return (
queryJSON?.flatFilters.some(
(filter) =>
filter.key === CONST.SEARCH.SYNTAX_FILTER_KEYS.ACTION &&
filter.filters.some((queryFilter) => queryFilter.operator === CONST.SEARCH.SYNTAX_OPERATORS.EQUAL_TO && queryFilter.value.toString() === CONST.SEARCH.ACTION_FILTERS.PAY),
) ?? false
);
}

type GetReportSectionsParams = {
data: OnyxTypes.SearchResults['data'];
policies: OnyxCollection<OnyxTypes.Policy>;
Expand Down Expand Up @@ -2022,6 +2032,7 @@ function getTransactionsSections({
const transactionsSections: TransactionListItemType[] = [];

const currentQueryJSON = queryJSON ?? getCurrentSearchQueryJSON();
const isPaySearch = isPayActionSearch(currentQueryJSON);

for (const key of transactionKeys) {
const transactionItem = data[key];
Expand Down Expand Up @@ -2069,6 +2080,9 @@ function getTransactionsSections({
const actions = reportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionItem.reportID}`] ?? [];
const reportMetadata = allReportMetadata?.[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${transactionItem.reportID}`] ?? {};
const allActions = getActions(data, allViolations, key, currentSearch, currentUserEmail, currentAccountID, bankAccountList, reportMetadata, actions);
if (isPaySearch && !allActions.includes(CONST.SEARCH.ACTION_TYPES.PAY)) {
continue;
}
const transactionPendingAction = getTransactionPendingAction(transactionItem);
const transactionAttendees = getAttendees(transactionItem, currentUserPersonalDetails);
const isUnreported = transactionItem.reportID === CONST.REPORT.UNREPORTED_REPORT_ID;
Expand Down Expand Up @@ -2617,6 +2631,7 @@ function getReportSections({
} = classifyAndPreprocess(data);

const currentQueryJSON = queryJSON ?? getCurrentSearchQueryJSON();
const isPaySearch = isPayActionSearch(currentQueryJSON);
const reportIDToTransactions: Record<string, TransactionReportGroupListItemType> = {};

const orderedKeys: string[] = [...reportKeys, ...transactionKeys];
Expand Down Expand Up @@ -2657,6 +2672,9 @@ function getReportSections({
const reportMetadata = allReportMetadata?.[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportItem.reportID}`] ?? {};
const allReportTransactions = transactionsByReportID.get(reportItem.reportID) ?? [];
const allActions = getActions(data, allViolations, key, currentSearch, currentUserEmail, currentAccountID, bankAccountList, reportMetadata, actions, allReportTransactions);
if (isPaySearch && !allActions.includes(CONST.SEARCH.ACTION_TYPES.PAY)) {
continue;
}

const fromDetails =
mergedPersonalDetails?.[reportItem.ownerAccountID ?? CONST.DEFAULT_NUMBER_ID] ??
Expand Down
Loading