Skip to content

Commit c55e519

Browse files
authored
feat: add datetime picker for start field in TaskDialog (#349)
1 parent b1411a6 commit c55e519

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

backend/controllers/edit_task.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ func EditTaskHandler(w http.ResponseWriter, r *http.Request) {
6767
return
6868
}
6969

70+
start, err = utils.ConvertISOToTaskwarriorFormat(start)
71+
if err != nil {
72+
http.Error(w, fmt.Sprintf("Invalid start date format: %v", err), http.StatusBadRequest)
73+
return
74+
}
75+
7076
logStore := models.GetLogStore()
7177
job := Job{
7278
Name: "Edit Task",

frontend/src/components/HomeComponents/Tasks/TaskDialog.tsx

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { EditTaskDialogProps } from '../../utils/types';
22
import { Badge } from '@/components/ui/badge';
33
import { Button } from '@/components/ui/button';
44
import { DatePicker } from '@/components/ui/date-picker';
5+
import { DateTimePicker } from '@/components/ui/date-time-picker';
56
import {
67
Dialog,
78
DialogClose,
@@ -350,7 +351,7 @@ export const TaskDialog = ({
350351
<TableCell>
351352
{editState.isEditingStartDate ? (
352353
<div className="flex items-center gap-2">
353-
<DatePicker
354+
<DateTimePicker
354355
date={
355356
editState.editedStartDate &&
356357
editState.editedStartDate !== ''
@@ -359,13 +360,10 @@ export const TaskDialog = ({
359360
// Handle YYYY-MM-DD format
360361
const dateStr =
361362
editState.editedStartDate.includes('T')
362-
? editState.editedStartDate.split(
363-
'T'
364-
)[0]
365-
: editState.editedStartDate;
366-
const parsed = new Date(
367-
dateStr + 'T00:00:00'
368-
);
363+
? editState.editedStartDate
364+
: editState.editedStartDate +
365+
'T00:00:00';
366+
const parsed = new Date(dateStr);
369367
return isNaN(parsed.getTime())
370368
? undefined
371369
: parsed;
@@ -375,13 +373,16 @@ export const TaskDialog = ({
375373
})()
376374
: undefined
377375
}
378-
onDateChange={(date) =>
376+
onDateTimeChange={(date, hasTime) =>
379377
onUpdateState({
380378
editedStartDate: date
381-
? format(date, 'yyyy-MM-dd')
379+
? hasTime
380+
? date.toISOString()
381+
: format(date, 'yyyy-MM-dd')
382382
: '',
383383
})
384384
}
385+
placeholder="Select start date and time"
385386
/>
386387

387388
<Button
@@ -420,11 +421,7 @@ export const TaskDialog = ({
420421
onClick={() => {
421422
onUpdateState({
422423
isEditingStartDate: true,
423-
editedStartDate: task.start
424-
? task.start.includes('T')
425-
? task.start.split('T')[0]
426-
: task.start
427-
: '',
424+
editedStartDate: task.start || '',
428425
});
429426
}}
430427
>

frontend/src/components/HomeComponents/Tasks/__tests__/Tasks.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,7 @@ describe('Tasks Component', () => {
11051105
['Wait', 'Wait:', 'Pick a date'],
11061106
['End', 'End:', 'Select end date'],
11071107
['Due', 'Due:', 'Select due date'],
1108-
['Start', 'Start:', 'Pick a date'],
1108+
['Start', 'Start:', 'Select start date and time'],
11091109
['Entry', 'Entry:', 'Pick a date'],
11101110
])('shows red when task %s date is edited', async (_, label, placeholder) => {
11111111
render(<Tasks {...mockProps} />);
@@ -1135,7 +1135,7 @@ describe('Tasks Component', () => {
11351135
});
11361136

11371137
const dialog = screen.getByRole('dialog');
1138-
const day15 = within(dialog).getByText('15');
1138+
const day15 = within(dialog).getAllByText('15')[0];
11391139
fireEvent.click(day15);
11401140

11411141
const saveButton = screen.getByLabelText('save');

0 commit comments

Comments
 (0)