diff --git a/src/CONST.ts b/src/CONST.ts index ef2e43c1ad47..65764d730f2f 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -1410,6 +1410,17 @@ const CONST = { TRANSACTION_LIST: { COLUMNS: { COMMENTS: 'comments', + RECEIPT: 'receipt', + DATE: 'date', + MERCHANT: 'merchant', + FROM: 'from', + TO: 'to', + CATEGORY: 'category', + TAG: 'tag', + TOTAL_AMOUNT: 'amount', + TYPE: 'type', + ACTION: 'action', + TAX: 'tax', }, }, CANCEL_PAYMENT_REASONS: { diff --git a/src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx b/src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx index cf9b2266f3fe..bfc4d36cb078 100644 --- a/src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx +++ b/src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx @@ -67,6 +67,17 @@ const sortableColumnNames = [ CONST.SEARCH.TABLE_COLUMNS.TOTAL_AMOUNT, ]; +const allReportColumns = [ + CONST.REPORT.TRANSACTION_LIST.COLUMNS.RECEIPT, + CONST.REPORT.TRANSACTION_LIST.COLUMNS.TYPE, + CONST.REPORT.TRANSACTION_LIST.COLUMNS.DATE, + CONST.REPORT.TRANSACTION_LIST.COLUMNS.MERCHANT, + CONST.REPORT.TRANSACTION_LIST.COLUMNS.CATEGORY, + CONST.REPORT.TRANSACTION_LIST.COLUMNS.TAG, + CONST.REPORT.TRANSACTION_LIST.COLUMNS.COMMENTS, + CONST.REPORT.TRANSACTION_LIST.COLUMNS.TOTAL_AMOUNT, +]; + type SortableColumnName = TupleToUnion; type SortedTransactions = { @@ -260,6 +271,7 @@ function MoneyRequestReportTransactionList({report, transactions, reportActions, shouldUseNarrowLayout={shouldUseNarrowLayout || isMediumScreenWidth} shouldShowCheckbox={!!selectionMode?.isEnabled || isMediumScreenWidth} onCheckboxPress={toggleTransaction} + columns={allReportColumns} /> ); diff --git a/src/components/SelectionList/Search/ReportListItem.tsx b/src/components/SelectionList/Search/ReportListItem.tsx index 4bfef2fec15a..902dcca0d1d6 100644 --- a/src/components/SelectionList/Search/ReportListItem.tsx +++ b/src/components/SelectionList/Search/ReportListItem.tsx @@ -1,21 +1,24 @@ -import React from 'react'; +import React, {useMemo} from 'react'; import {View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; +import type {ValueOf} from 'type-fest'; import BaseListItem from '@components/SelectionList/BaseListItem'; import type {ListItem, ReportListItemProps, ReportListItemType, TransactionListItemType} from '@components/SelectionList/types'; import Text from '@components/Text'; +import TransactionItemRow from '@components/TransactionItemRow'; import useAnimatedHighlightStyle from '@hooks/useAnimatedHighlightStyle'; import useLocalize from '@hooks/useLocalize'; import usePermissions from '@hooks/usePermissions'; +import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import Navigation from '@libs/Navigation/Navigation'; +import shouldShowTransactionYear from '@libs/TransactionUtils/shouldShowTransactionYear'; import variables from '@styles/variables'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import ReportListItemHeader from './ReportListItemHeader'; -import TransactionListItemRow from './TransactionListItemRow'; function ReportListItem({ item, @@ -38,6 +41,12 @@ function ReportListItem({ const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${reportItem?.policyID}`]; const isEmptyReport = reportItem.transactions.length === 0; const isDisabledOrEmpty = isEmptyReport || isDisabled; + const {isLargeScreenWidth} = useResponsiveLayout(); + + const dateColumnSize = useMemo(() => { + const shouldShowYearForSomeTransaction = reportItem.transactions.some((transaction) => shouldShowTransactionYear(transaction)); + return shouldShowYearForSomeTransaction ? CONST.SEARCH.TABLE_COLUMN_SIZES.WIDE : CONST.SEARCH.TABLE_COLUMN_SIZES.NORMAL; + }, [reportItem.transactions]); const animatedHighlightStyle = useAnimatedHighlightStyle({ borderRadius: variables.componentBorderRadius, @@ -78,6 +87,23 @@ function ReportListItem({ return null; } + const sampleTransaction = reportItem.transactions.at(0); + const {COLUMNS} = CONST.REPORT.TRANSACTION_LIST; + + const columns = [ + COLUMNS.RECEIPT, + COLUMNS.TYPE, + COLUMNS.DATE, + COLUMNS.MERCHANT, + COLUMNS.FROM, + COLUMNS.TO, + ...(sampleTransaction?.shouldShowCategory ? [COLUMNS.CATEGORY] : []), + ...(sampleTransaction?.shouldShowTag ? [COLUMNS.TAG] : []), + ...(sampleTransaction?.shouldShowTax ? [COLUMNS.TAX] : []), + COLUMNS.TOTAL_AMOUNT, + COLUMNS.ACTION, + ] as Array>; + return ( ({ hoverStyle={item.isSelected && styles.activeComponentBG} pressableWrapperStyle={[styles.mh5, animatedHighlightStyle]} > - {(hovered?: boolean) => ( + {(hovered) => ( ({ ) : ( reportItem.transactions.map((transaction) => ( - { - openReportInRHP(transaction); - }} - onCheckboxPress={() => onCheckboxPress?.(transaction as unknown as TItem)} - showItemHeaderOnNarrowLayout={false} - containerStyle={[transaction.isSelected && styles.activeComponentBG, styles.ph3, styles.pv1half]} - isChildListItem - isDisabled={!!isDisabled} - canSelectMultiple={!!canSelectMultiple} - isButtonSelected={transaction.isSelected} - shouldShowTransactionCheckbox - /> + + onCheckboxPress?.(transaction as unknown as TItem)} + columns={columns} + onButtonPress={() => { + openReportInRHP(transaction); + }} + isParentHovered={hovered} + columnWrapperStyles={[styles.ph3, styles.pv1half]} + /> + )) )} diff --git a/src/components/TransactionItemRow/DataCells/MerchantCell.tsx b/src/components/TransactionItemRow/DataCells/MerchantCell.tsx index 65dcd9e96177..092c8a84e83d 100644 --- a/src/components/TransactionItemRow/DataCells/MerchantCell.tsx +++ b/src/components/TransactionItemRow/DataCells/MerchantCell.tsx @@ -5,7 +5,7 @@ import {getMerchant} from '@libs/TransactionUtils'; import CONST from '@src/CONST'; import type TransactionDataCellProps from './TransactionDataCellProps'; -function MerchantCell({transactionItem, shouldShowTooltip}: TransactionDataCellProps) { +function MerchantCell({transactionItem, shouldShowTooltip, shouldUseNarrowLayout}: TransactionDataCellProps) { const styles = useThemeStyles(); const merchantName = getMerchant(transactionItem); @@ -15,7 +15,7 @@ function MerchantCell({transactionItem, shouldShowTooltip}: TransactionDataCellP ); } diff --git a/src/components/TransactionItemRow/DataCells/TaxCell.tsx b/src/components/TransactionItemRow/DataCells/TaxCell.tsx new file mode 100644 index 000000000000..80e819ea5f0e --- /dev/null +++ b/src/components/TransactionItemRow/DataCells/TaxCell.tsx @@ -0,0 +1,23 @@ +import TextWithTooltip from '@components/TextWithTooltip'; +import useThemeStyles from '@hooks/useThemeStyles'; +import {convertToDisplayString} from '@libs/CurrencyUtils'; +import {getTaxAmount, getCurrency as getTransactionCurrency} from '@libs/TransactionUtils'; +import type TransactionDataCellProps from './TransactionDataCellProps'; + +function TaxCell({transactionItem, shouldShowTooltip}: TransactionDataCellProps) { + const styles = useThemeStyles(); + + const taxAmount = getTaxAmount(transactionItem, true); + const currency = getTransactionCurrency(transactionItem); + + return ( + + ); +} + +TaxCell.displayName = 'TaxCell'; +export default TaxCell; diff --git a/src/components/TransactionItemRow/DataCells/TransactionDataCellProps.ts b/src/components/TransactionItemRow/DataCells/TransactionDataCellProps.ts index df905ea34fc2..05191346ac48 100644 --- a/src/components/TransactionItemRow/DataCells/TransactionDataCellProps.ts +++ b/src/components/TransactionItemRow/DataCells/TransactionDataCellProps.ts @@ -1,7 +1,7 @@ -import type Transaction from '@src/types/onyx/Transaction'; +import type {TransactionWithOptionalSearchFields} from '..'; type TransactionDataCellProps = { - transactionItem: Transaction; + transactionItem: TransactionWithOptionalSearchFields; shouldShowTooltip: boolean; shouldUseNarrowLayout?: boolean; }; diff --git a/src/components/TransactionItemRow/DataCells/TypeCell.tsx b/src/components/TransactionItemRow/DataCells/TypeCell.tsx index dafaf4c3763f..2a9996b7d7a5 100644 --- a/src/components/TransactionItemRow/DataCells/TypeCell.tsx +++ b/src/components/TransactionItemRow/DataCells/TypeCell.tsx @@ -24,6 +24,8 @@ const getTypeIcon = (type?: string) => { switch (type) { case CONST.SEARCH.TRANSACTION_TYPE.CARD: return Expensicons.CreditCard; + case CONST.SEARCH.TRANSACTION_TYPE.DISTANCE: + return Expensicons.Car; case CONST.SEARCH.TRANSACTION_TYPE.CASH: default: return Expensicons.Cash; @@ -32,6 +34,8 @@ const getTypeIcon = (type?: string) => { const getTypeText = (type?: string): TranslationPaths => { switch (type) { + case CONST.SEARCH.TRANSACTION_TYPE.DISTANCE: + return 'common.distance'; case CONST.SEARCH.TRANSACTION_TYPE.CARD: return 'iou.card'; case CONST.SEARCH.TRANSACTION_TYPE.CASH: @@ -43,7 +47,7 @@ const getTypeText = (type?: string): TranslationPaths => { function TypeCell({transactionItem, shouldUseNarrowLayout, shouldShowTooltip}: TransactionDataCellProps) { const {translate} = useLocalize(); const theme = useTheme(); - const type = getType(transactionItem.cardName); + const type = transactionItem.transactionType ?? getType(transactionItem.cardName); const typeIcon = getTypeIcon(type); const typeText = getTypeText(type); const styles = useThemeStyles(); diff --git a/src/components/TransactionItemRow/index.tsx b/src/components/TransactionItemRow/index.tsx index aaca88fbac54..e16ce35eadd9 100644 --- a/src/components/TransactionItemRow/index.tsx +++ b/src/components/TransactionItemRow/index.tsx @@ -1,10 +1,14 @@ import React, {useMemo} from 'react'; import {View} from 'react-native'; +import type {ViewStyle} from 'react-native'; import Animated from 'react-native-reanimated'; +import type {ValueOf} from 'type-fest'; import Checkbox from '@components/Checkbox'; import type {TransactionWithOptionalHighlight} from '@components/MoneyRequestReportView/MoneyRequestReportTransactionList'; import type {TableColumnSize} from '@components/Search/types'; +import ActionCell from '@components/SelectionList/Search/ActionCell'; import DateCell from '@components/SelectionList/Search/DateCell'; +import UserInfoCell from '@components/SelectionList/Search/UserInfoCell'; import Text from '@components/Text'; import useAnimatedHighlightStyle from '@hooks/useAnimatedHighlightStyle'; import useHover from '@hooks/useHover'; @@ -14,15 +18,38 @@ import useThemeStyles from '@hooks/useThemeStyles'; import {getMerchant, getCreated as getTransactionCreated, isPartialMerchant} from '@libs/TransactionUtils'; import variables from '@styles/variables'; import CONST from '@src/CONST'; +import type {SearchPersonalDetails, SearchTransactionAction} from '@src/types/onyx/SearchResults'; import CategoryCell from './DataCells/CategoryCell'; import ChatBubbleCell from './DataCells/ChatBubbleCell'; import MerchantCell from './DataCells/MerchantCell'; import ReceiptCell from './DataCells/ReceiptCell'; import TagCell from './DataCells/TagCell'; +import TaxCell from './DataCells/TaxCell'; import TotalCell from './DataCells/TotalCell'; import TypeCell from './DataCells/TypeCell'; import TransactionItemRowRBR from './TransactionItemRowRBR'; +type ColumnComponents = { + [key in ValueOf]: React.ReactElement; +}; + +type TransactionWithOptionalSearchFields = TransactionWithOptionalHighlight & { + /** The action that can be performed for the transaction */ + action?: SearchTransactionAction; + + /** Function passed to the action button, triggered when the button is pressed */ + onButtonPress?: () => void; + + /** The personal details of the user requesting money */ + from?: SearchPersonalDetails; + + /** The personal details of the user paying the request */ + to?: SearchPersonalDetails; + + /** Type of transaction */ + transactionType?: ValueOf; +}; + function TransactionItemRow({ transactionItem, shouldUseNarrowLayout, @@ -31,14 +58,22 @@ function TransactionItemRow({ dateColumnSize, onCheckboxPress, shouldShowCheckbox = false, + columns, + onButtonPress = () => {}, + isParentHovered, + columnWrapperStyles, }: { - transactionItem: TransactionWithOptionalHighlight; + transactionItem: TransactionWithOptionalSearchFields; shouldUseNarrowLayout: boolean; isSelected: boolean; shouldShowTooltip: boolean; dateColumnSize: TableColumnSize; onCheckboxPress: (transactionID: string) => void; shouldShowCheckbox: boolean; + columns?: Array>; + onButtonPress?: () => void; + isParentHovered?: boolean; + columnWrapperStyles?: ViewStyle[]; }) { const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); @@ -62,14 +97,131 @@ function TransactionItemRow({ return styles.activeComponentBG; } - if (hovered) { + if (hovered || isParentHovered) { return styles.hoveredComponentBG; } - }, [hovered, isSelected, styles.activeComponentBG, styles.hoveredComponentBG]); + }, [hovered, isParentHovered, isSelected, styles.activeComponentBG, styles.hoveredComponentBG]); const merchantName = getMerchant(transactionItem); const isMerchantEmpty = isPartialMerchant(merchantName); + const columnComponent: ColumnComponents = useMemo( + () => ({ + [CONST.REPORT.TRANSACTION_LIST.COLUMNS.TYPE]: ( + + + + ), + [CONST.REPORT.TRANSACTION_LIST.COLUMNS.RECEIPT]: ( + + + + ), + [CONST.REPORT.TRANSACTION_LIST.COLUMNS.TAG]: ( + + + + ), + [CONST.REPORT.TRANSACTION_LIST.COLUMNS.DATE]: ( + + + + ), + [CONST.REPORT.TRANSACTION_LIST.COLUMNS.CATEGORY]: ( + + + + ), + [CONST.REPORT.TRANSACTION_LIST.COLUMNS.ACTION]: ( + + {!!transactionItem.action && ( + + )} + + ), + [CONST.REPORT.TRANSACTION_LIST.COLUMNS.MERCHANT]: ( + + + + ), + [CONST.REPORT.TRANSACTION_LIST.COLUMNS.TO]: ( + + {!!transactionItem.to && ( + + )} + + ), + [CONST.REPORT.TRANSACTION_LIST.COLUMNS.FROM]: ( + + {!!transactionItem.from && ( + + )} + + ), + [CONST.REPORT.TRANSACTION_LIST.COLUMNS.COMMENTS]: ( + + + + ), + [CONST.REPORT.TRANSACTION_LIST.COLUMNS.TOTAL_AMOUNT]: ( + + + + ), + [CONST.REPORT.TRANSACTION_LIST.COLUMNS.TAX]: ( + + + + ), + }), + [StyleUtils, createdAt, isDateColumnWide, isSelected, onButtonPress, shouldShowTooltip, shouldUseNarrowLayout, transactionItem], + ); + const safeColumnWrapperStyle = columnWrapperStyles ?? [styles.p3, styles.expenseWidgetRadius]; return ( ) : ( - + - - - - - - - - - - - - - - - - - - - - - - - - + {columns?.map((column) => columnComponent[column])} @@ -240,3 +342,4 @@ function TransactionItemRow({ TransactionItemRow.displayName = 'TransactionItemRow'; export default TransactionItemRow; +export type {TransactionWithOptionalSearchFields}; diff --git a/src/stories/TransactionItemRow.stories.tsx b/src/stories/TransactionItemRow.stories.tsx index 460d89573776..058936db578f 100644 --- a/src/stories/TransactionItemRow.stories.tsx +++ b/src/stories/TransactionItemRow.stories.tsx @@ -1,32 +1,50 @@ import type {Meta, StoryFn} from '@storybook/react'; import React from 'react'; +import type {ValueOf} from 'type-fest'; import ScreenWrapper from '@components/ScreenWrapper'; import ThemeProvider from '@components/ThemeProvider'; import ThemeStylesProvider from '@components/ThemeStylesProvider'; import TransactionItemRow from '@components/TransactionItemRow'; import CONST from '@src/CONST'; import type Transaction from '@src/types/onyx/Transaction'; -import transaction from './objects/Transaction'; +import {transactionWithOptionalSearchFields} from './objects/Transaction'; type TransactionItemRowStory = StoryFn; +const allAvailableColumns = [ + CONST.REPORT.TRANSACTION_LIST.COLUMNS.RECEIPT, + CONST.REPORT.TRANSACTION_LIST.COLUMNS.TYPE, + CONST.REPORT.TRANSACTION_LIST.COLUMNS.DATE, + CONST.REPORT.TRANSACTION_LIST.COLUMNS.MERCHANT, + CONST.REPORT.TRANSACTION_LIST.COLUMNS.FROM, + CONST.REPORT.TRANSACTION_LIST.COLUMNS.TO, + CONST.REPORT.TRANSACTION_LIST.COLUMNS.MERCHANT, + CONST.REPORT.TRANSACTION_LIST.COLUMNS.CATEGORY, + CONST.REPORT.TRANSACTION_LIST.COLUMNS.TAG, + CONST.REPORT.TRANSACTION_LIST.COLUMNS.TOTAL_AMOUNT, + CONST.REPORT.TRANSACTION_LIST.COLUMNS.ACTION, +]; + type TransactionItemRowProps = { transactionItem: Transaction; shouldUseNarrowLayout: boolean; isSelected: boolean; shouldShowTooltip: boolean; shouldShowCheckbox: boolean; + columns?: Array>; + isParentHovered?: boolean; }; const story: Meta = { title: 'Components/TransactionItemRow', component: TransactionItemRow, args: { - transactionItem: transaction, + transactionItem: transactionWithOptionalSearchFields, shouldUseNarrowLayout: false, isSelected: false, shouldShowTooltip: true, shouldShowCheckbox: true, + columns: allAvailableColumns, }, argTypes: { transactionItem: { @@ -44,6 +62,16 @@ const story: Meta = { shouldShowCheckbox: { control: 'boolean', }, + isParentHovered: { + control: 'boolean', + }, + + columns: { + control: { + type: 'check', + }, + options: allAvailableColumns, + }, }, parameters: { useLightTheme: true, @@ -51,7 +79,7 @@ const story: Meta = { }; function Template( - {transactionItem, shouldUseNarrowLayout, isSelected, shouldShowTooltip, shouldShowCheckbox}: TransactionItemRowProps, + {transactionItem, shouldUseNarrowLayout, isSelected, shouldShowTooltip, shouldShowCheckbox, columns, isParentHovered}: TransactionItemRowProps, {parameters}: {parameters: {useLightTheme?: boolean}}, ) { const theme = parameters.useLightTheme ? CONST.THEME.LIGHT : CONST.THEME.DARK; @@ -68,6 +96,9 @@ function Template( dateColumnSize={CONST.SEARCH.TABLE_COLUMN_SIZES.NORMAL} onCheckboxPress={() => {}} shouldShowCheckbox={shouldShowCheckbox} + columns={columns} + isParentHovered={isParentHovered} + onButtonPress={() => {}} /> diff --git a/src/stories/objects/Transaction.ts b/src/stories/objects/Transaction.ts index 177b97eed1bc..ffc3d71a4f5f 100644 --- a/src/stories/objects/Transaction.ts +++ b/src/stories/objects/Transaction.ts @@ -1,3 +1,5 @@ +import type {TransactionWithOptionalSearchFields} from '@components/TransactionItemRow'; +import CONST from '@src/CONST'; import type Transaction from '@src/types/onyx/Transaction'; const transaction: Transaction & {mcc: string; modifiedMCC: string} = { @@ -36,4 +38,22 @@ const transaction: Transaction & {mcc: string; modifiedMCC: string} = { transactionID: '1564303948126109676', }; +const transactionWithOptionalSearchFields: TransactionWithOptionalSearchFields = { + ...transaction, + from: { + accountID: 1, + avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/avatar_7.png', + displayName: 'johnDoe@example.com User', + login: 'johnDoe@example.com', + }, + to: { + accountID: 1, + avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/avatar_7.png', + displayName: 'johnDoe@example.com User', + login: 'johnDoe@example.com', + }, + action: CONST.SEARCH.ACTION_TYPES.VIEW, +}; + export default transaction; +export {transactionWithOptionalSearchFields};