-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathTaskHeader.js
151 lines (141 loc) · 6.8 KB
/
TaskHeader.js
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
import React, {useEffect} from 'react';
import {View} from 'react-native';
import PropTypes from 'prop-types';
import lodashGet from 'lodash/get';
import {withOnyx} from 'react-native-onyx';
import reportPropTypes from '../pages/reportPropTypes';
import withLocalize, {withLocalizePropTypes} from './withLocalize';
import * as ReportUtils from '../libs/ReportUtils';
import * as Expensicons from './Icon/Expensicons';
import Text from './Text';
import participantPropTypes from './participantPropTypes';
import Avatar from './Avatar';
import styles from '../styles/styles';
import themeColors from '../styles/themes/default';
import CONST from '../CONST';
import withWindowDimensions from './withWindowDimensions';
import compose from '../libs/compose';
import Navigation from '../libs/Navigation/Navigation';
import ROUTES from '../ROUTES';
import Icon from './Icon';
import MenuItemWithTopDescription from './MenuItemWithTopDescription';
import Button from './Button';
import * as TaskUtils from '../libs/actions/Task';
import * as UserUtils from '../libs/UserUtils';
import PressableWithFeedback from './Pressable/PressableWithFeedback';
import ONYXKEYS from '../ONYXKEYS';
const propTypes = {
/** The report currently being looked at */
report: reportPropTypes.isRequired,
/** Personal details so we can get the ones for the report participants */
personalDetails: PropTypes.objectOf(participantPropTypes).isRequired,
/** Current user session */
session: PropTypes.shape({
accountID: PropTypes.number,
}),
...withLocalizePropTypes,
};
const defaultProps = {
session: {
accountID: 0,
},
};
function TaskHeader(props) {
const title = ReportUtils.getReportName(props.report);
const assigneeAccountID = TaskUtils.getTaskAssigneeAccountID(props.report);
const assigneeName = ReportUtils.getDisplayNameForParticipant(assigneeAccountID);
const assigneeAvatar = UserUtils.getAvatar(lodashGet(props.personalDetails, [assigneeAccountID, 'avatar']), assigneeAccountID);
const isOpen = props.report.stateNum === CONST.REPORT.STATE_NUM.OPEN && props.report.statusNum === CONST.REPORT.STATUS.OPEN;
const isCompleted = ReportUtils.isTaskCompleted(props.report);
useEffect(() => {
TaskUtils.setTaskReport(props.report);
}, [props.report]);
return (
<View style={styles.borderBottom}>
<View style={[{backgroundColor: themeColors.highlightBG}, styles.pl0]}>
<View style={[styles.ph5, styles.pb5]}>
<Text style={[styles.textLabelSupporting, styles.lh16]}>{props.translate('common.to')}</Text>
<PressableWithFeedback
onPress={() => Navigation.navigate(ROUTES.getTaskReportAssigneeRoute(props.report.reportID))}
disabled={!isOpen}
accessibilityRole="button"
accessibilityLabel={props.translate('newTaskPage.assignee')}
hoverDimmingValue={1}
pressDimmingValue={0.2}
>
<View style={[styles.flexRow, styles.alignItemsCenter, styles.justifyContentBetween, styles.pv3]}>
<View style={[styles.flexRow, styles.alignItemsCenter, styles.justifyContentBetween]}>
{assigneeAccountID && assigneeAccountID > 0 && (
<>
<Avatar
source={assigneeAvatar}
type={CONST.ICON_TYPE_AVATAR}
name={assigneeName}
size={CONST.AVATAR_SIZE.HEADER}
/>
<View style={[styles.flexColumn, styles.ml3]}>
<Text
style={[styles.headerText, styles.pre]}
numberOfLines={1}
>
{assigneeName}
</Text>
</View>
</>
)}
</View>
<View style={[styles.flexRow]}>
{isCompleted ? (
<>
<Text>{props.translate('task.completed')}</Text>
<View style={styles.defaultCheckmarkWrapper}>
<Icon
src={Expensicons.Checkmark}
fill={themeColors.iconSuccessFill}
/>
</View>
</>
) : (
<Button
success
isDisabled={TaskUtils.isTaskCanceled(props.report) || !TaskUtils.isTaskAssigneeOrTaskOwner(props.report, props.session.accountID)}
medium
text={props.translate('newTaskPage.markAsDone')}
onPress={() => TaskUtils.completeTask(props.report.reportID, title)}
/>
)}
</View>
</View>
</PressableWithFeedback>
</View>
</View>
<MenuItemWithTopDescription
shouldShowHeaderTitle
title={props.report.reportName}
description={props.translate('newTaskPage.task')}
onPress={() => Navigation.navigate(ROUTES.getTaskReportTitleRoute(props.report.reportID))}
disabled={!isOpen}
interactive={isOpen}
/>
<MenuItemWithTopDescription
title={lodashGet(props.report, 'description', '')}
description={props.translate('newTaskPage.description')}
onPress={() => Navigation.navigate(ROUTES.getTaskReportDescriptionRoute(props.report.reportID))}
disabled={!isOpen}
interactive={isOpen}
/>
</View>
);
}
TaskHeader.propTypes = propTypes;
TaskHeader.defaultProps = defaultProps;
TaskHeader.displayName = 'TaskHeader';
export default compose(
withWindowDimensions,
withLocalize,
withOnyx({
session: {
key: ONYXKEYS.SESSION,
},
}),
)(TaskHeader);