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 submit button when there is only non-reimbursable expenses #55610

Merged
merged 5 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea

const isAdmin = policy?.role === CONST.POLICY.ROLE.ADMIN;

const shouldShowSubmitButton = canSubmitReport(moneyRequestReport, policy, transactionIDs);
const shouldShowSubmitButton = canSubmitReport(moneyRequestReport, policy, allTransactions);

const shouldShowExportIntegrationButton = !shouldShowPayButton && !shouldShowSubmitButton && connectedIntegration && isAdmin && canBeExported(moneyRequestReport);

Expand Down
4 changes: 2 additions & 2 deletions src/components/ReportActionItem/ReportPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ function ReportPreview({
const lastThreeTransactions = allTransactions.slice(-3);
const lastThreeReceipts = lastThreeTransactions.map((transaction) => ({...getThumbnailAndImageURIs(transaction), transaction}));
const showRTERViolationMessage = numberOfRequests === 1 && hasPendingUI(allTransactions.at(0), getTransactionViolations(allTransactions.at(0)?.transactionID, transactionViolations));
const transactionIDList = [allTransactions.at(0)?.transactionID].filter((transactionID): transactionID is string => transactionID !== undefined);
const transactionIDList = allTransactions.map((reportTransaction) => reportTransaction.transactionID);
const shouldShowBrokenConnectionViolation = numberOfRequests === 1 && shouldShowBrokenConnectionViolationTransactionUtils(transactionIDList, iouReport, policy);
let formattedMerchant = numberOfRequests === 1 ? getMerchant(allTransactions.at(0)) : null;
const formattedDescription = numberOfRequests === 1 ? getDescription(allTransactions.at(0)) : null;
Expand All @@ -246,7 +246,7 @@ function ReportPreview({

const isArchived = isArchivedReport(iouReport);
const isAdmin = policy?.role === CONST.POLICY.ROLE.ADMIN;
const shouldShowSubmitButton = canSubmitReport(iouReport, policy, transactionIDList, transactionViolations);
const shouldShowSubmitButton = canSubmitReport(iouReport, policy, allTransactions, transactionViolations);

const shouldDisableSubmitButton = shouldShowSubmitButton && !isAllowedToSubmitDraftExpenseReport(iouReport);

Expand Down
3 changes: 1 addition & 2 deletions src/libs/SearchUIUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,7 @@ function getAction(data: OnyxTypes.SearchResults['data'], key: string): SearchTr
}

// We check for isAllowedToApproveExpenseReport because if the policy has preventSelfApprovals enabled, we disable the Submit action and in that case we want to show the View action instead
const transactionIDList = allReportTransactions.map((reportTransaction) => reportTransaction.transactionID);
if (canSubmitReport(report, policy, transactionIDList, allViolations) && isAllowedToApproveExpenseReport) {
if (canSubmitReport(report, policy, allReportTransactions, allViolations) && isAllowedToApproveExpenseReport) {
return CONST.SEARCH.ACTION_TYPES.SUBMIT;
}

Expand Down
14 changes: 11 additions & 3 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,13 @@ import {
getTransaction,
getUpdatedTransaction,
hasReceipt as hasReceiptTransactionUtils,
isAmountMissing,
isDistanceRequest as isDistanceRequestTransactionUtils,
isExpensifyCardTransaction,
isFetchingWaypointsFromServer,
isOnHold,
isPartialMerchant,
isPending,
isPerDiemRequest as isPerDiemRequestTransactionUtils,
isReceiptBeingScanned as isReceiptBeingScannedTransactionUtils,
isScanRequest as isScanRequestTransactionUtils,
Expand Down Expand Up @@ -7844,21 +7848,25 @@ function canIOUBePaid(
function canSubmitReport(
report: OnyxEntry<OnyxTypes.Report> | SearchReport,
policy: OnyxEntry<OnyxTypes.Policy> | SearchPolicy,
transactionIDList: string[],
transactions: OnyxTypes.Transaction[] | SearchTransaction[],
allViolations?: OnyxCollection<OnyxTypes.TransactionViolations>,
) {
const currentUserAccountID = getCurrentUserAccountID();
const isOpenExpenseReport = isOpenExpenseReportReportUtils(report);
const isArchived = isArchivedReport(report);
const {reimbursableSpend} = getMoneyRequestSpendBreakdown(report);
const isAdmin = policy?.role === CONST.POLICY.ROLE.ADMIN;
const transactionIDList = transactions.map((transaction) => transaction.transactionID);
const hasAllPendingRTERViolations = allHavePendingRTERViolation(transactionIDList, allViolations);
const hasBrokenConnectionViolation = shouldShowBrokenConnectionViolation(transactionIDList, report, policy, allViolations);

const hasOnlyPendingCardOrScanFailTransactions =
transactions.length > 0 &&
transactions.every((t) => (isExpensifyCardTransaction(t) && isPending(t)) || (isPartialMerchant(getMerchant(t)) && isAmountMissing(t)) || isReceiptBeingScannedTransactionUtils(t));

return (
isOpenExpenseReport &&
!isArchived &&
reimbursableSpend !== 0 &&
!hasOnlyPendingCardOrScanFailTransactions &&
!hasAllPendingRTERViolations &&
!hasBrokenConnectionViolation &&
Copy link
Contributor

Choose a reason for hiding this comment

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

coming from #56044, there was a regression, we should have added a transactions.length > 0 here

(report?.ownerAccountID === currentUserAccountID || isAdmin || report?.managerID === currentUserAccountID)
Expand Down
Loading