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): pick a project in the create-task modal when none is in scope

Andrej7d20a3fc5349
diff --git a/apps/web/src/components/shared/modals/create-task-modal.test.tsx b/apps/web/src/components/shared/modals/create-task-modal.test.tsx
new file mode 100644
index 000000000..90d85fe97
--- /dev/null
+++ b/apps/web/src/components/shared/modals/create-task-modal.test.tsx
@@ -0,0 +1,131 @@
+import { cleanup, fireEvent, render, screen } from "@testing-library/react";
+import { afterEach, describe, expect, it, vi } from "vitest";
+import CreateTaskModal from "./create-task-modal";
+
+const useLocation = vi.fn();
+const createTask = vi.fn(async (input: Record<string, unknown>) => ({
+ id: "task-1",
+ title: input.title,
+ status: input.status,
+ projectId: input.projectId,
+ createdAt: "2026-08-05T00:00:00.000Z",
+}));
+
+afterEach(() => {
+ cleanup();
+ document.body.innerHTML = "";
+ vi.clearAllMocks();
+});
+
+vi.mock("@tanstack/react-router", () => ({
+ useLocation: () => useLocation(),
+}));
+
+vi.mock("@/components/task/task-description-editor", () => ({
+ default: () => <div data-testid="description-editor" />,
+}));
+
+vi.mock("@/hooks/mutations/label/use-create-label", () => ({
+ default: () => ({ mutateAsync: vi.fn() }),
+}));
+
+vi.mock("@/hooks/mutations/task/use-create-task", () => ({
+ default: () => ({ mutateAsync: createTask }),
+}));
+
+vi.mock("@/hooks/mutations/task/use-delete-task", () => ({
+ useDeleteTask: () => ({ mutateAsync: vi.fn() }),
+}));
+
+vi.mock("@/hooks/mutations/task/use-update-task", () => ({
+ useUpdateTask: () => ({ mutateAsync: vi.fn() }),
+}));
+
+vi.mock("@/hooks/queries/label/use-get-labels-by-workspace", () => ({
+ default: () => ({ data: [] }),
+}));
+
+vi.mock("@/hooks/queries/workspace/use-active-workspace", () => ({
+ default: () => ({ data: { id: "workspace-1", name: "WS" } }),
+}));
+
+vi.mock(
+ "@/hooks/queries/workspace-users/use-get-active-workspace-users",
+ () => ({
+ useGetActiveWorkspaceUsers: () => ({ data: { members: [] } }),
+ }),
+);
+
+vi.mock("@/hooks/use-workspace-permission", () => ({
+ useWorkspacePermission: () => ({
+ canCreateTasks: () => true,
+ canManageLabels: () => true,
+ }),
+}));
+
+vi.mock("@/hooks/queries/project/use-get-projects", () => ({
+ default: () => ({
+ data: [
+ { id: "project-1", name: "Alpha", slug: "alp" },
+ { id: "project-2", name: "Beta", slug: "bet" },
+ ],
+ }),
+}));
+
+vi.mock("@/store/project", () => ({
+ default: () => ({ project: null, setProject: vi.fn() }),
+}));
+
+vi.mock("@/lib/toast", () => ({
+ toast: { error: vi.fn(), success: vi.fn() },
+}));
+
+vi.mock("react-i18next", () => ({
+ useTranslation: () => ({ t: (key: string) => key }),
+ initReactI18next: { type: "3rdParty", init: vi.fn() },
+}));
+
+describe("CreateTaskModal project picker", () => {
+ it("shows a project picker and creates the task in the chosen project", async () => {
+ useLocation.mockReturnValue({
+ pathname: "/dashboard/workspace/workspace-1",
+ });
+
+ render(<CreateTaskModal open onClose={vi.fn()} />);
+
+ const pickerTrigger = screen.getByText(
+ "common:modals.createTask.selectProject",
+ );
+ fireEvent.click(pickerTrigger);
+ fireEvent.click(await screen.findByText("Beta"));
+
+ fireEvent.change(
+ screen.getByPlaceholderText(
+ "common:modals.createTask.taskTitlePlaceholder",
+ ),
+ { target: { value: "Picked project task" } },
+ );
+ fireEvent.submit(document.querySelector("form") as HTMLFormElement);
+
+ await vi.waitFor(() => {
+ expect(createTask).toHaveBeenCalledWith(
+ expect.objectContaining({
+ title: "Picked project task",
+ projectId: "project-2",
+ }),
+ );
+ });
+ });
+
+ it("hides the picker when a project is in scope from the route", () => {
+ useLocation.mockReturnValue({
+ pathname: "/dashboard/workspace/workspace-1/project/project-1/board",
+ });
+
+ render(<CreateTaskModal open onClose={vi.fn()} />);
+
+ expect(
+ screen.queryByText("common:modals.createTask.selectProject"),
+ ).toBeNull();
+ });
+});
diff --git a/apps/web/src/components/shared/modals/create-task-modal.tsx b/apps/web/src/components/shared/modals/create-task-modal.tsx
index f3e5c0aab..b4c188f10 100644
--- a/apps/web/src/components/shared/modals/create-task-modal.tsx
+++ b/apps/web/src/components/shared/modals/create-task-modal.tsx
@@ -3,6 +3,7 @@ import { produce } from "immer";
import {
CalendarIcon,
Check,
+ FolderKanban,
Plus,
Search,
Tag,
@@ -41,6 +42,7 @@ import useCreateTask from "@/hooks/mutations/task/use-create-task";
import { useDeleteTask } from "@/hooks/mutations/task/use-delete-task";
import { useUpdateTask } from "@/hooks/mutations/task/use-update-task";
import useGetLabelsByWorkspace from "@/hooks/queries/label/use-get-labels-by-workspace";
+import useGetProjects from "@/hooks/queries/project/use-get-projects";
import useActiveWorkspace from "@/hooks/queries/workspace/use-active-workspace";
import { useGetActiveWorkspaceUsers } from "@/hooks/queries/workspace-users/use-get-active-workspace-users";
import { useWorkspacePermission } from "@/hooks/use-workspace-permission";
@@ -198,7 +200,16 @@ function CreateTaskModal({
const routeProjectId =
location.pathname.match(/\/project\/([^/]+)/)?.[1] ?? null;
- const resolvedProjectId = projectId || project?.id || routeProjectId || "";
+ const explicitProjectId = projectId || routeProjectId || "";
+ const [selectedProjectId, setSelectedProjectId] = useState("");
+ const resolvedProjectId =
+ explicitProjectId || selectedProjectId || project?.id || "";
+ const { data: workspaceProjects } = useGetProjects({
+ workspaceId: workspace?.id || "",
+ });
+ const resolvedProject = explicitProjectId
+ ? project
+ : (workspaceProjects?.find((p) => p.id === resolvedProjectId) ?? null);
const searchInputRef = useRef<HTMLInputElement>(null);
const draftCreationPromiseRef = useRef<Promise<Task> | null>(null);
@@ -487,7 +498,7 @@ function CreateTaskModal({
if ((e.metaKey || e.ctrlKey) && e.key === "Enter") {
e.preventDefault();
- if (title.trim() && project?.id && workspace?.id) {
+ if (title.trim() && resolvedProjectId && workspace?.id) {
const form = document.querySelector("form");
if (form) {
form.dispatchEvent(
@@ -497,7 +508,7 @@ function CreateTaskModal({
}
}
},
- [open, title, project?.id, workspace?.id],
+ [open, title, resolvedProjectId, workspace?.id],
);
useEffect(() => {
@@ -597,7 +608,7 @@ function CreateTaskModal({
<Breadcrumb>
<BreadcrumbList>
<BreadcrumbItem className="text-muted-foreground font-semibold tracking-wider text-sm">
- {project?.slug?.toUpperCase() ||
+ {resolvedProject?.slug?.toUpperCase() ||
t("common:modals.createTask.breadcrumbTask")}
</BreadcrumbItem>
<BreadcrumbSeparator />
@@ -664,6 +675,48 @@ function CreateTaskModal({
)}
<div className="flex flex-wrap items-center gap-2 py-2">
+ {!explicitProjectId && (
+ <Popover>
+ <PopoverTrigger asChild>
+ <button
+ type="button"
+ className={cn(
+ "flex items-center gap-1.5 px-2.5 py-1.5 text-xs font-medium rounded-md transition-colors border border-border hover:bg-accent/50",
+ resolvedProjectId
+ ? "bg-accent/30 text-foreground"
+ : "text-muted-foreground",
+ )}
+ >
+ <FolderKanban className="w-3.5 h-3.5" />
+ <span>
+ {resolvedProject?.name ||
+ t("common:modals.createTask.selectProject")}
+ </span>
+ </button>
+ </PopoverTrigger>
+ <PopoverContent className="w-48 p-1" align="start">
+ <div className="space-y-1">
+ {workspaceProjects?.map((workspaceProject) => (
+ <button
+ key={workspaceProject.id}
+ type="button"
+ className="w-full flex items-center gap-2 px-2 py-1.5 text-sm hover:bg-accent/50 text-left transition-colors h-8"
+ onClick={() =>
+ setSelectedProjectId(workspaceProject.id)
+ }
+ >
+ <span className="text-sm truncate">
+ {workspaceProject.name}
+ </span>
+ {resolvedProjectId === workspaceProject.id && (
+ <Check className="ml-auto h-4 w-4 shrink-0" />
+ )}
+ </button>
+ ))}
+ </div>
+ </PopoverContent>
+ </Popover>
+ )}
<div className="flex items-center gap-1.5 px-2.5 py-1.5 bg-accent/50 text-foreground rounded-md text-xs font-medium border border-border">
<div className="w-1.5 h-1.5 bg-foreground rounded-full" />
{statusLabel}
diff --git a/i18n/de-DE.json b/i18n/de-DE.json
index 94c10e155..e6ee49706 100644
--- a/i18n/de-DE.json
+++ b/i18n/de-DE.json
@@ -88,6 +88,7 @@
},
"createTask": {
"breadcrumbTask": "AUFGABE",
+ "selectProject": "Projekt auswählen",
"title": "Neue Aufgabe",
"description": "Erstelle eine neue Aufgabe, indem du einen Titel, eine Beschreibung und weitere Details angibst.",
"taskTitlePlaceholder": "Aufgabentitel",
diff --git a/i18n/el-GR.json b/i18n/el-GR.json
index 2692270f3..cc206d3c5 100644
--- a/i18n/el-GR.json
+++ b/i18n/el-GR.json
@@ -88,6 +88,7 @@
},
"createTask": {
"breadcrumbTask": "ΕΡΓΑΣΙΑ",
+ "selectProject": "Επιλογή έργου",
"title": "Νέα εργασία",
"description": "Δημιουργήστε μια νέα εργασία συμπληρώνοντας τίτλο, περιγραφή και άλλες λεπτομέρειες.",
"taskTitlePlaceholder": "Τίτλος εργασίας",
diff --git a/i18n/en-US.json b/i18n/en-US.json
index 3e916535e..208214e22 100644
--- a/i18n/en-US.json
+++ b/i18n/en-US.json
@@ -88,6 +88,7 @@
},
"createTask": {
"breadcrumbTask": "TASK",
+ "selectProject": "Select project",
"title": "New Task",
"description": "Create a new task by providing a title, description, and other details.",
"taskTitlePlaceholder": "Task title",
diff --git a/i18n/es-ES.json b/i18n/es-ES.json
index 174d64935..f01411387 100644
--- a/i18n/es-ES.json
+++ b/i18n/es-ES.json
@@ -87,6 +87,7 @@
},
"createTask": {
"breadcrumbTask": "TASK",
+ "selectProject": "Seleccionar proyecto",
"title": "Nueva tarea",
"description": "Crear una nueva tarea con título, descripción y otra información.",
"taskTitlePlaceholder": "Título de la tarea",
diff --git a/i18n/fr-FR.json b/i18n/fr-FR.json
index 8a7385152..731b39106 100644
--- a/i18n/fr-FR.json
+++ b/i18n/fr-FR.json
@@ -88,6 +88,7 @@
},
"createTask": {
"breadcrumbTask": "TÂCHE",
+ "selectProject": "Sélectionner un projet",
"title": "Nouvelle tâche",
"description": "Créez une nouvelle tâche en fournissant un titre, une description et d'autres détails.",
"taskTitlePlaceholder": "Titre de la tâche",
diff --git a/i18n/hi-IN.json b/i18n/hi-IN.json
index 37b130139..09e31d5fb 100644
--- a/i18n/hi-IN.json
+++ b/i18n/hi-IN.json
@@ -88,6 +88,7 @@
},
"createTask": {
"breadcrumbTask": "कार्य",
+ "selectProject": "प्रोजेक्ट चुनें",
"title": "नया कार्य",
"description": "शीर्षक, विवरण और अन्य विवरण देकर एक नया कार्य बनाएँ।",
"taskTitlePlaceholder": "कार्य का शीर्षक",
diff --git a/i18n/id-ID.json b/i18n/id-ID.json
index 7182d788b..e60048e00 100644
--- a/i18n/id-ID.json
+++ b/i18n/id-ID.json
@@ -88,6 +88,7 @@
},
"createTask": {
"breadcrumbTask": "TUGAS",
+ "selectProject": "Pilih proyek",
"title": "Tugas Baru",
"description": "Buat tugas baru dengan memberikan judul, deskripsi, dan detail lainnya.",
"taskTitlePlaceholder": "Judul tugas",
diff --git a/i18n/it-IT.json b/i18n/it-IT.json
index 5d586fa9f..fe609cacd 100644
--- a/i18n/it-IT.json
+++ b/i18n/it-IT.json
@@ -88,6 +88,7 @@
},
"createTask": {
"breadcrumbTask": "ATTIVITÀ",
+ "selectProject": "Seleziona progetto",
"title": "Nuova Attività",
"description": "Crea una nuova attività fornendo titolo, descrizione e altri dettagli.",
"taskTitlePlaceholder": "Titolo attività",
diff --git a/i18n/ko-KR.json b/i18n/ko-KR.json
index d3d909a6e..b966c8f8a 100644
--- a/i18n/ko-KR.json
+++ b/i18n/ko-KR.json
@@ -88,6 +88,7 @@
},
"createTask": {
"breadcrumbTask": "작업",
+ "selectProject": "프로젝트 선택",
"title": "새 작업",
"description": "제목, 설명 및 기타 세부 정보를 지정하여 새 작업을 만듭니다.",
"taskTitlePlaceholder": "작업 제목",
diff --git a/i18n/mk-MK.json b/i18n/mk-MK.json
index c860821b0..0e6ce3480 100644
--- a/i18n/mk-MK.json
+++ b/i18n/mk-MK.json
@@ -88,6 +88,7 @@
},
"createTask": {
"breadcrumbTask": "ЗАДАЧА",
+ "selectProject": "Избери проект",
"title": "Нова задача",
"description": "Креирај нова задача со наслов, опис и други детали.",
"taskTitlePlaceholder": "Наслов на задача",
diff --git a/i18n/nl-NL.json b/i18n/nl-NL.json
index 4d91b004c..b856218b7 100644
--- a/i18n/nl-NL.json
+++ b/i18n/nl-NL.json
@@ -87,6 +87,7 @@
},
"createTask": {
"breadcrumbTask": "TAAK",
+ "selectProject": "Project selecteren",
"title": "Nieuwe taak",
"description": "Maak een nieuwe taak aan door een titel, beschrijving en andere details op te geven.",
"taskTitlePlaceholder": "Taaknaam",
diff --git a/i18n/ru-RU.json b/i18n/ru-RU.json
index 1f2646971..3a25616d0 100644
--- a/i18n/ru-RU.json
+++ b/i18n/ru-RU.json
@@ -88,6 +88,7 @@
},
"createTask": {
"breadcrumbTask": "ЗАДАЧА",
+ "selectProject": "Выберите проект",
"title": "Новая задача",
"description": "Создайте новую задачу, указав название, описание и другие детали.",
"taskTitlePlaceholder": "Название задачи",
diff --git a/i18n/schema.json b/i18n/schema.json
index 1bb4d1cd0..eb9da7f29 100644
--- a/i18n/schema.json
+++ b/i18n/schema.json
@@ -344,6 +344,9 @@
"breadcrumbTask": {
"type": "string"
},
+ "selectProject": {
+ "type": "string"
+ },
"title": {
"type": "string"
},
@@ -475,6 +478,7 @@
},
"required": [
"breadcrumbTask",
+ "selectProject",
"title",
"description",
"taskTitlePlaceholder",
diff --git a/i18n/tr-TR.json b/i18n/tr-TR.json
index 4d358f55e..35f669244 100644
--- a/i18n/tr-TR.json
+++ b/i18n/tr-TR.json
@@ -88,6 +88,7 @@
},
"createTask": {
"breadcrumbTask": "TALEP",
+ "selectProject": "Proje seçin",
"title": "Yeni Talep",
"description": "Bir başlık, açıklama ve diğer ayrıntıları girerek yeni bir talep oluşturun.",
"taskTitlePlaceholder": "Talep başlığı",
diff --git a/i18n/uk-UA.json b/i18n/uk-UA.json
index a982720fc..ba658eb75 100644
--- a/i18n/uk-UA.json
+++ b/i18n/uk-UA.json
@@ -88,6 +88,7 @@
},
"createTask": {
"breadcrumbTask": "ЗАВДАННЯ",
+ "selectProject": "Виберіть проєкт",
"title": "Нове завдання",
"description": "Створіть нове завдання, вказавши назву, опис та інші деталі.",
"taskTitlePlaceholder": "Назва завдання",
diff --git a/i18n/vi-VN.json b/i18n/vi-VN.json
index 84ef088be..7576e4aff 100644
--- a/i18n/vi-VN.json
+++ b/i18n/vi-VN.json
@@ -88,6 +88,7 @@
},
"createTask": {
"breadcrumbTask": "CÔNG VIỆC",
+ "selectProject": "Chọn dự án",
"title": "Công việc mới",
"description": "Tạo một công việc mới bằng cách cung cấp tiêu đề, mô tả và các chi tiết khác.",
"taskTitlePlaceholder": "Tiêu đề công việc",
diff --git a/i18n/zh-CN.json b/i18n/zh-CN.json
index dcd2df9a3..4552b40b8 100644
--- a/i18n/zh-CN.json
+++ b/i18n/zh-CN.json
@@ -88,6 +88,7 @@
},
"createTask": {
"breadcrumbTask": "任务",
+ "selectProject": "选择项目",
"title": "新建任务",
"description": "通过提供标题、描述等详细信息来创建新任务。",
"taskTitlePlaceholder": "任务标题",