-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Expand file tree
/
Copy pathCardListItemHeader.tsx
More file actions
197 lines (183 loc) · 8.3 KB
/
CardListItemHeader.tsx
File metadata and controls
197 lines (183 loc) · 8.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import React from 'react';
import {View} from 'react-native';
import Checkbox from '@components/Checkbox';
import ReportActionAvatars from '@components/ReportActionAvatars';
import type {SearchColumnType} from '@components/Search/types';
import type {ListItem} from '@components/SelectionList/types';
import TextWithTooltip from '@components/TextWithTooltip';
import UserDetailsTooltip from '@components/UserDetailsTooltip';
import useLocalize from '@hooks/useLocalize';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import {getDisplayNameOrDefault} from '@libs/PersonalDetailsUtils';
import CONST from '@src/CONST';
import type {CompanyCardFeed} from '@src/types/onyx/CardFeeds';
import ExpandCollapseArrowButton from './ExpandCollapseArrowButton';
import TextCell from './TextCell';
import TotalCell from './TotalCell';
import type {TransactionCardGroupListItemType} from './types';
type CardListItemHeaderProps<TItem extends ListItem> = {
/** The card currently being looked at */
card: TransactionCardGroupListItemType;
/** Callback to fire when a checkbox is pressed */
onCheckboxPress?: (item: TItem) => void;
/** Whether this section items disabled for selection */
isDisabled?: boolean | null;
/** Whether the item is focused */
isFocused?: boolean;
/** Whether selecting multiple transactions at once is allowed */
canSelectMultiple: boolean | undefined;
/** Whether all transactions are selected */
isSelectAllChecked?: boolean;
/** Whether only some transactions are selected */
isIndeterminate?: boolean;
/** Callback for when the down arrow is clicked */
onDownArrowClick?: () => void;
/** Whether the down arrow is expanded */
isExpanded?: boolean;
/** The visible columns for the header */
columns?: SearchColumnType[];
};
function CardListItemHeader<TItem extends ListItem>({
card: cardItem,
onCheckboxPress,
isDisabled,
isFocused,
canSelectMultiple,
isSelectAllChecked,
isIndeterminate,
onDownArrowClick,
columns,
isExpanded,
}: CardListItemHeaderProps<TItem>) {
const theme = useTheme();
const styles = useThemeStyles();
const {isLargeScreenWidth} = useResponsiveLayout();
const StyleUtils = useStyleUtils();
const {translate, formatPhoneNumber} = useLocalize();
const formattedDisplayName = formatPhoneNumber(getDisplayNameOrDefault(cardItem));
const backgroundColor =
StyleUtils.getItemBackgroundColorStyle(!!cardItem.isSelected, !!isFocused, !!isDisabled, theme.activeComponentBG, theme.hoverComponentBG)?.backgroundColor ?? theme.cardBG;
const columnComponents = {
[CONST.SEARCH.TABLE_COLUMNS.AVATAR]: (
<View
key={CONST.SEARCH.TABLE_COLUMNS.AVATAR}
style={StyleUtils.getReportTableColumnStyles(CONST.SEARCH.TABLE_COLUMNS.AVATAR)}
>
<UserDetailsTooltip accountID={cardItem.accountID}>
<View>
<ReportActionAvatars
subscriptCardFeed={cardItem.bank as CompanyCardFeed}
subscriptAvatarBorderColor={backgroundColor}
noRightMarginOnSubscriptContainer
accountIDs={[cardItem.accountID]}
size={CONST.AVATAR_SIZE.SMALL}
/>
</View>
</UserDetailsTooltip>
</View>
),
[CONST.SEARCH.TABLE_COLUMNS.GROUP_CARD]: (
<View
key={CONST.SEARCH.TABLE_COLUMNS.GROUP_CARD}
style={StyleUtils.getReportTableColumnStyles(CONST.SEARCH.TABLE_COLUMNS.CARD)}
>
<View style={[styles.gapHalf, styles.flexShrink1]}>
<TextWithTooltip
text={cardItem.formattedCardName ?? ''}
numberOfLines={2}
style={[styles.preWrap]}
/>
</View>
</View>
),
[CONST.SEARCH.TABLE_COLUMNS.GROUP_FEED]: (
<View
key={CONST.SEARCH.TABLE_COLUMNS.GROUP_FEED}
style={StyleUtils.getReportTableColumnStyles(CONST.SEARCH.TABLE_COLUMNS.FEED)}
>
<TextWithTooltip
text={cardItem.formattedFeedName ?? ''}
numberOfLines={2}
style={[styles.lineHeightLarge, styles.preWrap]}
/>
</View>
),
[CONST.SEARCH.TABLE_COLUMNS.GROUP_EXPENSES]: (
<View
key={CONST.SEARCH.TABLE_COLUMNS.GROUP_EXPENSES}
style={StyleUtils.getReportTableColumnStyles(CONST.SEARCH.TABLE_COLUMNS.EXPENSES)}
>
<TextCell text={String(cardItem.count)} />
</View>
),
[CONST.SEARCH.TABLE_COLUMNS.GROUP_TOTAL]: (
<View
key={CONST.SEARCH.TABLE_COLUMNS.GROUP_TOTAL}
style={StyleUtils.getReportTableColumnStyles(CONST.SEARCH.TABLE_COLUMNS.TOTAL, {shouldRemoveTotalColumnFlex: true})}
>
<TotalCell
total={cardItem.total}
currency={cardItem.currency}
/>
</View>
),
};
return (
<View>
<View style={[styles.flexRow, styles.alignItemsCenter, isLargeScreenWidth ? [styles.pl3, styles.pv1, styles.gap3] : [styles.p4, styles.gap3]]}>
<View style={[styles.flexRow, styles.alignItemsCenter, styles.mnh40, styles.flex1, styles.gap3]}>
{!!canSelectMultiple && (
<Checkbox
onPress={() => onCheckboxPress?.(cardItem as unknown as TItem)}
isChecked={isSelectAllChecked}
isIndeterminate={isIndeterminate}
disabled={!!isDisabled || cardItem.isDisabledCheckbox}
accessibilityLabel={translate('common.select')}
containerStyle={styles.m0}
/>
)}
{!isLargeScreenWidth && (
<View style={[styles.flexRow, styles.flex1, styles.gap3]}>
<ReportActionAvatars
subscriptCardFeed={cardItem.bank as CompanyCardFeed}
subscriptAvatarBorderColor={backgroundColor}
noRightMarginOnSubscriptContainer
accountIDs={[cardItem.accountID]}
/>
<View style={[styles.gap1, styles.flexShrink1]}>
<TextWithTooltip
text={formattedDisplayName}
style={[styles.optionDisplayName, styles.sidebarLinkTextBold, styles.pre, styles.fontWeightNormal]}
/>
<TextWithTooltip
text={cardItem.formattedCardName ?? ''}
numberOfLines={2}
style={[styles.textLabelSupporting, styles.lh16, styles.preWrap]}
/>
</View>
</View>
)}
{isLargeScreenWidth && columns?.map((column) => columnComponents[column as keyof typeof columnComponents])}
</View>
{!isLargeScreenWidth && (
<View style={[styles.flexShrink0, styles.flexRow, styles.alignItemsCenter]}>
<TotalCell
total={cardItem.total}
currency={cardItem.currency}
/>
{!!onDownArrowClick && (
<ExpandCollapseArrowButton
isExpanded={isExpanded}
onPress={onDownArrowClick}
/>
)}
</View>
)}
</View>
</View>
);
}
export default CardListItemHeader;