-
-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathSingleTask.jsx
More file actions
298 lines (285 loc) · 11.6 KB
/
SingleTask.jsx
File metadata and controls
298 lines (285 loc) · 11.6 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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
import React, { useState, useEffect } from 'react';
import { connect, useSelector } from 'react-redux';
import ReactTooltip from 'react-tooltip';
import axios from 'axios';
import { NavItem, Button, Modal, ModalBody } from 'reactstrap';
import { Editor } from '@tinymce/tinymce-react';
import { Link, useHistory } from 'react-router-dom';
import { ENDPOINTS } from '~/utils/URL';
import { getUserProfile } from '~/actions/userProfile';
import hasPermission from '~/utils/permissions';
import { boxStyle, boxStyleDark } from '~/styles';
import EditTaskModal from '../WBSDetail/EditTask/EditTaskModal';
import ModalDelete from '../../../common/Modal';
import { deleteTask } from '../../../../actions/task';
import * as Message from '../../../../languages/en/messages';
import { getPopupById } from '../../../../actions/popupEditorAction';
import { TASK_DELETE_POPUP_ID } from '../../../../constants/popupId';
import { formatDate } from '~/utils/formatDate';
const TINY_MCE_INIT_OPTIONS =
{
license_key: 'gpl',
menubar: false,
toolbar: false,
branding: false,
min_height: 80,
max_height: 300,
autoresize_bottom_margin: 1,
};
function SingleTask(props) {
const darkMode = useSelector(state => state.theme.darkMode);
const { taskId } = props.match.params;
const { user } = props.auth;
const [task, setTask] = useState({});
const [modal, setModal] = useState(false);
const [modalDelete, setModalDelete] = useState(false);
const toggleModel = () => setModal(!modal);
const canPostProject = props.hasPermission('postProject');
const canDeleteTask = props.hasPermission('deleteTask');
const history = useHistory();
useEffect(() => {
const fetchTaskData = async () => {
if (!taskId) return;
try {
const res = await axios.get(ENDPOINTS.GET_TASK(taskId));
setTask(res?.data || {});
} catch (error) {
// eslint-disable-next-line no-console
console.log(error);
}
};
fetchTaskData();
}, [taskId]);
const deleteTask = (taskId, taskMother) => {
props.deleteTask(taskId, taskMother);
setTask({});
setModalDelete(false);
history.push('/dashboard');
};
const showUpDeleteModal = () => {
setModalDelete(true);
props.getPopupById(TASK_DELETE_POPUP_ID);
};
return (
<>
<div className={`${darkMode ? 'bg-oxford-blue' : 'bg-white'} h-100`}>
<ReactTooltip />
<div className="container-single-task">
{canPostProject && (
<nav aria-label="breadcrumb">
<ol className={`breadcrumb mx-2 ${darkMode ? 'bg-space-cadet text-light' : ''}`} style={darkMode ? boxStyleDark : boxStyle}>
<NavItem tag={Link} to={`/wbs/samefoldertasks/${taskId}`}>
<Button type="button" className="btn btn-secondary" style={darkMode ? boxStyleDark : boxStyle}>
<i className="fa fa-chevron-circle-left" aria-hidden="true" />
</Button>
</NavItem>
<div id="single_task_name" className='ml-2'>
See tasks in the same folder as "
{task.taskName}
"
</div>
</ol>
</nav>
)}
<div className='tasks-table table-responsive mb-5'>
<table className={`table table-bordered ${darkMode ? 'dark-mode text-light' : ''}`}>
<thead className={darkMode ? 'bg-space-cadet' : ''}>
<tr>
<th scope="col" data-tip="Action" colSpan="1">
Action
</th>
<th scope="col" data-tip="task-num" colSpan="1">
#
</th>
<th scope="col" data-tip="Task Name" style={{ minWidth: '200px' }}>
Task Name
</th>
<th scope="col" data-tip="Priority">
<i className="fa fa-star" aria-hidden="true" />
</th>
<th scope="col" data-tip="Resources">
<i className="fa fa-users" aria-hidden="true" />
</th>
<th scope="col" data-tip="Assigned">
<i className="fa fa-user-circle-o" aria-hidden="true" />
</th>
<th scope="col" data-tip="Status">
<i className="fa fa-tasks" aria-hidden="true" />
</th>
<th scope="col" data-tip="Hours-Best">
<i className="fa fa-hourglass-start" aria-hidden="true" />
</th>
<th scope="col" data-tip="Hours-Worst">
<i className="fa fa-hourglass" aria-hidden="true" />
</th>
<th scope="col" data-tip="Hours-Most">
<i className="fa fa-hourglass-half" aria-hidden="true" />
</th>
<th scope="col" data-tip="Estimated Hours">
<i className="fa fa-clock-o" aria-hidden="true" />
</th>
<th scope="col" data-tip="Hours-Logged">
<i className="fa fa-hourglass-end" aria-hidden="true" />
</th>
<th scope="col" data-tip="Start Date">
<i className="fa fa-calendar-check-o" aria-hidden="true" />
{' '}
Start
</th>
<th scope="col" data-tip="Due Date">
<i className="fa fa-calendar-times-o" aria-hidden="true" />
{' '}
End
</th>
<th scope="col" data-tip="Links">
<i className="fa fa-link" aria-hidden="true" />
</th>
<th scope="col" data-tip="Details">
<i className="fa fa-question" aria-hidden="true" />
</th>
</tr>
</thead>
<tbody className={darkMode ? 'bg-yinmn-blue' : ''}>
<tr>
<th scope="row">
<div className="d-flex flex-column align-items-start">
<EditTaskModal
key={`editTask_${task._id}`}
parentNum={task.num}
taskId={task._id}
wbsId={task.wbsId}
parentId1={task.parentId1}
parentId2={task.parentId2}
parentId3={task.parentId3}
mother={task.mother}
level={task.level}
setTask={setTask}
/>
{canDeleteTask && (
<>
<Button
type="button"
size="sm"
className="btn btn-danger mt-1 ml-2"
onClick={() => showUpDeleteModal()}
>
Delete
</Button>
<ModalDelete
isOpen={modalDelete}
closeModal={() => setModalDelete(false)}
confirmModal={() => deleteTask(task._id, task.mother)}
modalMessage={
props.popupEditor.currPopup.popupContent || 'DELETE THIS TASK ?'
}
modalTitle={Message.CONFIRM_DELETION}
darkMode={darkMode}
/>
</>
)}
</div>
</th>
<th scope="row">{task.num}</th>
<td>{task.taskName}</td>
<td>{task.priority}</td>
<td>
{task?.resources &&
task.resources.map((elem, i) => {
try {
if (elem.profilePic) {
return (
<a
key={`res_${i}`}
data-tip={elem.name}
className="name"
href={`/userprofile/${elem.userID}`}
target="_blank"
rel="noreferrer"
>
{/* eslint-disable-next-line jsx-a11y/alt-text */}
<img className="img-circle" src={elem.profilePic} />
</a>
);
}
return (
<a
key={`res_${i}`}
data-tip={elem.name}
className="name"
href={`/userprofile/${elem.userID}`}
target="_blank"
rel="noreferrer"
>
<span className="dot">{elem.name.substring(0, 2)}</span>
</a>
);
} catch (err) { }
})}
</td>
<td>
{task.isAssigned ? (
<i data-tip="Assigned" className="fa fa-check-square" aria-hidden="true" />
) : (
<i data-tip="Not Assigned" className="fa fa-square-o" aria-hidden="true" />
)}
</td>
<td>{task.status}</td>
<td>{task.hoursBest}</td>
<td>{task.hoursWorst}</td>
<td>{task.hoursMost}</td>
<td>{parseFloat(task.estimatedHours).toFixed(2)}</td>
<td>{parseFloat(task.hoursLogged).toFixed(2)}</td>
<td>{task.startedDatetime ? formatDate(task.startedDatetime) : 'N/A'}</td>
<td>{task.dueDatetime ? formatDate(task.dueDatetime) : 'N/A'}</td>
<td>
<a href={task.links}>
<i className={`fa fa-link ${darkMode ? 'text-azure' : ''}`} aria-hidden="true" />
</a>
</td>
<td onClick={toggleModel}>
<i className="fa fa-book" aria-hidden="true" />
</td>
</tr>
</tbody>
</table>
</div>
</div>
<Modal isOpen={modal} toggle={toggleModel}>
<ModalBody className={darkMode ? 'bg-yinmn-blue text-light' : ''}>
<h6>WHY THIS TASK IS IMPORTANT:</h6>
<Editor
tinymceScriptSrc="/tinymce/tinymce.min.js"
licenseKey="gpl"
init={TINY_MCE_INIT_OPTIONS}
disabled
value={task.whyInfo}
/>
<h6>THE DESIGN INTENT:</h6>
<Editor
tinymceScriptSrc="/tinymce/tinymce.min.js"
licenseKey="gpl"
init={TINY_MCE_INIT_OPTIONS}
disabled
value={task.intentInfo}
/>
<h6>ENDSTATE:</h6>
<Editor
tinymceScriptSrc="/tinymce/tinymce.min.js"
licenseKey="gpl"
init={TINY_MCE_INIT_OPTIONS}
disabled
value={task.endstateInfo}
/>
</ModalBody>
</Modal>
</div>
</>
);
}
const mapStateToProps = state => state;
export default connect(mapStateToProps, {
getUserProfile,
deleteTask,
getPopupById,
hasPermission,
})(SingleTask);