Skip to content

Commit 1425be9

Browse files
authored
feat: add datetime picker for entry field in TaskDialog (#358)
1 parent 696da3c commit 1425be9

3 files changed

Lines changed: 22 additions & 24 deletions

File tree

backend/controllers/edit_task.go

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

88+
entry, err = utils.ConvertISOToTaskwarriorFormat(entry)
89+
if err != nil {
90+
http.Error(w, fmt.Sprintf("Invalid entry date format: %v", err), http.StatusBadRequest)
91+
return
92+
}
93+
8894
logStore := models.GetLogStore()
8995
job := Job{
9096
Name: "Edit Task",

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

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,7 @@ export const TaskDialog = ({
11221122
<TableCell>
11231123
{editState.isEditingEntryDate ? (
11241124
<div className="flex items-center gap-2">
1125-
<DatePicker
1125+
<DateTimePicker
11261126
date={
11271127
editState.editedEntryDate &&
11281128
editState.editedEntryDate !== ''
@@ -1131,13 +1131,10 @@ export const TaskDialog = ({
11311131
// Handle YYYY-MM-DD format
11321132
const dateStr =
11331133
editState.editedEntryDate.includes('T')
1134-
? editState.editedEntryDate.split(
1135-
'T'
1136-
)[0]
1137-
: editState.editedEntryDate;
1138-
const parsed = new Date(
1139-
dateStr + 'T00:00:00'
1140-
);
1134+
? editState.editedEntryDate
1135+
: editState.editedEntryDate +
1136+
'T00:00:00';
1137+
const parsed = new Date(dateStr);
11411138
return isNaN(parsed.getTime())
11421139
? undefined
11431140
: parsed;
@@ -1147,13 +1144,16 @@ export const TaskDialog = ({
11471144
})()
11481145
: undefined
11491146
}
1150-
onDateChange={(date) =>
1147+
onDateTimeChange={(date, hasTime) =>
11511148
onUpdateState({
11521149
editedEntryDate: date
1153-
? format(date, 'yyyy-MM-dd')
1150+
? hasTime
1151+
? date.toISOString()
1152+
: format(date, 'yyyy-MM-dd')
11541153
: '',
11551154
})
11561155
}
1156+
placeholder="Select entry date and time"
11571157
/>
11581158

11591159
<Button
@@ -1174,12 +1174,8 @@ export const TaskDialog = ({
11741174
aria-label="cancel"
11751175
onClick={() =>
11761176
onUpdateState({
1177+
editedEntryDate: task.entry || '',
11771178
isEditingEntryDate: false,
1178-
editedEntryDate: task.entry
1179-
? task.entry.includes('T')
1180-
? task.entry.split('T')[0]
1181-
: task.entry
1182-
: '',
11831179
})
11841180
}
11851181
>
@@ -1193,16 +1189,12 @@ export const TaskDialog = ({
11931189
variant="ghost"
11941190
size="icon"
11951191
aria-label="edit"
1196-
onClick={() =>
1192+
onClick={() => {
11971193
onUpdateState({
11981194
isEditingEntryDate: true,
1199-
editedEntryDate: task.entry
1200-
? task.entry.includes('T')
1201-
? task.entry.split('T')[0]
1202-
: task.entry
1203-
: '',
1204-
})
1205-
}
1195+
editedEntryDate: task.entry || '',
1196+
});
1197+
}}
12061198
>
12071199
<PencilIcon className="h-4 w-4 text-gray-500" />
12081200
</Button>

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

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

0 commit comments

Comments
 (0)