-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathTaskPreview.js
102 lines (89 loc) · 3.8 KB
/
TaskPreview.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
import React from 'react';
import {View, Pressable} from 'react-native';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import compose from '../../libs/compose';
import styles from '../../styles/styles';
import ONYXKEYS from '../../ONYXKEYS';
import withLocalize, {withLocalizePropTypes} from '../withLocalize';
import Icon from '../Icon';
import CONST from '../../CONST';
import * as Expensicons from '../Icon/Expensicons';
import Text from '../Text';
import Checkbox from '../Checkbox';
import * as StyleUtils from '../../styles/StyleUtils';
import getButtonState from '../../libs/getButtonState';
import Navigation from '../../libs/Navigation/Navigation';
import ROUTES from '../../ROUTES';
import reportActionPropTypes from '../../pages/home/report/reportActionPropTypes';
import * as TaskUtils from '../../libs/actions/Task';
const propTypes = {
/** The ID of the associated taskReport */
taskReportID: PropTypes.string.isRequired,
/** Whether the task preview is hovered so we can modify its style */
isHovered: PropTypes.bool,
/** The linked reportAction */
action: PropTypes.shape(reportActionPropTypes).isRequired,
/* Onyx Props */
taskReport: PropTypes.shape({
/** Title of the task */
reportName: PropTypes.string,
/** Email address of the manager in this iou report */
managerEmail: PropTypes.string,
/** Email address of the creator of this iou report */
ownerEmail: PropTypes.string,
}),
...withLocalizePropTypes,
};
const defaultProps = {
taskReport: {},
isHovered: false,
};
const TaskPreview = (props) => {
// The reportAction might not contain details regarding the taskReport
// Only the direct parent reportAction will contain details about the taskReport
// Other linked reportActions will only contain the taskReportID and we will grab the details from there
const isTaskCompleted =
(props.taskReport.stateNum === CONST.REPORT.STATE_NUM.SUBMITTED && props.taskReport.statusNum === CONST.REPORT.STATUS.APPROVED) ||
(props.action.childStateNum === CONST.REPORT.STATE_NUM.SUBMITTED && props.action.childStatusNum === CONST.REPORT.STATUS.APPROVED);
const taskTitle = props.action.taskTitle || props.taskReport.reportName;
const parentReportID = props.action.parentReportID || props.taskReport.parentReportID;
return (
<Pressable
onPress={() => Navigation.navigate(ROUTES.getReportRoute(props.taskReportID))}
style={[styles.flexRow, styles.justifyContentBetween]}
>
<View style={[styles.flex1, styles.flexRow, styles.alignItemsCenter]}>
<Checkbox
style={[styles.mr2]}
containerStyle={[styles.taskCheckbox]}
isChecked={isTaskCompleted}
disabled={TaskUtils.isTaskCanceled(props.taskReport)}
onPress={() => {
if (isTaskCompleted) {
TaskUtils.reopenTask(props.taskReportID, parentReportID, taskTitle);
} else {
TaskUtils.completeTask(props.taskReportID, parentReportID, taskTitle);
}
}}
/>
<Text>{taskTitle}</Text>
</View>
<Icon
src={Expensicons.ArrowRight}
fill={StyleUtils.getIconFillColor(getButtonState(props.isHovered))}
/>
</Pressable>
);
};
TaskPreview.propTypes = propTypes;
TaskPreview.defaultProps = defaultProps;
TaskPreview.displayName = 'TaskPreview';
export default compose(
withLocalize,
withOnyx({
taskReport: {
key: ({taskReportID}) => `${ONYXKEYS.COLLECTION.REPORT}${taskReportID}`,
},
}),
)(TaskPreview);