-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathPromotedActionsBar.tsx
130 lines (116 loc) · 4.98 KB
/
PromotedActionsBar.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
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
import React from 'react';
import type {StyleProp, ViewStyle} from 'react-native';
import {View} from 'react-native';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import * as HeaderUtils from '@libs/HeaderUtils';
import * as Localize from '@libs/Localize';
import getTopmostCentralPaneRoute from '@libs/Navigation/getTopmostCentralPaneRoute';
import Navigation, {navigationRef} from '@libs/Navigation/Navigation';
import type {AuthScreensParamList, RootStackParamList, State} from '@libs/Navigation/types';
import * as ReportUtils from '@libs/ReportUtils';
import * as ReportActions from '@userActions/Report';
import * as Session from '@userActions/Session';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
import SCREENS from '@src/SCREENS';
import type {ReportAction} from '@src/types/onyx';
import type OnyxReport from '@src/types/onyx/Report';
import Button from './Button';
import type {ThreeDotsMenuItem} from './HeaderWithBackButton/types';
import * as Expensicons from './Icon/Expensicons';
type PromotedAction = {
key: string;
} & ThreeDotsMenuItem;
type BasePromotedActions = typeof CONST.PROMOTED_ACTIONS.PIN | typeof CONST.PROMOTED_ACTIONS.SHARE | typeof CONST.PROMOTED_ACTIONS.JOIN;
type PromotedActionsType = Record<BasePromotedActions, (report: OnyxReport) => PromotedAction> & {
message: (params: {accountID?: number; login?: string}) => PromotedAction;
} & {
hold: (params: {isTextHold: boolean; reportAction: ReportAction | undefined}) => PromotedAction;
};
const PromotedActions = {
pin: (report) => ({
key: CONST.PROMOTED_ACTIONS.PIN,
...HeaderUtils.getPinMenuItem(report),
}),
share: (report) => ({
key: CONST.PROMOTED_ACTIONS.SHARE,
...HeaderUtils.getShareMenuItem(report),
}),
join: (report) => ({
key: CONST.PROMOTED_ACTIONS.JOIN,
icon: Expensicons.ChatBubbles,
text: Localize.translateLocal('common.join'),
onSelected: Session.checkIfActionIsAllowed(() => {
Navigation.dismissModal();
ReportActions.joinRoom(report);
}),
}),
message: ({accountID, login}) => ({
key: CONST.PROMOTED_ACTIONS.MESSAGE,
icon: Expensicons.CommentBubbles,
text: Localize.translateLocal('common.message'),
onSelected: () => {
// The accountID might be optimistic, so we should use the login if we have it
if (login) {
ReportActions.navigateToAndOpenReport([login]);
return;
}
if (accountID) {
ReportActions.navigateToAndOpenReportWithAccountIDs([accountID]);
}
},
}),
hold: ({isTextHold, reportAction}) => ({
key: CONST.PROMOTED_ACTIONS.HOLD,
icon: Expensicons.Stopwatch,
text: Localize.translateLocal(`iou.${isTextHold ? 'hold' : 'unhold'}`),
onSelected: () => {
if (!isTextHold) {
Navigation.goBack();
}
const topmostCentralPaneRoute = getTopmostCentralPaneRoute(navigationRef.getRootState() as State<RootStackParamList>);
if (topmostCentralPaneRoute?.name !== SCREENS.SEARCH.CENTRAL_PANE && isTextHold) {
ReportUtils.changeMoneyRequestHoldStatus(reportAction, ROUTES.REPORT_WITH_ID.getRoute(reportAction?.childReportID ?? ''));
return;
}
const currentQuery = topmostCentralPaneRoute?.params as AuthScreensParamList['Search_Central_Pane'];
ReportUtils.changeMoneyRequestHoldStatus(reportAction, ROUTES.SEARCH_REPORT.getRoute(currentQuery?.query ?? CONST.SEARCH.TAB.ALL, reportAction?.childReportID ?? ''));
},
}),
} satisfies PromotedActionsType;
type PromotedActionsBarProps = {
/** The list of actions to show */
promotedActions: PromotedAction[];
/** The style of the container */
containerStyle?: StyleProp<ViewStyle>;
};
function PromotedActionsBar({promotedActions, containerStyle}: PromotedActionsBarProps) {
const theme = useTheme();
const styles = useThemeStyles();
if (promotedActions.length === 0) {
return null;
}
return (
<View style={[styles.flexRow, styles.ph5, styles.mb5, styles.gap2, styles.mw100, styles.w100, styles.justifyContentCenter, containerStyle]}>
{promotedActions.map(({key, onSelected, ...props}) => (
<View
style={[styles.flex1, styles.mw50]}
key={key}
>
<Button
onPress={onSelected}
iconFill={theme.icon}
medium
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
/>
</View>
))}
</View>
);
}
PromotedActionsBar.displayName = 'PromotedActionsBar';
export default PromotedActionsBar;
export {PromotedActions};
export type {PromotedActionsBarProps, PromotedAction};