diff --git a/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx b/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx index 9dc2c0fa758d7..5677c733e6e9f 100644 --- a/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx +++ b/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx @@ -52,10 +52,10 @@ import { areAllRequestsBeingSmartScanned as areAllRequestsBeingSmartScannedReportUtils, getAddExpenseDropdownOptions, getDisplayNameForParticipant, - getMoneyReportPreviewName, getMoneyRequestSpendBreakdown, getNonHeldAndFullAmount, getPolicyName, + getReportName, getReportStatusColorStyle, getReportStatusTranslation, getTransactionsWithReceipts, @@ -126,7 +126,6 @@ function MoneyRequestReportPreviewContent({ currentWidth, reportPreviewStyles, shouldDisplayContextMenu = true, - isInvoice, shouldShowBorder = false, onPress, forwardedFSClass, @@ -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); @@ -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} diff --git a/src/components/ReportActionItem/MoneyRequestReportPreview/index.tsx b/src/components/ReportActionItem/MoneyRequestReportPreview/index.tsx index 8e60d87023e9b..606d702304988 100644 --- a/src/components/ReportActionItem/MoneyRequestReportPreview/index.tsx +++ b/src/components/ReportActionItem/MoneyRequestReportPreview/index.tsx @@ -36,7 +36,6 @@ function MoneyRequestReportPreview({ onPaymentOptionsShow, onPaymentOptionsHide, shouldDisplayContextMenu = true, - isInvoice = false, shouldShowBorder, }: MoneyRequestReportPreviewProps) { const styles = useThemeStyles(); @@ -167,7 +166,6 @@ function MoneyRequestReportPreview({ currentWidth={widths.currentWidth} reportPreviewStyles={reportPreviewStyles} shouldDisplayContextMenu={shouldDisplayContextMenu} - isInvoice={isInvoice} onPress={openReportFromPreview} shouldShowBorder={shouldShowBorder} forwardedFSClass={CONST.FULLSTORY.CLASS.UNMASK} diff --git a/src/components/ReportActionItem/MoneyRequestReportPreview/types.ts b/src/components/ReportActionItem/MoneyRequestReportPreview/types.ts index f5b2174088c18..5f6ec4bca3cc0 100644 --- a/src/components/ReportActionItem/MoneyRequestReportPreview/types.ts +++ b/src/components/ReportActionItem/MoneyRequestReportPreview/types.ts @@ -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; }; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 0712d2280b1a6..92f3dabe24861 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -12629,17 +12629,6 @@ function hasReportBeenRetracted(report: OnyxEntry, reportActions?: OnyxE return reportActionList.some((action) => isRetractedAction(action)); } -function getMoneyReportPreviewName(action: ReportAction, iouReport: OnyxEntry, 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> | undefined> | null | undefined, ): Record | undefined { @@ -13298,7 +13287,6 @@ export { canRejectReportAction, hasReportBeenReopened, hasReportBeenRetracted, - getMoneyReportPreviewName, getNextApproverAccountID, isWorkspaceTaskReport, isWorkspaceThread, diff --git a/src/pages/inbox/report/PureReportActionItem.tsx b/src/pages/inbox/report/PureReportActionItem.tsx index afceb51f7b20e..6e430399a41a7 100644 --- a/src/pages/inbox/report/PureReportActionItem.tsx +++ b/src/pages/inbox/report/PureReportActionItem.tsx @@ -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)} diff --git a/tests/ui/MoneyRequestReportPreview.test.tsx b/tests/ui/MoneyRequestReportPreview.test.tsx index e2c9624fc5a8a..7e5c1b8e61b75 100644 --- a/tests/ui/MoneyRequestReportPreview.test.tsx +++ b/tests/ui/MoneyRequestReportPreview.test.tsx @@ -39,7 +39,7 @@ jest.mock('@rnmapbox/maps', () => { jest.mock('@src/hooks/useReportWithTransactionsAndViolations', () => jest.fn((): [OnyxEntry, Transaction[], OnyxCollection] => { - return [mockChatReport, [mockTransaction, {...mockTransaction, transactionID: mockSecondTransactionID}], {violations: mockViolations}]; + return [mockIOUReport, [mockTransaction, {...mockTransaction, transactionID: mockSecondTransactionID}], {violations: mockViolations}]; }), ); @@ -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); diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 5e28dd1c7e6a8..3af7489e9837a 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -74,7 +74,6 @@ import { getIconsForParticipants, getIndicatedMissingPaymentMethod, getIOUReportActionDisplayMessage, - getMoneyReportPreviewName, getMostRecentlyVisitedReport, getOriginalReportID, getOutstandingChildRequest, @@ -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