From a245b253a4b3b0dec9c22046ab6aa764f5059797 Mon Sep 17 00:00:00 2001 From: Mateusz Titz Date: Tue, 7 May 2024 10:34:13 +0200 Subject: [PATCH 01/16] Add handling of actions to TransactionListItem --- .../Search/TransactionListItemRow.tsx | 65 ++++++++++++++++--- src/libs/SearchUtils.ts | 29 ++++++++- src/libs/actions/Search.ts | 23 ++++++- src/types/onyx/SearchResults.ts | 5 +- 4 files changed, 109 insertions(+), 13 deletions(-) diff --git a/src/components/SelectionList/Search/TransactionListItemRow.tsx b/src/components/SelectionList/Search/TransactionListItemRow.tsx index c0fff452d1e5..0a51adf0e6df 100644 --- a/src/components/SelectionList/Search/TransactionListItemRow.tsx +++ b/src/components/SelectionList/Search/TransactionListItemRow.tsx @@ -1,6 +1,7 @@ import React from 'react'; import type {StyleProp, ViewStyle} from 'react-native'; import {View} from 'react-native'; +import Badge from '@components/Badge'; import Button from '@components/Button'; import Icon from '@components/Icon'; import * as Expensicons from '@components/Icon/Expensicons'; @@ -14,11 +15,13 @@ import useThemeStyles from '@hooks/useThemeStyles'; import useWindowDimensions from '@hooks/useWindowDimensions'; import * as CurrencyUtils from '@libs/CurrencyUtils'; import DateUtils from '@libs/DateUtils'; +import * as SearchUtils from '@libs/SearchUtils'; import * as TransactionUtils from '@libs/TransactionUtils'; import tryResolveUrlFromApiRoot from '@libs/tryResolveUrlFromApiRoot'; import variables from '@styles/variables'; import CONST from '@src/CONST'; -import type {SearchTransactionType} from '@src/types/onyx/SearchResults'; +import type {TranslationPaths} from '@src/languages/types'; +import type {SearchTransactionAction, SearchTransactionType} from '@src/types/onyx/SearchResults'; import ExpenseItemHeaderNarrow from './ExpenseItemHeaderNarrow'; import TextWithIconCell from './TextWithIconCell'; import UserInfoCell from './UserInfoCell'; @@ -35,8 +38,8 @@ type TransactionCellProps = { } & CellProps; type ActionCellProps = { - onButtonPress: () => void; -} & CellProps; + goToItem: () => void; +} & TransactionCellProps; type TotalCellProps = { isChildListItem: boolean; @@ -64,6 +67,18 @@ const getTypeIcon = (type?: SearchTransactionType) => { } }; +const actionTranslationsMap: Record = { + view: 'common.view', + // Todo add translation for Review + review: 'common.view', + done: 'common.done', + paid: 'iou.settledExpensify', + approve: 'iou.approve', + pay: 'iou.pay', + submit: 'common.submit', + hold: 'iou.hold', +}; + function ReceiptCell({transactionItem}: TransactionCellProps) { const theme = useTheme(); const styles = useThemeStyles(); @@ -148,17 +163,50 @@ function TypeCell({transactionItem, isLargeScreenWidth}: TransactionCellProps) { ); } -function ActionCell({onButtonPress}: ActionCellProps) { +function ActionCell({transactionItem, goToItem}: ActionCellProps) { const {translate} = useLocalize(); const styles = useThemeStyles(); + const {action, amount} = transactionItem; + + const text = translate(actionTranslationsMap[action]); + + if (['done', 'paid'].includes(action)) { + return ( + + ); + } + + if (['view', 'review'].includes(action)) { + return ( +