⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
fix(web): protect unsaved task input
Tin57a114165bc0
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.tsxindex f76cee1ae..79a98d5f8 100644--- a/apps/web/src/components/shared/modals/create-task-modal.test.tsx+++ b/apps/web/src/components/shared/modals/create-task-modal.test.tsx@@ -85,7 +85,37 @@ vi.mock("react-i18next", () => ({initReactI18next: { type: "3rdParty", init: vi.fn() },}));-describe("CreateTaskModal project picker", () => {+describe("CreateTaskModal", () => {+ it("keeps unsaved input until the user confirms discarding it", async () => {+ useLocation.mockReturnValue({+ pathname: "/dashboard/workspace/workspace-1/project/project-1/board",+ });+ const onClose = vi.fn();++ render(<CreateTaskModal open onClose={onClose} />);++ const titleInput = screen.getByPlaceholderText(+ "common:modals.createTask.taskTitlePlaceholder",+ );+ fireEvent.change(titleInput, { target: { value: "Unsaved task" } });++ const backdrop = document.querySelector('[data-slot="dialog-backdrop"]');+ expect(backdrop).not.toBeNull();+ fireEvent.pointerDown(backdrop as Element);+ fireEvent.pointerUp(backdrop as Element);+ fireEvent.click(backdrop as Element);++ expect(onClose).not.toHaveBeenCalled();+ expect(+ await screen.findByText("common:modals.createTask.discardTitle"),+ ).toBeTruthy();+ expect(titleInput).toHaveValue("Unsaved task");++ fireEvent.click(screen.getByText("common:modals.createTask.discardButton"));++ expect(onClose).toHaveBeenCalledTimes(1);+ });+it("shows a project picker and creates the task in the chosen project", async () => {useLocation.mockReturnValue({pathname: "/dashboard/workspace/workspace-1",diff --git a/apps/web/src/components/shared/modals/create-task-modal.tsx b/apps/web/src/components/shared/modals/create-task-modal.tsxindex cb3f627d7..9d9df3dd9 100644--- a/apps/web/src/components/shared/modals/create-task-modal.tsx+++ b/apps/web/src/components/shared/modals/create-task-modal.tsx@@ -13,6 +13,15 @@ import {import { useCallback, useEffect, useMemo, useRef, useState } from "react";import { useTranslation } from "react-i18next";import TaskDescriptionEditor from "@/components/task/task-description-editor";+import {+ AlertDialog,+ AlertDialogClose,+ AlertDialogContent,+ AlertDialogDescription,+ AlertDialogFooter,+ AlertDialogHeader,+ AlertDialogTitle,+} from "@/components/ui/alert-dialog";import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";import { Badge } from "@/components/ui/badge";import {@@ -191,6 +200,7 @@ function CreateTaskModal({const [createMore, setCreateMore] = useState(false);const [labels, setLabels] = useState<Label[]>([]);const [draftTask, setDraftTask] = useState<Task | null>(null);+ const [discardConfirmationOpen, setDiscardConfirmationOpen] = useState(false);const [labelsOpen, setLabelsOpen] = useState(false);const [labelsStep, setLabelsStep] = useState<PopoverStep>("select");@@ -241,9 +251,21 @@ function CreateTaskModal({(label) => label.name.toLowerCase() === searchValue.toLowerCase(),);- const handleClose = () => {+ const hasUnsavedChanges = Boolean(+ title.trim() ||+ description.trim() ||+ priority !== "no-priority" ||+ assigneeId ||+ startDate ||+ dueDate ||+ labels.length > 0 ||+ draftTask,+ );++ const closeAndReset = () => {const shouldDeleteDraft = draftTask && !didSubmitRef.current;+ setDiscardConfirmationOpen(false);setTitle("");setDescription("");setPriority("no-priority");@@ -268,6 +290,17 @@ function CreateTaskModal({}};+ const handleOpenChange = (nextOpen: boolean) => {+ if (nextOpen) return;++ if (hasUnsavedChanges && !didSubmitRef.current) {+ setDiscardConfirmationOpen(true);+ return;+ }++ closeAndReset();+ };+const syncTaskIntoProject = useCallback((task: Task) => {if (!project) return;@@ -451,7 +484,7 @@ function CreateTaskModal({didSubmitRef.current = false;setDraftTask(null);} else {- handleClose();+ closeAndReset();}} catch (error) {didSubmitRef.current = false;@@ -598,7 +631,7 @@ function CreateTaskModal({if (!canCreateTaskCapability) return null;return (- <Dialog open={open} onOpenChange={handleClose}>+ <Dialog open={open} onOpenChange={handleOpenChange}><DialogContentclassName="kaneo-create-task-modal max-w-2xl max-h-[90vh] flex flex-col overflow-hidden"showCloseButton={false}@@ -1084,7 +1117,7 @@ function CreateTaskModal({<Buttontype="button"- onClick={handleClose}+ onClick={() => handleOpenChange(false)}variant="outline"size="sm"className="border-border text-foreground hover:bg-accent"@@ -1102,6 +1135,37 @@ function CreateTaskModal({</DialogFooter></form></DialogContent>++ <AlertDialog+ open={discardConfirmationOpen}+ onOpenChange={setDiscardConfirmationOpen}+ >+ <AlertDialogContent>+ <AlertDialogHeader>+ <AlertDialogTitle>+ {t("common:modals.createTask.discardTitle")}+ </AlertDialogTitle>+ <AlertDialogDescription>+ {t("common:modals.createTask.discardDescription")}+ </AlertDialogDescription>+ </AlertDialogHeader>+ <AlertDialogFooter>+ <AlertDialogClose+ render={<Button type="button" variant="outline" size="sm" />}+ >+ {t("common:actions.cancel")}+ </AlertDialogClose>+ <Button+ type="button"+ variant="destructive"+ size="sm"+ onClick={closeAndReset}+ >+ {t("common:modals.createTask.discardButton")}+ </Button>+ </AlertDialogFooter>+ </AlertDialogContent>+ </AlertDialog></Dialog>);}diff --git a/i18n/de-DE.json b/i18n/de-DE.jsonindex e5549a50f..c55a6f12c 100644--- a/i18n/de-DE.json+++ b/i18n/de-DE.json@@ -139,6 +139,9 @@"labelCreateError": "Label konnte nicht erstellt werden","createMore": "Weitere erstellen","createButton": "Aufgabe erstellen",+ "discardTitle": "Aufgabe verwerfen?",+ "discardDescription": "Deine ungespeicherten Aufgabendetails gehen verloren.",+ "discardButton": "Aufgabe verwerfen","untitledTask": "Unbenannte Aufgabe","labelColors": {"stone": "Stein",diff --git a/i18n/el-GR.json b/i18n/el-GR.jsonindex 9223b05b1..aa49dcfa1 100644--- a/i18n/el-GR.json+++ b/i18n/el-GR.json@@ -139,6 +139,9 @@"labelCreateError": "Αποτυχία δημιουργίας ετικέτας","createMore": "Δημιουργία περισσότερων","createButton": "Δημιουργία εργασίας",+ "discardTitle": "Απόρριψη εργασίας;",+ "discardDescription": "Οι μη αποθηκευμένες λεπτομέρειες της εργασίας θα χαθούν.",+ "discardButton": "Απόρριψη εργασίας","untitledTask": "Εργασία χωρίς τίτλο","labelColors": {"stone": "Πέτρα",diff --git a/i18n/en-US.json b/i18n/en-US.jsonindex b0e7a597e..7526e0ede 100644--- a/i18n/en-US.json+++ b/i18n/en-US.json@@ -139,6 +139,9 @@"labelCreateError": "Failed to create label","createMore": "Create more","createButton": "Create Task",+ "discardTitle": "Discard task?",+ "discardDescription": "Your unsaved task details will be lost.",+ "discardButton": "Discard task","untitledTask": "Untitled task","labelColors": {"stone": "Stone",diff --git a/i18n/es-ES.json b/i18n/es-ES.jsonindex bb4cfbecf..1ec59eed0 100644--- a/i18n/es-ES.json+++ b/i18n/es-ES.json@@ -139,6 +139,9 @@"labelCreateError": "Error al crear la etiqueta","createMore": "Crear más","createButton": "Crear tarea",+ "discardTitle": "¿Descartar tarea?",+ "discardDescription": "Los detalles de la tarea que no hayas guardado se perderán.",+ "discardButton": "Descartar tarea","untitledTask": "Tarea sin título","labelColors": {"stone": "Piedra",diff --git a/i18n/fr-FR.json b/i18n/fr-FR.jsonindex 434ae1c39..5e184cd95 100644--- a/i18n/fr-FR.json+++ b/i18n/fr-FR.json@@ -139,6 +139,9 @@"labelCreateError": "Échec de la création du label","createMore": "Créer plus","createButton": "Créer la tâche",+ "discardTitle": "Abandonner la tâche ?",+ "discardDescription": "Les détails non enregistrés de la tâche seront perdus.",+ "discardButton": "Abandonner la tâche","untitledTask": "Tâche sans titre","labelColors": {"stone": "Pierre",diff --git a/i18n/hi-IN.json b/i18n/hi-IN.jsonindex 032daedf9..621c687b1 100644--- a/i18n/hi-IN.json+++ b/i18n/hi-IN.json@@ -139,6 +139,9 @@"labelCreateError": "लेबल बनाने में विफल","createMore": "और बनाएँ","createButton": "कार्य बनाएँ",+ "discardTitle": "कार्य छोड़ें?",+ "discardDescription": "आपके सहेजे नहीं गए कार्य विवरण खो जाएँगे।",+ "discardButton": "कार्य छोड़ें","untitledTask": "बिना शीर्षक कार्य","labelColors": {"stone": "पत्थर",diff --git a/i18n/id-ID.json b/i18n/id-ID.jsonindex 6cd4833f6..81dfa5bf3 100644--- a/i18n/id-ID.json+++ b/i18n/id-ID.json@@ -139,6 +139,9 @@"labelCreateError": "Gagal membuat label","createMore": "Buat lagi","createButton": "Buat Tugas",+ "discardTitle": "Buang tugas?",+ "discardDescription": "Detail tugas yang belum disimpan akan hilang.",+ "discardButton": "Buang tugas","untitledTask": "Tugas tanpa judul","labelColors": {"stone": "Abu Batu",diff --git a/i18n/it-IT.json b/i18n/it-IT.jsonindex 4375e15d5..1d6bc05a0 100644--- a/i18n/it-IT.json+++ b/i18n/it-IT.json@@ -139,6 +139,9 @@"labelCreateError": "Creazione etichetta fallita","createMore": "Crea altro","createButton": "Crea Attività",+ "discardTitle": "Scartare l'attività?",+ "discardDescription": "I dettagli non salvati dell'attività andranno persi.",+ "discardButton": "Scarta attività","untitledTask": "Attività senza titolo","labelColors": {"stone": "Pietra",diff --git a/i18n/ja-JP.json b/i18n/ja-JP.jsonindex 8719bcd4f..14de760c0 100644--- a/i18n/ja-JP.json+++ b/i18n/ja-JP.json@@ -139,6 +139,9 @@"labelCreateError": "ラベルの作成に失敗しました","createMore": "続けて作成","createButton": "タスクを作成",+ "discardTitle": "タスクを破棄しますか?",+ "discardDescription": "保存されていないタスクの詳細は失われます。",+ "discardButton": "タスクを破棄","untitledTask": "無題のタスク","labelColors": {"stone": "ストーン",diff --git a/i18n/ko-KR.json b/i18n/ko-KR.jsonindex 2b594d7ca..65dfd214c 100644--- a/i18n/ko-KR.json+++ b/i18n/ko-KR.json@@ -139,6 +139,9 @@"labelCreateError": "라벨 생성에 실패했습니다","createMore": "계속 만들기","createButton": "작업 만들기",+ "discardTitle": "작업을 취소할까요?",+ "discardDescription": "저장하지 않은 작업 세부 정보가 손실됩니다.",+ "discardButton": "작업 취소","untitledTask": "제목 없는 작업","labelColors": {"stone": "스톤",diff --git a/i18n/mk-MK.json b/i18n/mk-MK.jsonindex 4f587ae92..3b1909a04 100644--- a/i18n/mk-MK.json+++ b/i18n/mk-MK.json@@ -139,6 +139,9 @@"labelCreateError": "Неуспешно креирање на етикета","createMore": "Креирај уште","createButton": "Креирај задача",+ "discardTitle": "Да се отфрли задачата?",+ "discardDescription": "Незачуваните детали за задачата ќе се изгубат.",+ "discardButton": "Отфрли ја задачата","untitledTask": "Задача без наслов","labelColors": {"stone": "Камен",diff --git a/i18n/nl-NL.json b/i18n/nl-NL.jsonindex ab369d44d..a76d7727c 100644--- a/i18n/nl-NL.json+++ b/i18n/nl-NL.json@@ -139,6 +139,9 @@"labelCreateError": "Aanmaken van label mislukt","createMore": "Meer aanmaken","createButton": "Taak aanmaken",+ "discardTitle": "Taak verwerpen?",+ "discardDescription": "Je niet-opgeslagen taakgegevens gaan verloren.",+ "discardButton": "Taak verwerpen","untitledTask": "Naamloze taak","labelColors": {"stone": "Steen",diff --git a/i18n/pt-BR.json b/i18n/pt-BR.jsonindex 50f64fde8..6d8460499 100644--- a/i18n/pt-BR.json+++ b/i18n/pt-BR.json@@ -139,6 +139,9 @@"labelCreateError": "Falha ao criar etiqueta","createMore": "Criar mais","createButton": "Criar tarefa",+ "discardTitle": "Descartar tarefa?",+ "discardDescription": "Os detalhes não salvos da tarefa serão perdidos.",+ "discardButton": "Descartar tarefa","untitledTask": "Tarefa sem título","labelColors": {"stone": "Pedra",diff --git a/i18n/ru-RU.json b/i18n/ru-RU.jsonindex bbdc04e4c..8596b1608 100644--- a/i18n/ru-RU.json+++ b/i18n/ru-RU.json@@ -139,6 +139,9 @@"labelCreateError": "Не удалось создать метку","createMore": "Создать ещё","createButton": "Создать задачу",+ "discardTitle": "Отменить задачу?",+ "discardDescription": "Несохранённые данные задачи будут потеряны.",+ "discardButton": "Отменить задачу","untitledTask": "Задача без названия","labelColors": {"stone": "Камень",diff --git a/i18n/schema.json b/i18n/schema.jsonindex 2648324be..456802b89 100644--- a/i18n/schema.json+++ b/i18n/schema.json@@ -515,6 +515,15 @@"createButton": {"type": "string"},+ "discardTitle": {+ "type": "string"+ },+ "discardDescription": {+ "type": "string"+ },+ "discardButton": {+ "type": "string"+ },"untitledTask": {"type": "string"},@@ -593,6 +602,9 @@"labelCreateError","createMore","createButton",+ "discardTitle",+ "discardDescription",+ "discardButton","untitledTask","labelColors"]diff --git a/i18n/tr-TR.json b/i18n/tr-TR.jsonindex 86ecb1934..f48e97f50 100644--- a/i18n/tr-TR.json+++ b/i18n/tr-TR.json@@ -139,6 +139,9 @@"labelCreateError": "Etiket oluşturulamadı","createMore": "Daha fazla oluştur","createButton": "Talep Oluştur",+ "discardTitle": "Görev iptal edilsin mi?",+ "discardDescription": "Kaydedilmemiş görev ayrıntıları kaybolacak.",+ "discardButton": "Görevi iptal et","untitledTask": "Başlıksız talep","labelColors": {"stone": "Taş",diff --git a/i18n/uk-UA.json b/i18n/uk-UA.jsonindex d4042e899..f19b8e38a 100644--- a/i18n/uk-UA.json+++ b/i18n/uk-UA.json@@ -139,6 +139,9 @@"labelCreateError": "Не вдалося створити мітку","createMore": "Створити ще","createButton": "Створити завдання",+ "discardTitle": "Відхилити завдання?",+ "discardDescription": "Незбережені дані завдання буде втрачено.",+ "discardButton": "Відхилити завдання","untitledTask": "Завдання без назви","labelColors": {"stone": "Камінь",diff --git a/i18n/vi-VN.json b/i18n/vi-VN.jsonindex 1bd9a8955..53f0bde01 100644--- a/i18n/vi-VN.json+++ b/i18n/vi-VN.json@@ -139,6 +139,9 @@"labelCreateError": "Không thể tạo nhãn","createMore": "Tạo thêm","createButton": "Tạo công việc",+ "discardTitle": "Hủy công việc?",+ "discardDescription": "Các chi tiết công việc chưa lưu sẽ bị mất.",+ "discardButton": "Hủy công việc","untitledTask": "Công việc chưa đặt tên","labelColors": {"stone": "Đá",diff --git a/i18n/zh-CN.json b/i18n/zh-CN.jsonindex ef3755f5d..3cd70152a 100644--- a/i18n/zh-CN.json+++ b/i18n/zh-CN.json@@ -139,6 +139,9 @@"labelCreateError": "创建标签失败","createMore": "继续创建","createButton": "创建任务",+ "discardTitle": "放弃任务?",+ "discardDescription": "未保存的任务详情将会丢失。",+ "discardButton": "放弃任务","untitledTask": "未命名任务","labelColors": {"stone": "石板灰",