Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

feat(web): redesign subtasks UI with bulk actions

Andrej9b059f394439
diff --git a/apps/web/src/components/kanban-board/task-card-context-menu/task-card-context-menu-content.tsx b/apps/web/src/components/kanban-board/task-card-context-menu/task-card-context-menu-content.tsx
index 80a49dceb..6370912bc 100644
--- a/apps/web/src/components/kanban-board/task-card-context-menu/task-card-context-menu-content.tsx
+++ b/apps/web/src/components/kanban-board/task-card-context-menu/task-card-context-menu-content.tsx
@@ -18,6 +18,7 @@ import { useUpdateTaskDueDate } from "@/hooks/mutations/task/use-update-task-due
import { useUpdateTaskStatus } from "@/hooks/mutations/task/use-update-task-status";
import { useUpdateTaskPriority } from "@/hooks/mutations/task/use-update-task-status-priority";
import { useUpdateTaskTitle } from "@/hooks/mutations/task/use-update-task-title";
+import { useGetColumns } from "@/hooks/queries/column/use-get-columns";
import { useGetActiveWorkspaceUsers } from "@/hooks/queries/workspace-users/use-get-active-workspace-users";
import { getColumnIcon } from "@/lib/column";
import { generateLink } from "@/lib/generate-link";
@@ -43,6 +44,19 @@ export default function TaskCardContextMenuContent({
onDeleteClick,
}: TaskCardContextMenuContentProps) {
const { project } = useProjectStore();
+ const { data: columnsData = [] } = useGetColumns(taskCardContext.projectId);
+ const columns =
+ project?.columns && project.columns.length > 0
+ ? project.columns.map((col) => ({
+ slug: col.id,
+ name: col.name,
+ isFinal: col.isFinal,
+ }))
+ : columnsData.map((col) => ({
+ slug: col.slug,
+ name: col.name,
+ isFinal: col.isFinal,
+ }));
const { data: workspaceUsers } = useGetActiveWorkspaceUsers(
taskCardContext.worskpaceId,
);
@@ -124,6 +138,7 @@ export default function TaskCardContextMenuContent({
key="no-priority"
checked={task.priority === "no-priority"}
onCheckedChange={() => handleChange("priority", "no-priority")}
+ closeOnClick
className="[&_svg]:text-muted-foreground"
>
{getPriorityIcon("no-priority")}
@@ -134,6 +149,7 @@ export default function TaskCardContextMenuContent({
key={priority}
checked={task.priority === priority}
onCheckedChange={() => handleChange("priority", priority)}
+ closeOnClick
className="[&_svg]:text-muted-foreground"
>
{getPriorityIcon(priority)}
@@ -148,14 +164,15 @@ export default function TaskCardContextMenuContent({
<span>Status</span>
</ContextMenuSubTrigger>
<ContextMenuSubContent className="w-48">
- {(project?.columns ?? []).map((col) => (
+ {columns.map((col) => (
<ContextMenuCheckboxItem
- key={col.id}
- checked={task.status === col.id}
- onCheckedChange={() => handleChange("status", col.id)}
+ key={col.slug}
+ checked={task.status === col.slug}
+ onCheckedChange={() => handleChange("status", col.slug)}
+ closeOnClick
className="[&_svg]:text-muted-foreground"
>
- {getColumnIcon(col.id, col.isFinal)}
+ {getColumnIcon(col.slug, col.isFinal)}
<span>{col.name}</span>
</ContextMenuCheckboxItem>
))}
@@ -227,6 +244,7 @@ export default function TaskCardContextMenuContent({
<ContextMenuCheckboxItem
checked={!task.userId}
onCheckedChange={() => handleChange("userId", "")}
+ closeOnClick
>
<div
className="w-6 h-6 rounded-full bg-muted border border-border flex items-center justify-center"
@@ -243,6 +261,7 @@ export default function TaskCardContextMenuContent({
key={user.value}
checked={task.userId === user.value}
onCheckedChange={() => handleChange("userId", user.value ?? "")}
+ closeOnClick
>
<Avatar className="h-6 w-6">
<AvatarImage src={user.image ?? ""} alt={user.name || ""} />
diff --git a/apps/web/src/components/task/subtask-assignee-popover.tsx b/apps/web/src/components/task/subtask-assignee-popover.tsx
new file mode 100644
index 000000000..27a5f1126
--- /dev/null
+++ b/apps/web/src/components/task/subtask-assignee-popover.tsx
@@ -0,0 +1,130 @@
+import { Check } from "lucide-react";
+import { useCallback, useMemo, useState } from "react";
+import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
+import { Button } from "@/components/ui/button";
+import {
+ Popover,
+ PopoverContent,
+ PopoverTrigger,
+} from "@/components/ui/popover";
+import { ShortcutNumber } from "@/components/ui/shortcut-number";
+import { useUpdateTaskAssignee } from "@/hooks/mutations/task/use-update-task-assignee";
+import { useGetActiveWorkspaceUsers } from "@/hooks/queries/workspace-users/use-get-active-workspace-users";
+import { useNumberedShortcuts } from "@/hooks/use-numbered-shortcuts";
+import { toast } from "@/lib/toast";
+import type Task from "@/types/task";
+
+type SubtaskAssigneePopoverProps = {
+ tasks: Task[];
+ workspaceId: string;
+ children: React.ReactNode;
+};
+
+export default function SubtaskAssigneePopover({
+ tasks,
+ workspaceId,
+ children,
+}: SubtaskAssigneePopoverProps) {
+ const [open, setOpen] = useState(false);
+ const { mutateAsync: updateTaskAssignee } = useUpdateTaskAssignee();
+ const { data: workspaceUsers } = useGetActiveWorkspaceUsers(workspaceId);
+
+ const usersOptions = useMemo(() => {
+ return workspaceUsers?.members?.map((member) => ({
+ label: member?.user?.name ?? member.userId,
+ value: member.userId,
+ image: member?.user?.image ?? "",
+ name: member?.user?.name ?? "",
+ }));
+ }, [workspaceUsers]);
+
+ const allSameAssignee =
+ tasks.length > 0 && tasks.every((t) => t.userId === tasks[0].userId);
+ const currentAssignee = allSameAssignee ? tasks[0].userId : null;
+
+ const handleAssigneeChange = useCallback(
+ async (newUserId: string) => {
+ try {
+ await Promise.all(
+ tasks.map((task) =>
+ updateTaskAssignee({
+ ...task,
+ userId: newUserId,
+ }),
+ ),
+ );
+ setOpen(false);
+ } catch (error) {
+ toast.error(
+ error instanceof Error
+ ? error.message
+ : "Failed to update task assignee",
+ );
+ }
+ },
+ [tasks, updateTaskAssignee],
+ );
+
+ const shortcutOptions = useMemo(() => {
+ const unassignedOption = { onSelect: () => handleAssigneeChange("") };
+ const userOptions = (usersOptions || []).slice(0, 8).map((user) => ({
+ onSelect: () => handleAssigneeChange(user.value),
+ }));
+ return [unassignedOption, ...userOptions];
+ }, [usersOptions, handleAssigneeChange]);
+
+ useNumberedShortcuts(open, shortcutOptions);
+
+ return (
+ <Popover open={open} onOpenChange={setOpen} modal={false}>
+ <PopoverTrigger asChild>{children}</PopoverTrigger>
+ <PopoverContent className="w-48 p-0" align="start">
+ <div className="space-y-1 p-1">
+ <Button
+ variant="ghost"
+ size="sm"
+ className="w-full justify-start gap-2 h-8 px-2"
+ onClick={() => handleAssigneeChange("")}
+ >
+ <div
+ className="w-6 h-6 rounded-full bg-muted border border-border flex items-center justify-center"
+ title="Unassigned"
+ >
+ <span className="text-[10px] font-medium text-muted-foreground">
+ ?
+ </span>
+ </div>
+ <span className="text-sm">Unassigned</span>
+ {allSameAssignee && !currentAssignee ? (
+ <Check className="ml-auto h-4 w-4" />
+ ) : (
+ <ShortcutNumber number={1} />
+ )}
+ </Button>
+ {usersOptions?.slice(0, 8).map((user, index) => (
+ <Button
+ key={user.value}
+ variant="ghost"
+ size="sm"
+ className="w-full justify-start gap-2 h-8 px-2"
+ onClick={() => handleAssigneeChange(user.value)}
+ >
+ <Avatar className="h-6 w-6">
+ <AvatarImage src={user.image ?? ""} alt={user.name || ""} />
+ <AvatarFallback className="text-xs font-medium border border-border/30">
+ {user.name?.charAt(0).toUpperCase()}
+ </AvatarFallback>
+ </Avatar>
+ <span className="text-sm truncate">{user.label}</span>
+ {currentAssignee === user.value ? (
+ <Check className="ml-auto h-4 w-4 shrink-0" />
+ ) : (
+ <ShortcutNumber number={index + 2} />
+ )}
+ </Button>
+ ))}
+ </div>
+ </PopoverContent>
+ </Popover>
+ );
+}
diff --git a/apps/web/src/components/task/subtask-row.tsx b/apps/web/src/components/task/subtask-row.tsx
new file mode 100644
index 000000000..9fa685186
--- /dev/null
+++ b/apps/web/src/components/task/subtask-row.tsx
@@ -0,0 +1,106 @@
+import TaskCardContextMenuContent from "@/components/kanban-board/task-card-context-menu/task-card-context-menu-content";
+import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
+import { Checkbox } from "@/components/ui/checkbox";
+import { ContextMenu, ContextMenuTrigger } from "@/components/ui/context-menu";
+import { getColumnIcon } from "@/lib/column";
+import type Task from "@/types/task";
+import SubtaskAssigneePopover from "./subtask-assignee-popover";
+import SubtaskStatusPopover from "./subtask-status-popover";
+
+type SubtaskRowProps = {
+ task: Task;
+ tasks: Task[];
+ projectId: string;
+ workspaceId: string;
+ isSelected: boolean;
+ selectionRadius: string;
+ assignee: {
+ user?: { image?: string | null; name?: string | null } | null;
+ } | null;
+ onToggleSelection: () => void;
+ onNavigate: () => void;
+ onDeleteClick: () => void;
+};
+
+export default function SubtaskRow({
+ task,
+ tasks,
+ projectId,
+ workspaceId,
+ isSelected,
+ selectionRadius,
+ assignee,
+ onToggleSelection,
+ onNavigate,
+ onDeleteClick,
+}: SubtaskRowProps) {
+ return (
+ <ContextMenu>
+ <ContextMenuTrigger asChild>
+ <div
+ className={`group flex items-center gap-2 py-1 px-2 ${selectionRadius} transition-colors cursor-default ${isSelected ? "bg-primary/10 hover:bg-primary/15" : "hover:bg-accent/50"}`}
+ >
+ <Checkbox checked={isSelected} onCheckedChange={onToggleSelection} />
+
+ <SubtaskStatusPopover tasks={tasks} projectId={projectId}>
+ <button
+ type="button"
+ className="shrink-0 flex items-center justify-center rounded p-0.5 transition-colors outline-none [&_svg]:text-muted-foreground hover:[&_svg]:text-foreground"
+ >
+ {getColumnIcon(task.status, false)}
+ </button>
+ </SubtaskStatusPopover>
+
+ <button
+ type="button"
+ className="flex-1 min-w-0 text-left outline-none"
+ onClick={onNavigate}
+ >
+ <span
+ className={`text-sm truncate block ${task.status === "done" ? "line-through text-muted-foreground" : "text-foreground/90"}`}
+ >
+ {task.title}
+ </span>
+ </button>
+
+ <SubtaskAssigneePopover tasks={tasks} workspaceId={workspaceId}>
+ <button
+ type="button"
+ className="shrink-0 flex items-center justify-center rounded p-0.5 transition-colors outline-none"
+ >
+ {task.userId && assignee ? (
+ <Avatar className="h-5 w-5">
+ <AvatarImage
+ src={assignee?.user?.image ?? ""}
+ alt={assignee?.user?.name || ""}
+ />
+ <AvatarFallback className="text-[9px] font-medium border border-border/30">
+ {assignee?.user?.name?.charAt(0).toUpperCase()}
+ </AvatarFallback>
+ </Avatar>
+ ) : (
+ <div
+ className="flex h-5 w-5 items-center justify-center rounded-full border border-dashed border-border/70"
+ title="Unassigned"
+ >
+ <span className="text-[9px] font-medium text-muted-foreground">
+ ?
+ </span>
+ </div>
+ )}
+ </button>
+ </SubtaskAssigneePopover>
+ </div>
+ </ContextMenuTrigger>
+
+ <TaskCardContextMenuContent
+ task={task}
+ taskCardContext={{
+ projectId,
+ worskpaceId: workspaceId,
+ }}
+ onDeleteClick={onDeleteClick}
+ />
+ </ContextMenu>
+ );
+}
diff --git a/apps/web/src/components/task/subtask-status-popover.tsx b/apps/web/src/components/task/subtask-status-popover.tsx
new file mode 100644
index 000000000..836a357b9
--- /dev/null
+++ b/apps/web/src/components/task/subtask-status-popover.tsx
@@ -0,0 +1,100 @@
+import { Check } from "lucide-react";
+import { useCallback, useMemo, useState } from "react";
+import { Button } from "@/components/ui/button";
+import {
+ Popover,
+ PopoverContent,
+ PopoverTrigger,
+} from "@/components/ui/popover";
+import { ShortcutNumber } from "@/components/ui/shortcut-number";
+import { useUpdateTaskStatus } from "@/hooks/mutations/task/use-update-task-status";
+import { useGetColumns } from "@/hooks/queries/column/use-get-columns";
+import { useNumberedShortcuts } from "@/hooks/use-numbered-shortcuts";
+import { getColumnIcon } from "@/lib/column";
+import { toast } from "@/lib/toast";
+import type Task from "@/types/task";
+
+type SubtaskStatusPopoverProps = {
+ tasks: Task[];
+ projectId: string;
+ children: React.ReactNode;
+};
+
+export default function SubtaskStatusPopover({
+ tasks,
+ projectId,
+ children,
+}: SubtaskStatusPopoverProps) {
+ const [open, setOpen] = useState(false);
+ const { data: columns = [] } = useGetColumns(projectId);
+ const statusOptions = columns.map((col) => ({
+ value: col.slug,
+ label: col.name,
+ isFinal: col.isFinal,
+ }));
+ const { mutateAsync: updateTaskStatus } = useUpdateTaskStatus();
+
+ const allSameStatus =
+ tasks.length > 0 && tasks.every((t) => t.status === tasks[0].status);
+ const currentStatus = allSameStatus ? tasks[0].status : null;
+
+ const handleStatusChange = useCallback(
+ async (newStatus: string) => {
+ try {
+ await Promise.all(
+ tasks.map((task) =>
+ updateTaskStatus({
+ ...task,
+ status: newStatus,
+ }),
+ ),
+ );
+ setOpen(false);
+ } catch (error) {
+ toast.error(
+ error instanceof Error
+ ? error.message
+ : "Failed to update task status",
+ );
+ }
+ },
+ [tasks, updateTaskStatus],
+ );
+
+ const shortcutOptions = useMemo(
+ () =>
+ statusOptions.map((status) => ({
+ onSelect: () => handleStatusChange(status.value),
+ })),
+ [handleStatusChange, statusOptions],
+ );
+
+ useNumberedShortcuts(open, shortcutOptions);
+
+ return (
+ <Popover open={open} onOpenChange={setOpen} modal={false}>
+ <PopoverTrigger asChild>{children}</PopoverTrigger>
+ <PopoverContent className="w-48 p-0" align="start">
+ <div>
+ {statusOptions.map((status, index) => (
+ <Button
+ key={status.value}
+ variant="ghost"
+ size="sm"
+ className="w-full justify-start gap-2 h-8 px-2 rounded-none first:rounded-t-md last:rounded-b-md"
+ onClick={() => handleStatusChange(status.value)}
+ >
+ {getColumnIcon(status.value, status.isFinal)}
+ <span className="text-sm">{status.label}</span>
+ {currentStatus === status.value ? (
+ <Check className="ml-auto h-4 w-4" />
+ ) : (
+ <ShortcutNumber number={index + 1} />
+ )}
+ </Button>
+ ))}
+ </div>
+ </PopoverContent>
+ </Popover>
+ );
+}
diff --git a/apps/web/src/components/task/task-details-content.tsx b/apps/web/src/components/task/task-details-content.tsx
index c7f3dd87c..245e711bc 100644
--- a/apps/web/src/components/task/task-details-content.tsx
+++ b/apps/web/src/components/task/task-details-content.tsx
@@ -1,3 +1,5 @@
+import { useNavigate } from "@tanstack/react-router";
+import { ArrowUpRight } from "lucide-react";
import Activity from "@/components/activity";
import CommentInput from "@/components/activity/comment-input";
import { isCommentActivity } from "@/components/activity/utils";
@@ -8,9 +10,9 @@ import useGetActivitiesByTaskId from "@/hooks/queries/activity/use-get-activitie
import useExternalLinks from "@/hooks/queries/external-link/use-external-links";
import useGetProject from "@/hooks/queries/project/use-get-project";
import useGetTask from "@/hooks/queries/task/use-get-task";
+import useGetTaskRelations from "@/hooks/queries/task-relation/use-get-task-relations";
import type { ExternalLink } from "@/types/external-link";
import TaskDescription from "./task-description";
-import TaskRelations from "./task-relations";
import TaskSubtasks from "./task-subtasks";
import TaskTitle from "./task-title";
@@ -27,18 +29,46 @@ export default function TaskDetailsContent({
workspaceId,
className,
}: TaskDetailsContentProps) {
+ const navigate = useNavigate();
const { data: task } = useGetTask(taskId ?? "");
const { data: project } = useGetProject({ id: projectId, workspaceId });
const { data: activities = [] } = useGetActivitiesByTaskId(taskId ?? "");
const { data: externalLinks = [], isLoading: isLoadingExternalLinks } =
useExternalLinks(taskId ?? "");
+ const { data: relations = [] } = useGetTaskRelations(taskId ?? "");
const { user } = useAuth();
+ const parentRelation = relations.find(
+ (rel) => rel.relationType === "subtask" && rel.targetTaskId === taskId,
+ );
+ const parentTask = parentRelation?.sourceTask;
+
if (!taskId) return null;
return (
<div className={`${className} gap-4`}>
<div className="flex flex-col gap-2.5">
+ {parentTask && (
+ <button
+ type="button"
+ className="flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors w-fit"
+ onClick={() =>
+ navigate({
+ to: "/dashboard/workspace/$workspaceId/project/$projectId/task/$taskId",
+ params: {
+ workspaceId,
+ projectId,
+ taskId: parentTask.id,
+ },
+ })
+ }
+ >
+ <ArrowUpRight className="size-3" />
+ <span>
+ Subtask of <span className="font-medium">{parentTask.title}</span>
+ </span>
+ </button>
+ )}
<p className="text-xs font-semibold text-foreground/70">
{project?.slug}-{task?.number}
</p>
@@ -60,13 +90,6 @@ export default function TaskDetailsContent({
workspaceId={workspaceId}
/>
</div>
- <div className="mt-2">
- <TaskRelations
- taskId={taskId}
- projectId={projectId}
- workspaceId={workspaceId}
- />
- </div>
<span className="text-sm font-medium text-muted-foreground h-[1px] bg-border w-full block shrink-0" />
<div className="flex flex-col gap-4">
<h1 className="text-md font-semibold">Activity</h1>
diff --git a/apps/web/src/components/task/task-subtasks.tsx b/apps/web/src/components/task/task-subtasks.tsx
index 4137d632d..c2744a797 100644
--- a/apps/web/src/components/task/task-subtasks.tsx
+++ b/apps/web/src/components/task/task-subtasks.tsx
@@ -1,8 +1,17 @@
import { useNavigate } from "@tanstack/react-router";
-import { ChevronDown, ChevronRight, ListTree, Plus, X } from "lucide-react";
+import { ChevronDown, ChevronRight, Plus } from "lucide-react";
import { useState } from "react";
+import {
+ AlertDialog,
+ AlertDialogClose,
+ AlertDialogContent,
+ AlertDialogDescription,
+ AlertDialogFooter,
+ AlertDialogHeader,
+ AlertDialogTitle,
+} from "@/components/ui/alert-dialog";
import { Button } from "@/components/ui/button";
-import { Checkbox } from "@/components/ui/checkbox";
+import CircularProgress from "@/components/ui/circular-progress";
import {
Collapsible,
CollapsibleContent,
@@ -10,13 +19,15 @@ import {
} from "@/components/ui/collapsible";
import { Input } from "@/components/ui/input";
import useCreateTask from "@/hooks/mutations/task/use-create-task";
-import { useUpdateTaskStatus } from "@/hooks/mutations/task/use-update-task-status";
+import { useDeleteTask } from "@/hooks/mutations/task/use-delete-task";
import useCreateTaskRelation from "@/hooks/mutations/task-relation/use-create-task-relation";
-import useDeleteTaskRelation from "@/hooks/mutations/task-relation/use-delete-task-relation";
import useGetTaskRelations from "@/hooks/queries/task-relation/use-get-task-relations";
-import { getColumnIcon } from "@/lib/column";
-import { getPriorityIcon } from "@/lib/priority";
+import useActiveWorkspace from "@/hooks/queries/workspace/use-active-workspace";
+import { useGetActiveWorkspaceUsers } from "@/hooks/queries/workspace-users/use-get-active-workspace-users";
import { toast } from "@/lib/toast";
+import queryClient from "@/query-client";
+import type Task from "@/types/task";
+import SubtaskRow from "./subtask-row";
type TaskSubtasksProps = {
taskId: string;
@@ -33,12 +44,17 @@ export default function TaskSubtasks({
const [isOpen, setIsOpen] = useState(true);
const [isAdding, setIsAdding] = useState(false);
const [newTitle, setNewTitle] = useState("");
+ const [deleteTaskId, setDeleteTaskId] = useState<string | null>(null);
+ const [selectedIds, setSelectedIds] = useState<Set<string>>(new Set());
const { data: relations = [] } = useGetTaskRelations(taskId);
+ const { data: workspace } = useActiveWorkspace();
+ const { data: workspaceUsers } = useGetActiveWorkspaceUsers(
+ workspace?.id ?? "",
+ );
const createTask = useCreateTask();
const createRelation = useCreateTaskRelation();
- const deleteRelation = useDeleteTaskRelation(taskId);
- const updateStatus = useUpdateTaskStatus();
+ const { mutateAsync: deleteTask } = useDeleteTask();
const subtasks = relations
.filter(
@@ -54,8 +70,64 @@ export default function TaskSubtasks({
(s) => s.task.status === "done",
).length;
const totalCount = subtasks.length;
- const progressPercent =
- totalCount > 0 ? (completedCount / totalCount) * 100 : 0;
+ const hasSelection = selectedIds.size > 0;
+
+ const toggleSelection = (id: string) => {
+ setSelectedIds((prev) => {
+ const next = new Set(prev);
+ if (next.has(id)) {
+ next.delete(id);
+ } else {
+ next.add(id);
+ }
+ return next;
+ });
+ };
+
+ const buildTaskObject = (subtask: (typeof subtasks)[number]): Task => ({
+ id: subtask.task.id,
+ title: subtask.task.title,
+ number: subtask.task.number,
+ description: null,
+ status: subtask.task.status,
+ priority: subtask.task.priority,
+ dueDate: null,
+ position: null,
+ createdAt: "",
+ userId: subtask.task.userId,
+ assigneeId: subtask.task.userId,
+ assigneeName: subtask.task.assigneeName,
+ projectId: subtask.task.projectId,
+ });
+
+ const getTargetTasks = (currentTask: Task): Task[] => {
+ if (hasSelection && selectedIds.has(currentTask.id)) {
+ return subtasks
+ .filter((s) => selectedIds.has(s.task.id))
+ .map(buildTaskObject);
+ }
+ return [currentTask];
+ };
+
+ const getAssignee = (userId: string | null) => {
+ if (!userId || !workspaceUsers?.members) return null;
+ return workspaceUsers.members.find((member) => member.userId === userId);
+ };
+
+ const getSelectionRadius = (index: number, isSelected: boolean) => {
+ if (!isSelected) return "rounded-md";
+
+ const prevSelected =
+ index > 0 && selectedIds.has(subtasks[index - 1].task.id);
+ const nextSelected =
+ index < subtasks.length - 1 &&
+ selectedIds.has(subtasks[index + 1].task.id);
+
+ if (prevSelected && nextSelected) return "rounded-none";
+ if (prevSelected) return "rounded-t-none rounded-b-md";
+ if (nextSelected) return "rounded-t-md rounded-b-none";
+ return "rounded-md";
+ };
const handleAddSubtask = async () => {
if (!newTitle.trim()) return;
@@ -82,179 +154,172 @@ export default function TaskSubtasks({
}
};
- const handleToggleStatus = (subtask: {
- relation: { id: string };
- task: {
- id: string;
- status: string;
- projectId: string;
- title: string;
- number: number | null;
- priority: string | null;
- userId: string | null;
- assigneeName: string | null;
- };
- }) => {
- const newStatus = subtask.task.status === "done" ? "to-do" : "done";
- updateStatus.mutate({
- id: subtask.task.id,
- status: newStatus,
- projectId: subtask.task.projectId,
- title: subtask.task.title,
- number: subtask.task.number,
- description: null,
- priority: subtask.task.priority,
- dueDate: null,
- position: null,
- createdAt: "",
- userId: subtask.task.userId,
- assigneeId: subtask.task.userId,
- assigneeName: subtask.task.assigneeName,
- });
- };
-
- const handleRemoveSubtask = (relationId: string) => {
- deleteRelation.mutate(relationId);
- };
-
- const handleNavigateToTask = (subtaskId: string) => {
- navigate({
- to: "/dashboard/workspace/$workspaceId/project/$projectId/task/$taskId",
- params: { workspaceId, projectId, taskId: subtaskId },
- });
+ const handleDeleteTask = async () => {
+ if (!deleteTaskId) return;
+ try {
+ await deleteTask(deleteTaskId);
+ queryClient.invalidateQueries({ queryKey: ["tasks", projectId] });
+ queryClient.invalidateQueries({ queryKey: ["task-relations", taskId] });
+ setSelectedIds((prev) => {
+ const next = new Set(prev);
+ next.delete(deleteTaskId);
+ return next;
+ });
+ toast.success("Task deleted successfully");
+ } catch (error) {
+ toast.error(
+ error instanceof Error ? error.message : "Failed to delete task",
+ );
+ } finally {
+ setDeleteTaskId(null);
+ }
};
return (
- <Collapsible open={isOpen} onOpenChange={setIsOpen} className="w-full">
- <div className="flex items-center justify-between">
- <CollapsibleTrigger asChild>
- <Button
- variant="ghost"
- size="sm"
- className="w-full justify-start gap-1 px-0 h-8 hover:bg-transparent"
- >
- {isOpen ? (
- <ChevronDown className="size-4 text-muted-foreground" />
- ) : (
- <ChevronRight className="size-4 text-muted-foreground" />
- )}
- <ListTree className="size-4 text-muted-foreground" />
- <span className="text-sm text-muted-foreground">Subtasks</span>
+ <>
+ <Collapsible open={isOpen} onOpenChange={setIsOpen} className="w-full">
+ <div className="flex items-center justify-between">
+ <div className="flex items-center gap-1.5">
+ <CollapsibleTrigger asChild>
+ <button
+ type="button"
+ className="flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground transition-colors"
+ >
+ {isOpen ? (
+ <ChevronDown className="size-4" />
+ ) : (
+ <ChevronRight className="size-4" />
+ )}
+ <span>Sub-tasks</span>
+ </button>
+ </CollapsibleTrigger>
{totalCount > 0 && (
- <span className="text-xs text-muted-foreground ml-1">
- {completedCount}/{totalCount}
+ <span className="flex items-center gap-1.5 ml-0.5">
+ <CircularProgress
+ completed={completedCount}
+ total={totalCount}
+ />
+ <span className="text-xs text-muted-foreground">
+ {completedCount}/{totalCount}
+ </span>
</span>
)}
+ </div>
+ <Button
+ variant="ghost"
+ size="xs"
+ className="text-muted-foreground"
+ onClick={() => setIsAdding(true)}
+ >
+ <Plus className="size-3.5" />
</Button>
- </CollapsibleTrigger>
- <Button
- variant="ghost"
- size="xs"
- className="text-muted-foreground"
- onClick={() => setIsAdding(true)}
- >
- <Plus className="size-3.5" />
- </Button>
- </div>
+ </div>
- <CollapsibleContent>
- {totalCount > 0 && (
- <div className="mt-2 mb-2">
- <div className="h-1.5 w-full rounded-full bg-input overflow-hidden">
- <div
- className="h-full bg-primary transition-all duration-300"
- style={{ width: `${progressPercent}%` }}
- />
- </div>
+ <CollapsibleContent>
+ <div className="flex flex-col mt-1">
+ {subtasks.map((subtask, index) => {
+ const taskObj = buildTaskObject(subtask);
+ const isSelected = selectedIds.has(subtask.task.id);
+
+ return (
+ <SubtaskRow
+ key={subtask.relation.id}
+ task={taskObj}
+ tasks={getTargetTasks(taskObj)}
+ projectId={projectId}
+ workspaceId={workspace?.id ?? workspaceId}
+ isSelected={isSelected}
+ selectionRadius={getSelectionRadius(index, isSelected)}
+ assignee={getAssignee(subtask.task.userId)}
+ onToggleSelection={() => toggleSelection(subtask.task.id)}
+ onNavigate={() =>
+ navigate({
+ to: "/dashboard/workspace/$workspaceId/project/$projectId/task/$taskId",
+ params: {
+ workspaceId,
+ projectId,
+ taskId: subtask.task.id,
+ },
+ })
+ }
+ onDeleteClick={() => setDeleteTaskId(subtask.task.id)}
+ />
+ );
+ })}
</div>
- )}
- <div className="flex flex-col gap-1 mt-1">
- {subtasks.map((subtask) => (
- <div
- key={subtask.relation.id}
- className="group flex items-center gap-2 py-1.5 px-2 rounded-md hover:bg-accent/50 transition-colors"
- >
- <Checkbox
- checked={subtask.task.status === "done"}
- onCheckedChange={() => handleToggleStatus(subtask)}
+ {isAdding && (
+ <div className="flex items-center gap-2 mt-2">
+ <Input
+ size="sm"
+ placeholder="Subtask title..."
+ value={newTitle}
+ onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
+ setNewTitle(e.target.value)
+ }
+ onKeyDown={(e: React.KeyboardEvent<HTMLInputElement>) => {
+ if (e.key === "Enter") handleAddSubtask();
+ if (e.key === "Escape") {
+ setIsAdding(false);
+ setNewTitle("");
+ }
+ }}
+ autoFocus
/>
- <button
- type="button"
- className="flex items-center gap-2 flex-1 min-w-0 text-left"
- onClick={() => handleNavigateToTask(subtask.task.id)}
+ <Button
+ size="xs"
+ onClick={handleAddSubtask}
+ disabled={!newTitle.trim() || createTask.isPending}
>
- {getColumnIcon(subtask.task.status, false)}
- <span
- className={`text-sm truncate flex-1 ${subtask.task.status === "done" ? "line-through text-muted-foreground" : "text-foreground/90"}`}
- >
- {subtask.task.title}
- </span>
- {subtask.task.priority &&
- subtask.task.priority !== "no-priority" && (
- <span className="shrink-0">
- {getPriorityIcon(subtask.task.priority)}
- </span>
- )}
- </button>
+ Add
+ </Button>
<Button
variant="ghost"
size="xs"
- className="opacity-0 group-hover:opacity-100 text-muted-foreground h-5 w-5 p-0"
- onClick={() => handleRemoveSubtask(subtask.relation.id)}
+ onClick={() => {
+ setIsAdding(false);
+ setNewTitle("");
+ }}
>
- <X className="size-3" />
+ Cancel
</Button>
</div>
- ))}
- </div>
+ )}
- {isAdding && (
- <div className="flex items-center gap-2 mt-2">
- <Input
- size="sm"
- placeholder="Subtask title..."
- value={newTitle}
- onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
- setNewTitle(e.target.value)
- }
- onKeyDown={(e: React.KeyboardEvent<HTMLInputElement>) => {
- if (e.key === "Enter") {
- handleAddSubtask();
- }
- if (e.key === "Escape") {
- setIsAdding(false);
- setNewTitle("");
- }
- }}
- autoFocus
- />
- <Button
- size="xs"
- onClick={handleAddSubtask}
- disabled={!newTitle.trim() || createTask.isPending}
- >
- Add
- </Button>
- <Button
- variant="ghost"
- size="xs"
- onClick={() => {
- setIsAdding(false);
- setNewTitle("");
- }}
- >
- Cancel
- </Button>
- </div>
- )}
+ {!isAdding && totalCount === 0 && (
+ <p className="text-xs text-muted-foreground px-2 py-1">
+ No subtasks yet
+ </p>
+ )}
+ </CollapsibleContent>
+ </Collapsible>
- {!isAdding && totalCount === 0 && (
- <p className="text-xs text-muted-foreground px-2 py-1">
- No subtasks yet
- </p>
- )}
- </CollapsibleContent>
- </Collapsible>
+ <AlertDialog
+ open={!!deleteTaskId}
+ onOpenChange={(open) => !open && setDeleteTaskId(null)}
+ >
+ <AlertDialogContent>
+ <AlertDialogHeader>
+ <AlertDialogTitle>Delete Task?</AlertDialogTitle>
+ <AlertDialogDescription>
+ This will permanently remove the task and all its data. You can't
+ undo this action.
+ </AlertDialogDescription>
+ </AlertDialogHeader>
+ <AlertDialogFooter>
+ <AlertDialogClose>
+ <Button variant="outline" size="sm">
+ Cancel
+ </Button>
+ </AlertDialogClose>
+ <AlertDialogClose onClick={handleDeleteTask}>
+ <Button variant="destructive" size="sm">
+ Delete Task
+ </Button>
+ </AlertDialogClose>
+ </AlertDialogFooter>
+ </AlertDialogContent>
+ </AlertDialog>
+ </>
);
}
diff --git a/apps/web/src/components/ui/circular-progress.tsx b/apps/web/src/components/ui/circular-progress.tsx
new file mode 100644
index 000000000..0c1738c05
--- /dev/null
+++ b/apps/web/src/components/ui/circular-progress.tsx
@@ -0,0 +1,54 @@
+type CircularProgressProps = {
+ completed: number;
+ total: number;
+ size?: number;
+ strokeWidth?: number;
+};
+
+export default function CircularProgress({
+ completed,
+ total,
+ size = 16,
+ strokeWidth = 2,
+}: CircularProgressProps) {
+ const radius = (size - strokeWidth) / 2;
+ const circumference = 2 * Math.PI * radius;
+ const percent = total > 0 ? completed / total : 0;
+ const offset = circumference * (1 - percent);
+
+ return (
+ <svg
+ width={size}
+ height={size}
+ className="shrink-0 -rotate-90"
+ aria-hidden="true"
+ >
+ <circle
+ cx={size / 2}
+ cy={size / 2}
+ r={radius}
+ fill="none"
+ stroke="currentColor"
+ strokeWidth={strokeWidth}
+ className="text-border"
+ />
+ {total > 0 && (
+ <circle
+ cx={size / 2}
+ cy={size / 2}
+ r={radius}
+ fill="none"
+ stroke="currentColor"
+ strokeWidth={strokeWidth}
+ strokeDasharray={circumference}
+ strokeDashoffset={offset}
+ strokeLinecap="round"
+ className={
+ completed === total ? "text-success-foreground" : "text-primary"
+ }
+ style={{ transition: "stroke-dashoffset 0.4s ease" }}
+ />
+ )}
+ </svg>
+ );
+}
diff --git a/apps/web/src/hooks/mutations/task/use-update-task-assignee.ts b/apps/web/src/hooks/mutations/task/use-update-task-assignee.ts
index d01d3a1e8..baad024f8 100644
--- a/apps/web/src/hooks/mutations/task/use-update-task-assignee.ts
+++ b/apps/web/src/hooks/mutations/task/use-update-task-assignee.ts
@@ -23,6 +23,9 @@ export function useUpdateTaskAssignee() {
queryClient.invalidateQueries({
queryKey: ["activities", variables.id],
});
+ queryClient.invalidateQueries({
+ queryKey: ["task-relations"],
+ });
},
});
}
diff --git a/apps/web/src/hooks/mutations/task/use-update-task-status.ts b/apps/web/src/hooks/mutations/task/use-update-task-status.ts
index 42ba5992a..53ae96631 100644
--- a/apps/web/src/hooks/mutations/task/use-update-task-status.ts
+++ b/apps/web/src/hooks/mutations/task/use-update-task-status.ts
@@ -23,6 +23,9 @@ export function useUpdateTaskStatus() {
queryClient.invalidateQueries({
queryKey: ["activities", variables.id],
});
+ queryClient.invalidateQueries({
+ queryKey: ["task-relations"],
+ });
},
});
}
diff --git a/apps/web/src/lib/column.tsx b/apps/web/src/lib/column.tsx
index ffb63f043..dc20bd35d 100644
--- a/apps/web/src/lib/column.tsx
+++ b/apps/web/src/lib/column.tsx
@@ -1,4 +1,11 @@
-import { CheckCircle2, Circle, CircleDot, Search } from "lucide-react";
+import {
+ Archive,
+ CheckCircle2,
+ Circle,
+ CircleDashed,
+ CircleDot,
+ Search,
+} from "lucide-react";
export const getColumnIcon = (columnId: string, isFinal?: boolean) => {
switch (columnId) {
@@ -10,6 +17,10 @@ export const getColumnIcon = (columnId: string, isFinal?: boolean) => {
return <Search className="w-4 h-4 text-muted-foreground" />;
case "done":
return <CheckCircle2 className="w-4 h-4 text-muted-foreground" />;
+ case "archived":
+ return <Archive className="w-4 h-4 text-muted-foreground" />;
+ case "planned":
+ return <CircleDashed className="w-4 h-4 text-muted-foreground" />;
default:
return isFinal ? (
<CheckCircle2 className="w-4 h-4 text-muted-foreground" />