Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import useThemeStyles from '@hooks/useThemeStyles';
import ControlSelection from '@libs/ControlSelection';
import {convertToDisplayString} from '@libs/CurrencyUtils';
import {canUseTouchScreen} from '@libs/DeviceCapabilities';
import {hasNonReimbursableTransactions as hasNonReimbursableTransactionsMoneyRequestReportUtils} from '@libs/MoneyRequestReportUtils';
import Navigation from '@libs/Navigation/Navigation';
import {getInvoicePayerName, getReportName} from '@libs/ReportNameUtils';
import {
Expand All @@ -41,7 +42,6 @@ import {
getReportStatusColorStyle,
getReportStatusTranslation,
getTransactionsWithReceipts,
hasNonReimbursableTransactions as hasNonReimbursableTransactionsReportUtils,
hasOnlyHeldExpenses as hasOnlyHeldExpensesReportUtils,
hasOnlyTransactionsWithPendingRoutes as hasOnlyTransactionsWithPendingRoutesReportUtils,
isInvoiceRoom as isInvoiceRoomReportUtils,
Expand Down Expand Up @@ -140,7 +140,7 @@ function MoneyRequestReportPreviewContent({
() => ({
areAllRequestsBeingSmartScanned: areAllRequestsBeingSmartScannedReportUtils(iouReportID, action),
hasOnlyTransactionsWithPendingRoutes: hasOnlyTransactionsWithPendingRoutesReportUtils(iouReportID),
hasNonReimbursableTransactions: hasNonReimbursableTransactionsReportUtils(iouReportID),
hasNonReimbursableTransactions: hasNonReimbursableTransactionsMoneyRequestReportUtils(transactions),
}),
// When transactions get updated these values may have changed, so that is a case where we also want to recompute them
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down
26 changes: 19 additions & 7 deletions src/libs/ReportNameUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ import {
getTransactionReportName,
getUnreportedTransactionMessage,
getWorkspaceNameUpdatedMessage,
hasNonReimbursableTransactions,
isAdminRoom,
isArchivedNonExpenseReport,
isCanceledTaskReport,
Expand All @@ -152,7 +151,9 @@ import {
isThread,
isTripRoom,
isUserCreatedPolicyRoom,
reportTransactionsSelector,
} from './ReportUtils';
import {getReimbursable} from './TransactionUtils';

type ComputeReportName = {
report?: Report;
Expand Down Expand Up @@ -329,8 +330,8 @@ function getInvoicesChatName({
return getPolicyName({report, policy: receiverPolicy});
}

function getInvoiceReportName(report: OnyxEntry<Report>, policy?: OnyxEntry<Policy>, invoiceReceiverPolicy?: OnyxEntry<Policy>): string {
const moneyRequestReportName = getMoneyRequestReportName({report, policy, invoiceReceiverPolicy});
function getInvoiceReportName(report: OnyxEntry<Report>, policy?: OnyxEntry<Policy>, invoiceReceiverPolicy?: OnyxEntry<Policy>, transactions?: Transaction[]): string {
const moneyRequestReportName = getMoneyRequestReportName({report, policy, invoiceReceiverPolicy, transactions});
const oldDotInvoiceName = report?.reportName ?? moneyRequestReportName;
return isNewDotInvoice(report?.chatReportID) ? moneyRequestReportName : oldDotInvoiceName;
}
Expand All @@ -355,7 +356,17 @@ function getInvoicePayerName(report: OnyxEntry<Report>, invoiceReceiverPolicy?:
/**
* Get the title for an IOU or expense chat which will be showing the payer and the amount
*/
function getMoneyRequestReportName({report, policy, invoiceReceiverPolicy}: {report: OnyxEntry<Report>; policy?: OnyxEntry<Policy>; invoiceReceiverPolicy?: OnyxEntry<Policy>}): string {
function getMoneyRequestReportName({
report,
policy,
invoiceReceiverPolicy,
transactions = [],
}: {
report: OnyxEntry<Report>;
policy?: OnyxEntry<Policy>;
invoiceReceiverPolicy?: OnyxEntry<Policy>;
transactions?: Transaction[];
}): string {
// For expense reports with empty fieldList and empty reportName, return "New Report" (matches OldDot behavior)
if (isExpenseReport(report)) {
if (report?.reportName === '' && isPolicyFieldListEmpty(policy)) {
Expand Down Expand Up @@ -393,7 +404,7 @@ function getMoneyRequestReportName({report, policy, invoiceReceiverPolicy}: {rep
return `${payerPaidAmountMessage} ${CONST.DOT_SEPARATOR} ${translateLocal('iou.pending')}`;
}

if (!isSettled(report?.reportID) && hasNonReimbursableTransactions(report?.reportID)) {
if (!isSettled(report?.reportID) && transactions.some((transaction) => !getReimbursable(transaction))) {
payerOrApproverName = getDisplayNameForParticipant({accountID: report?.ownerAccountID, formatPhoneNumber: formatPhoneNumberPhoneUtils}) ?? '';
// eslint-disable-next-line @typescript-eslint/no-deprecated
return translateLocal('iou.payerSpentAmount', formattedAmount, payerOrApproverName);
Expand Down Expand Up @@ -914,8 +925,9 @@ function computeReportName({
}

const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`];
const reportTransactions = reportTransactionsSelector(transactions, report.reportID);
if (isMoneyRequestReport(report)) {
formattedName = getMoneyRequestReportName({report, policy});
formattedName = getMoneyRequestReportName({report, policy, transactions: reportTransactions});
}

if (isInvoiceReport(report)) {
Expand All @@ -926,7 +938,7 @@ function computeReportName({
chatReceiverPolicyID = (chatReceiver as {policyID: string}).policyID;
}
const invoiceReceiverPolicy = chatReceiverPolicyID ? policies?.[`${ONYXKEYS.COLLECTION.POLICY}${chatReceiverPolicyID}`] : undefined;
formattedName = getInvoiceReportName(report, policy, invoiceReceiverPolicy);
formattedName = getInvoiceReportName(report, policy, invoiceReceiverPolicy, reportTransactions);
}

if (isInvoiceRoom(report)) {
Expand Down
15 changes: 3 additions & 12 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@
isTax: false,
};

let conciergeReportIDOnyxConnect: OnyxEntry<string>;

Check warning on line 1055 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
Onyx.connect({
key: ONYXKEYS.CONCIERGE_REPORT_ID,
callback: (value) => {
Expand All @@ -1060,7 +1060,7 @@
},
});

const defaultAvatarBuildingIconTestID = 'SvgDefaultAvatarBuilding Icon';

Check warning on line 1063 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
Onyx.connect({
key: ONYXKEYS.SESSION,
callback: (value) => {
Expand All @@ -1078,7 +1078,7 @@

let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
let allPersonalDetailLogins: string[];
let currentUserPersonalDetails: OnyxEntry<PersonalDetails>;

Check warning on line 1081 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
Onyx.connect({
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
Expand All @@ -1090,7 +1090,7 @@
},
});

let allReportsDraft: OnyxCollection<Report>;

Check warning on line 1093 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT_DRAFT,
waitForCollectionCallback: true,
Expand All @@ -1098,7 +1098,7 @@
});

let allPolicies: OnyxCollection<Policy>;
let policiesArray: Policy[] = [];

Check warning on line 1101 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
Onyx.connect({
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
Expand All @@ -1108,7 +1108,7 @@
},
});

let allPolicyDrafts: OnyxCollection<Policy>;

Check warning on line 1111 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
Onyx.connect({
key: ONYXKEYS.COLLECTION.POLICY_DRAFTS,
waitForCollectionCallback: true,
Expand All @@ -1116,7 +1116,7 @@
});

let allReports: OnyxCollection<Report>;
let reportsByPolicyID: ReportByPolicyMap;

Check warning on line 1119 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
Expand Down Expand Up @@ -1152,14 +1152,14 @@
},
});

let betaConfiguration: OnyxEntry<BetaConfiguration> = {};

Check warning on line 1155 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
Onyx.connect({
key: ONYXKEYS.BETA_CONFIGURATION,
callback: (value) => (betaConfiguration = value ?? {}),
});

let deprecatedAllTransactions: OnyxCollection<Transaction> = {};
let deprecatedReportsTransactions: Record<string, Transaction[]> = {};

Check warning on line 1162 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
Onyx.connect({
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
Expand All @@ -1185,7 +1185,7 @@
},
});

let allReportActions: OnyxCollection<ReportActions>;

Check warning on line 1188 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,
Expand Down Expand Up @@ -4372,14 +4372,6 @@
return !!getReasonAndReportActionThatRequiresAttention(optionOrReport, parentReportAction, isReportArchived);
}

/**
* Checks if the report contains at least one Non-Reimbursable transaction
*/
function hasNonReimbursableTransactions(iouReportID: string | undefined, reportsTransactionsParam: Record<string, Transaction[]> = deprecatedReportsTransactions): boolean {
const transactions = getReportTransactions(iouReportID, reportsTransactionsParam);
return transactions.filter((transaction) => transaction.reimbursable === false).length > 0;
}

function getMoneyRequestSpendBreakdown(report: OnyxInputOrEntry<Report>, searchReports?: Report[]): SpendBreakdown {
const reports = searchReports ?? allReports;
let moneyRequestReport: OnyxEntry<Report>;
Expand Down Expand Up @@ -5441,7 +5433,7 @@
}
}

const containsNonReimbursable = hasNonReimbursableTransactions(report.reportID);
const containsNonReimbursable = getReportTransactions(report.reportID).some((transaction) => !getReimbursable(transaction));
const {totalDisplaySpend: totalAmount} = getMoneyRequestSpendBreakdown(report);

const parentReport = getParentReport(report);
Expand Down Expand Up @@ -6008,11 +6000,11 @@
}

if (isMoneyRequestReport(report)) {
formattedName = getMoneyRequestReportName({report, policy});
formattedName = getMoneyRequestReportName({report, policy, transactions});
}

if (isInvoiceReport(report)) {
formattedName = getInvoiceReportName(report, policy, invoiceReceiverPolicy);
formattedName = getInvoiceReportName(report, policy, invoiceReceiverPolicy, transactions);
}

if (isInvoiceRoom(report)) {
Expand Down Expand Up @@ -13645,7 +13637,6 @@
hasExpensifyGuidesEmails,
hasHeldExpenses,
hasIOUWaitingOnCurrentUserBankAccount,
hasNonReimbursableTransactions,
hasOnlyHeldExpenses,
hasOnlyTransactionsWithPendingRoutes,
hasReceiptError,
Expand Down
4 changes: 2 additions & 2 deletions src/libs/actions/IOU/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import isFileUploadable from '@libs/isFileUploadable';
import {formatPhoneNumber} from '@libs/LocalePhoneNumber';
import * as Localize from '@libs/Localize';
import Log from '@libs/Log';
import {hasNonReimbursableTransactions as hasNonReimbursableTransactionsMoneyRequestReportUtils} from '@libs/MoneyRequestReportUtils';
import isReportOpenInRHP from '@libs/Navigation/helpers/isReportOpenInRHP';
import isReportOpenInSuperWideRHP from '@libs/Navigation/helpers/isReportOpenInSuperWideRHP';
import isReportTopmostSplitNavigator from '@libs/Navigation/helpers/isReportTopmostSplitNavigator';
Expand Down Expand Up @@ -155,7 +156,6 @@ import {
getReportTransactions,
getTransactionDetails,
hasHeldExpenses as hasHeldExpensesReportUtils,
hasNonReimbursableTransactions as hasNonReimbursableTransactionsReportUtils,
hasOnlyNonReimbursableTransactions,
hasOutstandingChildRequest,
hasViolations as hasViolationsReportUtils,
Expand Down Expand Up @@ -8142,7 +8142,7 @@ function prepareToCleanUpMoneyRequest(
updatedIOUReport.lastVisibleActionCreated = lastVisibleAction?.created;
}

const hasNonReimbursableTransactions = hasNonReimbursableTransactionsReportUtils(iouReport?.reportID);
const hasNonReimbursableTransactions = hasNonReimbursableTransactionsMoneyRequestReportUtils(getReportTransactions(iouReport?.reportID));
// eslint-disable-next-line @typescript-eslint/no-deprecated
const messageText = Localize.translateLocal(
hasNonReimbursableTransactions ? 'iou.payerSpentAmount' : 'iou.payerOwesAmount',
Expand Down
Loading