Skip to content

Commit c6f9125

Browse files
authored
add menu items to overview (#108)
1 parent 7e45da8 commit c6f9125

File tree

3 files changed

+71
-12
lines changed

3 files changed

+71
-12
lines changed

src/views/Modals/Inputs/DateModal.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import moment from 'moment'
44
import React from 'react'
55

66
interface DateModalProps {
7-
current: Date | null
87
title: string
98

109
onClose: (newDate: Date | null) => void
@@ -21,13 +20,14 @@ export class DateModal extends React.Component<DateModalProps, DateModalState> {
2120
super(props)
2221

2322
this.state = {
24-
date: props.current,
23+
date: null,
2524
isOpen: false,
2625
}
2726
}
2827

29-
public open = async (): Promise<void> => {
28+
public open = async (current: Date | null): Promise<void> => {
3029
await this.setState({
30+
date: current,
3131
isOpen: true,
3232
})
3333

@@ -53,7 +53,7 @@ export class DateModal extends React.Component<DateModalProps, DateModalState> {
5353
public render(): React.ReactNode {
5454
const { title } = this.props
5555
const { isOpen } = this.state
56-
const date = moment(this.state.date).format('yyyy-MM-DD')
56+
const date = moment(this.state.date).format('yyyy-MM-DD[T]HH:mm')
5757

5858
return (
5959
<Modal
@@ -64,7 +64,7 @@ export class DateModal extends React.Component<DateModalProps, DateModalState> {
6464
<Typography>{title}</Typography>
6565
<Input
6666
sx={{ mt: 3 }}
67-
type='date'
67+
type='datetime-local'
6868
value={date}
6969
onChange={this.onDateChange}
7070
ref={this.inputRef}

src/views/Tasks/TaskCard.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export class TaskCard extends React.Component<TaskCardProps, TaskCardState> {
134134

135135
private onChangeDueDate = () => {
136136
this.dismissMoreMenu()
137-
this.dateModalRef.current?.open()
137+
this.dateModalRef.current?.open(this.props.task.next_due_date)
138138
}
139139

140140
private hasAnyNotificationsActive = () => {
@@ -362,7 +362,6 @@ export class TaskCard extends React.Component<TaskCardProps, TaskCardState> {
362362
<DateModal
363363
key={'changeDueDate' + task.id}
364364
ref={this.dateModalRef}
365-
current={task.next_due_date}
366365
title={`Change due date`}
367366
onClose={this.handleChangeDueDate}
368367
/>

src/views/Tasks/TasksOverview.tsx

+65-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { GetTasks, MarkTaskComplete, UpdateDueDate } from '@/api/tasks'
1+
import { DeleteTask, GetTasks, MarkTaskComplete, UpdateDueDate } from '@/api/tasks'
22
import { Task, getDueDateChipColor, getDueDateChipText } from '@/models/task'
33
import {
44
CancelRounded,
55
SearchRounded,
66
CheckBox,
77
Edit,
88
History,
9+
CalendarMonth,
10+
Delete,
911
} from '@mui/icons-material'
1012
import {
1113
Container,
@@ -25,6 +27,7 @@ import { setTitle } from '@/utils/dom'
2527
import { getTextColorFromBackgroundColor } from '@/utils/colors'
2628
import { sortTasksByDueDate } from '@/utils/tasks'
2729
import { Loading } from '@/Loading'
30+
import { ConfirmationModal } from '../Modals/Inputs/ConfirmationModal'
2831

2932
type TasksOverviewProps = object & WithNavigate
3033

@@ -41,6 +44,8 @@ export class TasksOverview extends React.Component<
4144
TasksOverviewState
4245
> {
4346
private dateModalRef = React.createRef<DateModal>()
47+
private confirmationModalRef = React.createRef<ConfirmationModal>()
48+
private taskBeingDeleted: Task | null = null
4449

4550
constructor(props: TasksOverviewProps) {
4651
super(props)
@@ -139,7 +144,39 @@ export class TasksOverview extends React.Component<
139144
await this.setState({
140145
taskId: task.id,
141146
})
142-
this.dateModalRef.current?.open()
147+
this.dateModalRef.current?.open(task.next_due_date)
148+
}
149+
150+
private onViewHistory = (task: Task) => {
151+
const { navigate } = this.props
152+
navigate(NavigationPaths.TaskHistory(task.id))
153+
}
154+
155+
private onDeleteTask = async (task: Task) => {
156+
this.taskBeingDeleted = task
157+
this.confirmationModalRef.current?.open()
158+
}
159+
160+
private onDeleteConfirm = async (isConfirmed: boolean) => {
161+
const task = this.taskBeingDeleted
162+
this.taskBeingDeleted = null
163+
164+
if (!isConfirmed) {
165+
return
166+
}
167+
168+
const { tasks } = this.state
169+
if (!task) {
170+
throw new Error('Task to delete is not set')
171+
}
172+
173+
await DeleteTask(task.id)
174+
const newTasks = tasks.filter(t => t.id !== task.id)
175+
176+
this.setState({
177+
tasks: newTasks,
178+
filteredTasks: newTasks,
179+
})
143180
}
144181

145182
render(): React.ReactNode {
@@ -204,9 +241,9 @@ export class TasksOverview extends React.Component<
204241
<thead>
205242
<tr>
206243
<th>Due</th>
207-
<th>Task</th>
244+
<th>Title</th>
208245
<th>Labels</th>
209-
<th>Action</th>
246+
<th>Actions</th>
210247
</tr>
211248
</thead>
212249
<tbody>
@@ -261,6 +298,14 @@ export class TasksOverview extends React.Component<
261298
size='sm'
262299
onClick={() => this.onReschedule(task)}
263300
aria-setsize={2}
301+
>
302+
<CalendarMonth />
303+
</IconButton>
304+
<IconButton
305+
variant='outlined'
306+
size='sm'
307+
onClick={() => this.onViewHistory(task)}
308+
aria-setsize={2}
264309
>
265310
<History />
266311
</IconButton>
@@ -271,6 +316,14 @@ export class TasksOverview extends React.Component<
271316
>
272317
<Edit />
273318
</IconButton>
319+
<IconButton
320+
variant='outlined'
321+
size='sm'
322+
onClick={() => this.onDeleteTask(task)}
323+
aria-setsize={2}
324+
>
325+
<Delete />
326+
</IconButton>
274327
</ButtonGroup>
275328
</td>
276329
</tr>
@@ -280,10 +333,17 @@ export class TasksOverview extends React.Component<
280333
<DateModal
281334
ref={this.dateModalRef}
282335
key={taskId}
283-
current={null}
284336
title={`Change due date`}
285337
onClose={this.handleChangeDueDate}
286338
/>
339+
<ConfirmationModal
340+
ref={this.confirmationModalRef}
341+
title='Delete Task'
342+
confirmText='Delete'
343+
cancelText='Cancel'
344+
message='Are you sure you want to delete this task?'
345+
onClose={this.onDeleteConfirm}
346+
/>
287347
</Container>
288348
)
289349
}

0 commit comments

Comments
 (0)