From c40f8424ffbc00074f91e2393a8d2b645c5ab470 Mon Sep 17 00:00:00 2001 From: Adam Jolicoeur Date: Mon, 12 Oct 2026 09:45:50 -0400 Subject: [PATCH 1/2] feat: allow adding tasks to archived days --- src/components/ArchiveEditDialog.tsx | 260 ++++++++++++++++++++++++++- src/contexts/TimeTrackingContext.tsx | 27 ++- 2 files changed, 285 insertions(+), 2 deletions(-) diff --git a/src/components/ArchiveEditDialog.tsx b/src/components/ArchiveEditDialog.tsx index 0160e60..b268ecc 100644 --- a/src/components/ArchiveEditDialog.tsx +++ b/src/components/ArchiveEditDialog.tsx @@ -34,6 +34,7 @@ import { TooltipTrigger, } from "@/components/ui/tooltip"; import { Button } from "@/components/ui/button"; +import { Label } from "@/components/ui/label"; import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; @@ -56,6 +57,8 @@ import { Edit, AlertTriangle, RotateCcw, + Plus, + X, } from "lucide-react"; import { formatDuration, @@ -119,15 +122,28 @@ export const ArchiveEditDialog: React.FC = ({ categories, projects, isDayStarted, + addTaskToArchivedDay, } = useTimeTracking(); const { toast } = useToast(); const { confirmDelete } = useUndoableDelete(); const [isSummaryEditing, setIsSummaryEditing] = useState(false); const [expandedTaskId, setExpandedTaskId] = useState(null); + const [isAddingTask, setIsAddingTask] = useState(false); const [isSaving, setIsSaving] = useState(false); const [showDeleteConfirm, setShowDeleteConfirm] = useState(false); const [showRestoreDialog, setShowRestoreDialog] = useState(false); + const [newTaskData, setNewTaskData] = useState({ + title: "", + description: "", + project: "none" as string, + category: "none" as string, + }); + const [newTaskTimes, setNewTaskTimes] = useState({ + startTime: "", + endTime: "", + }); + const dayForm = useForm({ resolver: zodResolver(dayFormSchema), mode: "onBlur", @@ -174,6 +190,7 @@ export const ArchiveEditDialog: React.FC = ({ setIsSummaryEditing(false); setExpandedTaskId(null); setShowDeleteConfirm(false); + handleCancelNewTask(); }; // Initialize form data when dialog opens @@ -338,6 +355,53 @@ export const ArchiveEditDialog: React.FC = ({ setExpandedTaskId((cur) => (cur === id ? null : id)); }, []); + const handleAddTask = () => { + const selectedProject = + newTaskData.project !== "none" + ? projects.find((p) => p.id === newTaskData.project) + : undefined; + const selectedCategory = + newTaskData.category !== "none" + ? categories.find((c) => c.id === newTaskData.category) + : undefined; + + const baseDate = day.startTime; + const startTime = parseTimeInput(newTaskTimes.startTime, baseDate); + const endTime = newTaskTimes.endTime + ? parseTimeInput(newTaskTimes.endTime, baseDate) + : undefined; + + const newTask: Task = { + id: crypto.randomUUID(), + title: newTaskData.title.trim(), + description: newTaskData.description.trim() || undefined, + project: selectedProject?.name || undefined, + client: selectedProject?.client || undefined, + category: selectedCategory?.id || undefined, + startTime, + endTime, + duration: endTime + ? endTime.getTime() - startTime.getTime() + : undefined, + }; + + handleCancelNewTask(); + setIsSaving(true); + addTaskToArchivedDay(day.id, newTask) + .catch((error) => { + console.error("Failed to add task to archived day:", error); + }) + .finally(() => { + setIsSaving(false); + }); + }; + + const handleCancelNewTask = () => { + setNewTaskData({ title: "", description: "", project: "none", category: "none" }); + setNewTaskTimes({ startTime: "", endTime: "" }); + setIsAddingTask(false); + }; + const handleCancel = () => { resetFormState(); }; @@ -604,7 +668,30 @@ export const ArchiveEditDialog: React.FC = ({ {/* Tasks Detail */} - Tasks ({tasks.length}) +
+ Tasks ({tasks.length}) + +
@@ -633,6 +720,177 @@ export const ArchiveEditDialog: React.FC = ({ projects={projects} /> ))} + {isAddingTask && ( + + +
+
+ + + setNewTaskData((prev) => ({ ...prev, title: e.target.value })) + } + placeholder="Enter task title" + autoFocus + /> +
+ +
+ + + + Edit + Preview + + +