Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ import {
areAllRequestsBeingSmartScanned as areAllRequestsBeingSmartScannedReportUtils,
getAddExpenseDropdownOptions,
getDisplayNameForParticipant,
getMoneyReportPreviewName,
getMoneyRequestSpendBreakdown,
getNonHeldAndFullAmount,
getPolicyName,
getReportName,
getReportStatusColorStyle,
getReportStatusTranslation,
getTransactionsWithReceipts,
Expand Down Expand Up @@ -126,7 +126,6 @@ function MoneyRequestReportPreviewContent({
currentWidth,
reportPreviewStyles,
shouldDisplayContextMenu = true,
isInvoice,
shouldShowBorder = false,
onPress,
forwardedFSClass,
Expand Down Expand Up @@ -228,12 +227,6 @@ function MoneyRequestReportPreviewContent({

const [reportAttributes] = useOnyx(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES, {canBeMissing: true, selector: reportAttributesSelector});

const currentReportName = iouReport?.reportID ? reportAttributes?.[iouReport.reportID]?.reportName : undefined;
const reportPreviewName = useMemo(() => {
return getMoneyReportPreviewName(action, iouReport, isInvoice, reportAttributes);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [action, iouReport, isInvoice, currentReportName]);

const hasReceipts = transactionsWithReceipts.length > 0;
const isScanning = hasReceipts && areAllRequestsBeingSmartScanned;
const existingB2BInvoiceReport = useParticipantsInvoiceReport(activePolicyID, CONST.REPORT.INVOICE_RECEIVER_TYPE.BUSINESS, chatReport?.policyID);
Expand Down Expand Up @@ -787,7 +780,9 @@ function MoneyRequestReportPreviewContent({
style={[styles.headerText]}
testID="MoneyRequestReportPreview-reportName"
>
{reportPreviewName}
{/* This will be fixed as follow up https://github.com/Expensify/App/pull/75357 */}
{/* eslint-disable-next-line @typescript-eslint/no-deprecated */}
{getReportName(iouReport, undefined, undefined, undefined, undefined, reportAttributes) || action.childReportName}
</Text>
</Animated.View>
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ function MoneyRequestReportPreview({
onPaymentOptionsShow,
onPaymentOptionsHide,
shouldDisplayContextMenu = true,
isInvoice = false,
shouldShowBorder,
}: MoneyRequestReportPreviewProps) {
const styles = useThemeStyles();
Expand Down Expand Up @@ -167,7 +166,6 @@ function MoneyRequestReportPreview({
currentWidth={widths.currentWidth}
reportPreviewStyles={reportPreviewStyles}
shouldDisplayContextMenu={shouldDisplayContextMenu}
isInvoice={isInvoice}
onPress={openReportFromPreview}
shouldShowBorder={shouldShowBorder}
forwardedFSClass={CONST.FULLSTORY.CLASS.UNMASK}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ type MoneyRequestReportPreviewProps = {
/** Whether context menu should be shown on press */
shouldDisplayContextMenu?: boolean;

/** Whether the report is an invoice preview */
isInvoice?: boolean;

/** Whether to show a border to separate Reports Chat Item and Money Request Report Preview */
shouldShowBorder?: boolean;
};
Expand Down
12 changes: 0 additions & 12 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@
};

let conciergeReportIDOnyxConnect: OnyxEntry<string>;
Onyx.connect({

Check warning on line 1016 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
key: ONYXKEYS.CONCIERGE_REPORT_ID,
callback: (value) => {
conciergeReportIDOnyxConnect = value;
Expand All @@ -1021,7 +1021,7 @@
});

const defaultAvatarBuildingIconTestID = 'SvgDefaultAvatarBuilding Icon';
Onyx.connect({

Check warning on line 1024 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
key: ONYXKEYS.SESSION,
callback: (value) => {
// When signed out, val is undefined
Expand All @@ -1039,7 +1039,7 @@
let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
let allPersonalDetailLogins: string[];
let currentUserPersonalDetails: OnyxEntry<PersonalDetails>;
Onyx.connect({

Check warning on line 1042 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
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
if (currentUserAccountID) {
Expand All @@ -1051,7 +1051,7 @@
});

let allReportsDraft: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 1054 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
key: ONYXKEYS.COLLECTION.REPORT_DRAFT,
waitForCollectionCallback: true,
callback: (value) => (allReportsDraft = value),
Expand All @@ -1060,7 +1060,7 @@
let allPolicies: OnyxCollection<Policy>;
let hasPolicies: boolean;
let policiesArray: Policy[] = [];
Onyx.connect({

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
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -1071,7 +1071,7 @@
});

let allPolicyDrafts: OnyxCollection<Policy>;
Onyx.connect({

Check warning on line 1074 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
key: ONYXKEYS.COLLECTION.POLICY_DRAFTS,
waitForCollectionCallback: true,
callback: (value) => (allPolicyDrafts = value),
Expand All @@ -1079,7 +1079,7 @@

let allReports: OnyxCollection<Report>;
let reportsByPolicyID: ReportByPolicyMap;
Onyx.connect({

Check warning on line 1082 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
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand Down Expand Up @@ -1115,14 +1115,14 @@
});

let betaConfiguration: OnyxEntry<BetaConfiguration> = {};
Onyx.connect({

Check warning on line 1118 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
key: ONYXKEYS.BETA_CONFIGURATION,
callback: (value) => (betaConfiguration = value ?? {}),
});

let allTransactions: OnyxCollection<Transaction> = {};
let reportsTransactions: Record<string, Transaction[]> = {};
Onyx.connect({

Check warning on line 1125 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
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -1148,7 +1148,7 @@
});

let allReportActions: OnyxCollection<ReportActions>;
Onyx.connect({

Check warning on line 1151 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
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
Expand Down Expand Up @@ -12629,17 +12629,6 @@
return reportActionList.some((action) => isRetractedAction(action));
}

function getMoneyReportPreviewName(action: ReportAction, iouReport: OnyxEntry<Report>, isInvoice?: boolean, reportAttributes?: ReportAttributesDerivedValue['reports']) {
if (isInvoice && isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW)) {
const originalMessage = getOriginalMessage(action);
// eslint-disable-next-line @typescript-eslint/no-deprecated
return originalMessage && translateLocal('iou.invoiceReportName', originalMessage);
}
// This will be fixed as follow up https://github.com/Expensify/App/pull/75357
// eslint-disable-next-line @typescript-eslint/no-deprecated
return getReportName(iouReport, undefined, undefined, undefined, undefined, reportAttributes) || action.childReportName;
}

function selectFilteredReportActions(
reportActions: Record<string, Record<string, OnyxInputOrEntry<ReportAction>> | undefined> | null | undefined,
): Record<string, ReportAction[]> | undefined {
Expand Down Expand Up @@ -13298,7 +13287,6 @@
canRejectReportAction,
hasReportBeenReopened,
hasReportBeenRetracted,
getMoneyReportPreviewName,
getNextApproverAccountID,
isWorkspaceTaskReport,
isWorkspaceThread,
Expand Down
1 change: 0 additions & 1 deletion src/pages/inbox/report/PureReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,6 @@ function PureReportActionItem({
contextMenuAnchor={popoverAnchorRef.current}
isHovered={hovered}
isWhisper={isWhisper}
isInvoice={action.childType === CONST.REPORT.CHAT_TYPE.INVOICE}
checkIfContextMenuActive={toggleContextMenuFromActiveReportAction}
onPaymentOptionsShow={() => setIsPaymentMethodPopoverActive(true)}
onPaymentOptionsHide={() => setIsPaymentMethodPopoverActive(false)}
Expand Down
9 changes: 6 additions & 3 deletions tests/ui/MoneyRequestReportPreview.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jest.mock('@rnmapbox/maps', () => {

jest.mock('@src/hooks/useReportWithTransactionsAndViolations', () =>
jest.fn((): [OnyxEntry<Report>, Transaction[], OnyxCollection<TransactionViolation[]>] => {
return [mockChatReport, [mockTransaction, {...mockTransaction, transactionID: mockSecondTransactionID}], {violations: mockViolations}];
return [mockIOUReport, [mockTransaction, {...mockTransaction, transactionID: mockSecondTransactionID}], {violations: mockViolations}];
}),
);

Expand Down Expand Up @@ -155,11 +155,14 @@ describe('MoneyRequestReportPreview', () => {
await waitForBatchedUpdatesWithAct();
});
await waitForBatchedUpdatesWithAct();
const {reportName: moneyRequestReportPreviewName = ''} = mockChatReport;

// This will be fixed as follow up https://github.com/Expensify/App/pull/75357
// eslint-disable-next-line @typescript-eslint/no-deprecated
expect(screen.getByText(ReportUtils.getReportName(mockIOUReport, undefined, undefined, undefined, undefined, undefined))).toBeOnTheScreen();

for (const transaction of arrayOfTransactions) {
const {transactionDisplayAmount, transactionHeaderText} = getTransactionDisplayAmountAndHeaderText(transaction);

expect(screen.getByText(moneyRequestReportPreviewName)).toBeOnTheScreen();
expect(screen.getByText(transactionDisplayAmount)).toBeOnTheScreen();
expect(screen.getAllByText(transactionHeaderText)).toHaveLength(arrayOfTransactions.length);
expect(screen.getAllByText(transaction.merchant)).toHaveLength(arrayOfTransactions.length);
Expand Down
141 changes: 0 additions & 141 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ import {
getIconsForParticipants,
getIndicatedMissingPaymentMethod,
getIOUReportActionDisplayMessage,
getMoneyReportPreviewName,
getMostRecentlyVisitedReport,
getOriginalReportID,
getOutstandingChildRequest,
Expand Down Expand Up @@ -6740,146 +6739,6 @@ describe('ReportUtils', () => {
});
});

describe('getMoneyReportPreviewName', () => {
beforeAll(async () => {
await Onyx.clear();
await Onyx.multiSet({
[ONYXKEYS.PERSONAL_DETAILS_LIST]: participantsPersonalDetails,
[ONYXKEYS.SESSION]: {email: currentUserEmail, accountID: currentUserAccountID},
});
});

afterAll(async () => {
await Onyx.clear();
});

it('should return the report name when the chat type is policy room', () => {
const action: ReportAction = {
...createRandomReportAction(1),
actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
};
const report: Report = createRandomReport(1, CONST.REPORT.CHAT_TYPE.POLICY_ROOM);
const result = getMoneyReportPreviewName(action, report);
expect(result).toBe(report.reportName);
});

it('should return the report name when the chat type is domain all', () => {
const action: ReportAction = {
...createRandomReportAction(1),
actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
};
const report: Report = createRandomReport(1, CONST.REPORT.CHAT_TYPE.DOMAIN_ALL);
const result = getMoneyReportPreviewName(action, report);
expect(result).toBe(report.reportName);
});

it('should return the report name when the chat type is group', () => {
const action: ReportAction = {
...createRandomReportAction(1),
actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
};
const report: Report = createRandomReport(1, CONST.REPORT.CHAT_TYPE.GROUP);
const result = getMoneyReportPreviewName(action, report);
expect(result).toBe(report.reportName);
});

it('should return policy name when the chat type is invoice', () => {
const action: ReportAction = {
...createRandomReportAction(1),
actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
};
const report: Report = createRandomReport(1, CONST.REPORT.CHAT_TYPE.INVOICE);
const result = getMoneyReportPreviewName(action, report);
// Policies are empty, so the policy name is "Unavailable workspace"
expect(result).toBe('Unavailable workspace');
});

it('should return the report name when the chat type is policy admins', () => {
const action: ReportAction = {
...createRandomReportAction(1),
actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
};
const report: Report = createRandomReport(1, CONST.REPORT.CHAT_TYPE.POLICY_ADMINS);
const result = getMoneyReportPreviewName(action, report);
expect(result).toBe(report.reportName);
});

it('should return the report name when the chat type is policy announce', () => {
const action: ReportAction = {
...createRandomReportAction(1),
actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
};
const report: Report = createRandomReport(1, CONST.REPORT.CHAT_TYPE.POLICY_ANNOUNCE);
const result = getMoneyReportPreviewName(action, report);
expect(result).toBe(report.reportName);
});

it('should return the owner name expenses when the chat type is policy expense chat', () => {
const action: ReportAction = {
...createRandomReportAction(1),
actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
};
const report: Report = createRandomReport(1, CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT);
const result = getMoneyReportPreviewName(action, report);
// Report with ownerAccountID: 1 corresponds to "Ragnar Lothbrok"
expect(result).toBe("Ragnar Lothbrok's expenses");
});

it('should return the display name of the current user when the chat type is self dm', () => {
const action: ReportAction = {
...createRandomReportAction(1),
actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
};
const report: Report = createRandomReport(1, CONST.REPORT.CHAT_TYPE.SELF_DM);
const result = getMoneyReportPreviewName(action, report);
// currentUserAccountID: 5 corresponds to "Lagertha Lothbrok"
expect(result).toBe('Lagertha Lothbrok (you)');
});

it('should return the participant name when the chat type is system', () => {
const action: ReportAction = {
...createRandomReportAction(1),
actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
};
const report: Report = {
...createRandomReport(1, CONST.REPORT.CHAT_TYPE.SYSTEM),
participants: {
1: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN},
},
};
const result = getMoneyReportPreviewName(action, report);
// participant accountID: 1 corresponds to "Ragnar Lothbrok"
expect(result).toBe('Ragnar Lothbrok');
});

it('should return the participant names when the chat type is trip room', () => {
const action: ReportAction = {
...createRandomReportAction(1),
actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
};
const report: Report = {
...createRandomReport(1, CONST.REPORT.CHAT_TYPE.TRIP_ROOM),
participants: {
1: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN},
2: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS},
},
};
const result = getMoneyReportPreviewName(action, report);
// participant accountID: 1, 2 corresponds to "Ragnar", "floki@vikings.net"
expect(result).toBe('Ragnar, floki@vikings.net');
});

it('should return the child report name when the report name is not present', () => {
const action: ReportAction = {
...createRandomReportAction(1),
actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
childReportName: 'Child Report',
};
const result = getMoneyReportPreviewName(action, undefined);
expect(result).toBe('Child Report');
});
});

describe('canAddTransaction', () => {
it('should return true for a non-archived report', async () => {
// Given a non-archived expense report
Expand Down
Loading