-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
ActionCell.tsx
97 lines (86 loc) · 3.61 KB
/
ActionCell.tsx
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
import React from 'react';
import {View} from 'react-native';
import Badge from '@components/Badge';
import Button from '@components/Button';
import * as Expensicons from '@components/Icon/Expensicons';
import useLocalize from '@hooks/useLocalize';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import variables from '@styles/variables';
import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
import type {SearchTransactionAction} from '@src/types/onyx/SearchResults';
const actionTranslationsMap: Record<SearchTransactionAction, TranslationPaths> = {
view: 'common.view',
review: 'common.review',
done: 'common.done',
paid: 'iou.settledExpensify',
};
type ActionCellProps = {
action?: SearchTransactionAction;
isLargeScreenWidth?: boolean;
isSelected?: boolean;
goToItem: () => void;
isChildListItem?: boolean;
parentAction?: string;
};
function ActionCell({action = CONST.SEARCH.ACTION_TYPES.VIEW, isLargeScreenWidth = true, isSelected = false, goToItem, isChildListItem = false, parentAction = ''}: ActionCellProps) {
const {translate} = useLocalize();
const theme = useTheme();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const text = translate(actionTranslationsMap[action]);
const shouldUseViewAction = action === CONST.SEARCH.ACTION_TYPES.VIEW || (parentAction === CONST.SEARCH.ACTION_TYPES.PAID && action === CONST.SEARCH.ACTION_TYPES.PAID);
if ((parentAction !== CONST.SEARCH.ACTION_TYPES.PAID && action === CONST.SEARCH.ACTION_TYPES.PAID) || action === CONST.SEARCH.ACTION_TYPES.DONE) {
return (
<View style={[StyleUtils.getHeight(variables.h28), styles.justifyContentCenter]}>
<Badge
text={text}
icon={Expensicons.Checkmark}
badgeStyles={[
styles.ml0,
styles.ph2,
styles.gap1,
isLargeScreenWidth ? styles.alignSelfCenter : styles.alignSelfEnd,
StyleUtils.getHeight(variables.h20),
StyleUtils.getMinimumHeight(variables.h20),
isSelected ? StyleUtils.getBorderColorStyle(theme.buttonHoveredBG) : StyleUtils.getBorderColorStyle(theme.border),
]}
textStyles={StyleUtils.getFontSizeStyle(variables.fontSizeExtraSmall)}
iconStyles={styles.mr0}
success
/>
</View>
);
}
const buttonInnerStyles = isSelected ? styles.buttonDefaultHovered : {};
if (action === CONST.SEARCH.ACTION_TYPES.VIEW || shouldUseViewAction) {
return isLargeScreenWidth ? (
<Button
text={translate(actionTranslationsMap[CONST.SEARCH.ACTION_TYPES.VIEW])}
onPress={goToItem}
small
pressOnEnter
style={[styles.w100]}
innerStyles={buttonInnerStyles}
link={isChildListItem}
shouldUseDefaultHover={!isChildListItem}
/>
) : null;
}
if (action === CONST.SEARCH.ACTION_TYPES.REVIEW) {
return (
<Button
text={text}
onPress={goToItem}
small
pressOnEnter
style={[styles.w100]}
innerStyles={buttonInnerStyles}
/>
);
}
}
ActionCell.displayName = 'ActionCell';
export default ActionCell;