⚡ 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
feat(settings): add workspace labels management page with CRUD
Glen Edere656a698f588
diff --git a/.plans/workspace-labels-settings.md b/.plans/workspace-labels-settings.mdnew file mode 100644index 000000000..bdc86a925--- /dev/null+++ b/.plans/workspace-labels-settings.md@@ -0,0 +1,125 @@+# Workspace Labels Settings++Add a "Labels" configuration section to the workspace settings tab, allowing users to create, edit, and delete workspace-level labels.++## Background++Labels can exist at two levels in the database:+- **Workspace-level** (`taskId = null`): Reusable label templates unique by name within a workspace.+- **Task-level** (`taskId` set): An instance of a workspace label assigned to a specific task.++Currently, workspace-level labels can only be managed indirectly through the task label picker popover. There is no dedicated management UI for listing, editing, or deleting workspace-level labels from the settings.++A `@/constants/label-colors.ts` file already exists with the 9 label color definitions. The API endpoints for CRUD mostly exist but need minor fixes.++---++## Steps++### Step 1: Fix API — Allow deletion of workspace-level labels++**File: `apps/api/src/label/controllers/delete-label.ts`**++The current `deleteLabel` controller rejects deletion of labels with `taskId = null` (workspace-level labels) with a 400 error. This needs to be updated to:++- If the label has a `taskId` (task-level): keep existing logic — fetch the task, delete, sync to GitHub, publish event.+- If the label has **no `taskId`** (workspace-level): just delete the row directly. No GitHub sync or event needed.++**Specific changes:**+- Remove the guard that throws 400 when `taskId` is null (lines 19-23).+- Branch logic: if `taskId` exists, do the existing full flow (fetch task, delete, GitHub sync, publish event). If `taskId` is null, just `db.delete(labelTable).where(eq(labelTable.id, id))`.++### Step 2: Fix frontend — Add cache invalidation to `useUpdateLabel`++**File: `apps/web/src/hooks/mutations/label/use-update-label.ts`**++The `useUpdateLabel` mutation hook has **no `onSuccess` callback**, so after updating a label's name or color, the cached label lists in the frontend are stale until a refetch happens.++Add cache invalidation on success: after the mutation completes, invalidate the `["labels", workspaceId]` query key so the workspace labels list refreshes automatically.++**Note:** The response from `PUT /label/:id` returns the updated label which includes `workspaceId`, so the hook can access `updatedLabel.workspaceId` for the query key.++### Step 3: Create the Labels settings page route + component++**New file: `apps/web/src/routes/_layout/_authenticated/dashboard/settings/workspace/labels.tsx`**++This is the main page. Structure:++1. **Page layout**: Follow the pattern from `general.tsx` — use `PageTitle`, translated texts, section-based layout.+2. **Data fetching**: Use `useGetLabelsByWorkspace(workspaceId)` to fetch all workspace-level labels (filtered by `taskId = null`).+3. **Labels list**: Render existing labels as a list/table with:+ - Color dot + name display+ - Edit button (opens a dialog)+ - Delete button (with confirmation dialog)+4. **Create label**: A "Create Label" button at the top that opens a dialog with name input + color picker. Uses `useCreateLabel` mutation.+5. **Edit label**: Dialog pre-filled with current name and color. Uses `useUpdateLabel` mutation.+6. **Delete label**: AlertDialog confirmation, then calls `useDeleteLabel` mutation.+7. **Permission gating**: Use `canManageLabels()` from `useWorkspacePermission` to conditionally show/hide create/edit/delete controls.+8. **Color picker**: Reuse `labelColors` from `@/constants/label-colors` for the 9-color palette (same colors as in the task label picker).++### Step 4: Add sidebar link for Labels in workspace settings++**File: `apps/web/src/routes/_layout/_authenticated/dashboard/settings/workspace.tsx`**++Add a new "Labels" menu item to the `menuItems` array:+- `title`: `t("settings:workspaceLabels.title", { defaultValue: "Labels" })`+- `url`: `/dashboard/settings/workspace/labels`+- `icon`: `Tag` from `lucide-react`++### Step 5: Add translation keys++**File: `i18n/en-US.json`** (and add to `i18n/schema.json`)++Add `workspaceLabels` key under the `settings` section:+```json+"workspaceLabels": {+ "pageTitle": "Label Management",+ "title": "Labels",+ "subtitle": "Create, edit, and delete workspace-level labels.",+ "createLabel": "Create Label",+ "editLabel": "Edit Label",+ "deleteLabel": "Delete Label",+ "nameLabel": "Label name",+ "namePlaceholder": "Enter label name",+ "colorLabel": "Color",+ "deleteConfirmTitle": "Delete this label?",+ "deleteConfirmDescription": "This will permanently remove this label from all tasks. This action cannot be undone.",+ "empty": "No labels yet. Create your first label to get started.",+ "createSuccess": "Label created",+ "updateSuccess": "Label updated",+ "deleteSuccess": "Label deleted",+ "createError": "Failed to create label",+ "updateError": "Failed to update label",+ "deleteError": "Failed to delete label",+ "nameRequired": "Label name is required"+}+```++### Step 6: Regenerate the route tree++Run `pnpm dev` or the TanStack Router codegen so the new route file gets picked up in `routeTree.gen.ts`. The file-based routing will auto-detect `labels.tsx` as a child of `workspace.tsx` and wire it up.++Alternatively, if auto-generation is not running, manually trigger: check if there's a route generation command in package.json scripts.++---++## API Change Summary++| File | Change |+|------|--------|+| `apps/api/src/label/controllers/delete-label.ts` | Allow deletion of workspace-level labels (no taskId) |+| `apps/web/src/hooks/mutations/label/use-update-label.ts` | Add cache invalidation on success |++## New Frontend Files++| File | Purpose |+|------|---------|+| `apps/web/src/routes/_layout/_authenticated/dashboard/settings/workspace/labels.tsx` | Labels settings page with CRUD UI |++## Modified Frontend Files++| File | Change |+|------|--------|+| `apps/web/src/routes/_layout/_authenticated/dashboard/settings/workspace.tsx` | Add "Labels" nav item to sidebar |+| `i18n/en-US.json` | Add `workspaceLabels` translation keys |+| `i18n/schema.json` | Add `workspaceLabels` schema definition |diff --git a/apps/api/src/label/controllers/delete-label.ts b/apps/api/src/label/controllers/delete-label.tsindex 963f31ea3..3307e7557 100644--- a/apps/api/src/label/controllers/delete-label.ts+++ b/apps/api/src/label/controllers/delete-label.ts@@ -16,29 +16,57 @@ async function deleteLabel(id: string, userId: string) {});}- if (!label.taskId) {- throw new HTTPException(400, {- message: "Label is not associated with a task",- });- }+ if (label.taskId) {+ // Task-level label: fetch task, delete with event + GitHub sync+ const [task] = await db+ .select({+ id: taskTable.id,+ projectId: taskTable.projectId,+ workspaceId: projectTable.workspaceId,+ })+ .from(taskTable)+ .innerJoin(projectTable, eq(taskTable.projectId, projectTable.id))+ .where(eq(taskTable.id, label.taskId))+ .limit(1);- const [task] = await db- .select({- id: taskTable.id,- projectId: taskTable.projectId,- workspaceId: projectTable.workspaceId,- })- .from(taskTable)- .innerJoin(projectTable, eq(taskTable.projectId, projectTable.id))- .where(eq(taskTable.id, label.taskId))- .limit(1);+ if (!task) {+ throw new HTTPException(404, {+ message: "Task not found",+ });+ }- if (!task) {- throw new HTTPException(404, {- message: "Task not found",+ const [deletedLabel] = await db+ .delete(labelTable)+ .where(eq(labelTable.id, id))+ .returning();++ if (!deletedLabel) {+ throw new HTTPException(404, {+ message: "Label not found",+ });+ }++ if (deletedLabel.taskId) {+ removeLabelFromGitHub(deletedLabel.taskId, deletedLabel.name).catch(+ (error) => {+ console.error("Failed to remove label from GitHub:", error);+ },+ );+ }++ await publishEvent("task.label_deleted", {+ label: deletedLabel,+ task,+ projectId: task.projectId,+ taskId: task.id,+ userId,+ type: "label_deleted",});++ return deletedLabel;}+ // Workspace-level label: just delete, no GitHub sync or event neededconst [deletedLabel] = await db.delete(labelTable).where(eq(labelTable.id, id))@@ -50,23 +78,6 @@ async function deleteLabel(id: string, userId: string) {});}- if (deletedLabel?.taskId) {- removeLabelFromGitHub(deletedLabel.taskId, deletedLabel.name).catch(- (error) => {- console.error("Failed to remove label from GitHub:", error);- },- );- }-- await publishEvent("task.label_deleted", {- label: deletedLabel,- task: task,- projectId: task.projectId,- taskId: task.id,- userId: userId,- type: "label_deleted",- });-return deletedLabel;}diff --git a/apps/web/src/hooks/mutations/label/use-update-label.test.tsx b/apps/web/src/hooks/mutations/label/use-update-label.test.tsxnew file mode 100644index 000000000..54f3f165d--- /dev/null+++ b/apps/web/src/hooks/mutations/label/use-update-label.test.tsx@@ -0,0 +1,69 @@+import { renderHook } from "@testing-library/react";+import { describe, expect, it, vi } from "vitest";+import useUpdateLabel from "./use-update-label";++const mockInvalidateQueries = vi.fn();++vi.mock("@tanstack/react-query", () => ({+ useQueryClient: () => ({+ invalidateQueries: mockInvalidateQueries,+ }),+ useMutation: (options: { onSuccess?: (data: unknown) => void }) => {+ const mutateAsync = vi+ .fn()+ .mockImplementation(+ async (vars: { id: string; name: string; color: string }) => {+ const result = {+ id: vars.id,+ name: vars.name,+ color: vars.color,+ workspaceId: "workspace-1",+ taskId: null,+ createdAt: new Date(),+ updatedAt: new Date(),+ };+ await options.onSuccess?.(result);+ return result;+ },+ );++ return {+ mutateAsync,+ isPending: false,+ };+ },+}));++vi.mock("@/fetchers/label/update-label", () => ({+ default: vi.fn(),+}));++describe("useUpdateLabel", () => {+ it("invalidates the workspace labels cache on success", async () => {+ const { result } = renderHook(() => useUpdateLabel());++ await result.current.mutateAsync({+ id: "label-1",+ name: "Updated Label",+ color: "purple",+ });++ expect(mockInvalidateQueries).toHaveBeenCalledWith({+ queryKey: ["labels", "workspace-1"],+ });+ });++ it("invalidates with the correct workspaceId from the response", async () => {+ const { result } = renderHook(() => useUpdateLabel());++ await result.current.mutateAsync({+ id: "label-2",+ name: "Bug",+ color: "red",+ });++ expect(mockInvalidateQueries).toHaveBeenCalledWith({+ queryKey: ["labels", "workspace-1"],+ });+ });+});diff --git a/apps/web/src/hooks/mutations/label/use-update-label.ts b/apps/web/src/hooks/mutations/label/use-update-label.tsindex facce90b4..4a17ee13c 100644--- a/apps/web/src/hooks/mutations/label/use-update-label.ts+++ b/apps/web/src/hooks/mutations/label/use-update-label.ts@@ -1,9 +1,16 @@-import { useMutation } from "@tanstack/react-query";+import { useMutation, useQueryClient } from "@tanstack/react-query";import updateLabel from "@/fetchers/label/update-label";function useUpdateLabel() {+ const queryClient = useQueryClient();+return useMutation({mutationFn: updateLabel,+ onSuccess: (updatedLabel) => {+ void queryClient.invalidateQueries({+ queryKey: ["labels", updatedLabel.workspaceId],+ });+ },});}diff --git a/apps/web/src/routeTree.gen.ts b/apps/web/src/routeTree.gen.tsindex deb14e611..390d58e81 100644--- a/apps/web/src/routeTree.gen.ts+++ b/apps/web/src/routeTree.gen.ts@@ -39,6 +39,7 @@ import { Route as LayoutAuthenticatedDashboardWorkspaceWorkspaceIdIndexRouteImpoimport { Route as LayoutAuthenticatedDashboardWorkspaceWorkspaceIdSearchRouteImport } from './routes/_layout/_authenticated/dashboard/workspace/$workspaceId/search'import { Route as LayoutAuthenticatedDashboardWorkspaceWorkspaceIdMembersRouteImport } from './routes/_layout/_authenticated/dashboard/workspace/$workspaceId/members'import { Route as LayoutAuthenticatedDashboardSettingsWorkspaceRolesRouteImport } from './routes/_layout/_authenticated/dashboard/settings/workspace/roles'+import { Route as LayoutAuthenticatedDashboardSettingsWorkspaceLabelsRouteImport } from './routes/_layout/_authenticated/dashboard/settings/workspace/labels'import { Route as LayoutAuthenticatedDashboardSettingsWorkspaceGeneralRouteImport } from './routes/_layout/_authenticated/dashboard/settings/workspace/general'import { Route as LayoutAuthenticatedDashboardSettingsAccountPreferencesRouteImport } from './routes/_layout/_authenticated/dashboard/settings/account/preferences'import { Route as LayoutAuthenticatedDashboardSettingsAccountNotificationsRouteImport } from './routes/_layout/_authenticated/dashboard/settings/account/notifications'@@ -219,6 +220,12 @@ const LayoutAuthenticatedDashboardSettingsWorkspaceRolesRoute =path: '/roles',getParentRoute: () => LayoutAuthenticatedDashboardSettingsWorkspaceRoute,} as any)+const LayoutAuthenticatedDashboardSettingsWorkspaceLabelsRoute =+ LayoutAuthenticatedDashboardSettingsWorkspaceLabelsRouteImport.update({+ id: '/labels',+ path: '/labels',+ getParentRoute: () => LayoutAuthenticatedDashboardSettingsWorkspaceRoute,+ } as any)const LayoutAuthenticatedDashboardSettingsWorkspaceGeneralRoute =LayoutAuthenticatedDashboardSettingsWorkspaceGeneralRouteImport.update({id: '/general',@@ -357,6 +364,7 @@ export interface FileRoutesByFullPath {'/dashboard/settings/account/notifications': typeof LayoutAuthenticatedDashboardSettingsAccountNotificationsRoute'/dashboard/settings/account/preferences': typeof LayoutAuthenticatedDashboardSettingsAccountPreferencesRoute'/dashboard/settings/workspace/general': typeof LayoutAuthenticatedDashboardSettingsWorkspaceGeneralRoute+ '/dashboard/settings/workspace/labels': typeof LayoutAuthenticatedDashboardSettingsWorkspaceLabelsRoute'/dashboard/settings/workspace/roles': typeof LayoutAuthenticatedDashboardSettingsWorkspaceRolesRoute'/dashboard/workspace/$workspaceId/members': typeof LayoutAuthenticatedDashboardWorkspaceWorkspaceIdMembersRoute'/dashboard/workspace/$workspaceId/search': typeof LayoutAuthenticatedDashboardWorkspaceWorkspaceIdSearchRoute@@ -398,6 +406,7 @@ export interface FileRoutesByTo {'/dashboard/settings/account/notifications': typeof LayoutAuthenticatedDashboardSettingsAccountNotificationsRoute'/dashboard/settings/account/preferences': typeof LayoutAuthenticatedDashboardSettingsAccountPreferencesRoute'/dashboard/settings/workspace/general': typeof LayoutAuthenticatedDashboardSettingsWorkspaceGeneralRoute+ '/dashboard/settings/workspace/labels': typeof LayoutAuthenticatedDashboardSettingsWorkspaceLabelsRoute'/dashboard/settings/workspace/roles': typeof LayoutAuthenticatedDashboardSettingsWorkspaceRolesRoute'/dashboard/workspace/$workspaceId/members': typeof LayoutAuthenticatedDashboardWorkspaceWorkspaceIdMembersRoute'/dashboard/workspace/$workspaceId/search': typeof LayoutAuthenticatedDashboardWorkspaceWorkspaceIdSearchRoute@@ -445,6 +454,7 @@ export interface FileRoutesById {'/_layout/_authenticated/dashboard/settings/account/notifications': typeof LayoutAuthenticatedDashboardSettingsAccountNotificationsRoute'/_layout/_authenticated/dashboard/settings/account/preferences': typeof LayoutAuthenticatedDashboardSettingsAccountPreferencesRoute'/_layout/_authenticated/dashboard/settings/workspace/general': typeof LayoutAuthenticatedDashboardSettingsWorkspaceGeneralRoute+ '/_layout/_authenticated/dashboard/settings/workspace/labels': typeof LayoutAuthenticatedDashboardSettingsWorkspaceLabelsRoute'/_layout/_authenticated/dashboard/settings/workspace/roles': typeof LayoutAuthenticatedDashboardSettingsWorkspaceRolesRoute'/_layout/_authenticated/dashboard/workspace/$workspaceId/members': typeof LayoutAuthenticatedDashboardWorkspaceWorkspaceIdMembersRoute'/_layout/_authenticated/dashboard/workspace/$workspaceId/search': typeof LayoutAuthenticatedDashboardWorkspaceWorkspaceIdSearchRoute@@ -491,6 +501,7 @@ export interface FileRouteTypes {| '/dashboard/settings/account/notifications'| '/dashboard/settings/account/preferences'| '/dashboard/settings/workspace/general'+ | '/dashboard/settings/workspace/labels'| '/dashboard/settings/workspace/roles'| '/dashboard/workspace/$workspaceId/members'| '/dashboard/workspace/$workspaceId/search'@@ -532,6 +543,7 @@ export interface FileRouteTypes {| '/dashboard/settings/account/notifications'| '/dashboard/settings/account/preferences'| '/dashboard/settings/workspace/general'+ | '/dashboard/settings/workspace/labels'| '/dashboard/settings/workspace/roles'| '/dashboard/workspace/$workspaceId/members'| '/dashboard/workspace/$workspaceId/search'@@ -578,6 +590,7 @@ export interface FileRouteTypes {| '/_layout/_authenticated/dashboard/settings/account/notifications'| '/_layout/_authenticated/dashboard/settings/account/preferences'| '/_layout/_authenticated/dashboard/settings/workspace/general'+ | '/_layout/_authenticated/dashboard/settings/workspace/labels'| '/_layout/_authenticated/dashboard/settings/workspace/roles'| '/_layout/_authenticated/dashboard/workspace/$workspaceId/members'| '/_layout/_authenticated/dashboard/workspace/$workspaceId/search'@@ -815,6 +828,13 @@ declare module '@tanstack/react-router' {preLoaderRoute: typeof LayoutAuthenticatedDashboardSettingsWorkspaceRolesRouteImportparentRoute: typeof LayoutAuthenticatedDashboardSettingsWorkspaceRoute}+ '/_layout/_authenticated/dashboard/settings/workspace/labels': {+ id: '/_layout/_authenticated/dashboard/settings/workspace/labels'+ path: '/labels'+ fullPath: '/dashboard/settings/workspace/labels'+ preLoaderRoute: typeof LayoutAuthenticatedDashboardSettingsWorkspaceLabelsRouteImport+ parentRoute: typeof LayoutAuthenticatedDashboardSettingsWorkspaceRoute+ }'/_layout/_authenticated/dashboard/settings/workspace/general': {id: '/_layout/_authenticated/dashboard/settings/workspace/general'path: '/general'@@ -966,6 +986,7 @@ const LayoutAuthenticatedDashboardSettingsProjectsRouteWithChildren =interface LayoutAuthenticatedDashboardSettingsWorkspaceRouteChildren {LayoutAuthenticatedDashboardSettingsWorkspaceGeneralRoute: typeof LayoutAuthenticatedDashboardSettingsWorkspaceGeneralRoute+ LayoutAuthenticatedDashboardSettingsWorkspaceLabelsRoute: typeof LayoutAuthenticatedDashboardSettingsWorkspaceLabelsRouteLayoutAuthenticatedDashboardSettingsWorkspaceRolesRoute: typeof LayoutAuthenticatedDashboardSettingsWorkspaceRolesRoute}@@ -973,6 +994,8 @@ const LayoutAuthenticatedDashboardSettingsWorkspaceRouteChildren: LayoutAuthenti{LayoutAuthenticatedDashboardSettingsWorkspaceGeneralRoute:LayoutAuthenticatedDashboardSettingsWorkspaceGeneralRoute,+ LayoutAuthenticatedDashboardSettingsWorkspaceLabelsRoute:+ LayoutAuthenticatedDashboardSettingsWorkspaceLabelsRoute,LayoutAuthenticatedDashboardSettingsWorkspaceRolesRoute:LayoutAuthenticatedDashboardSettingsWorkspaceRolesRoute,}diff --git a/apps/web/src/routes/_layout/_authenticated/dashboard/settings/workspace.tsx b/apps/web/src/routes/_layout/_authenticated/dashboard/settings/workspace.tsxindex 951940936..d162388aa 100644--- a/apps/web/src/routes/_layout/_authenticated/dashboard/settings/workspace.tsx+++ b/apps/web/src/routes/_layout/_authenticated/dashboard/settings/workspace.tsx@@ -5,7 +5,7 @@ import {redirect,useLocation,} from "@tanstack/react-router";-import { Settings, Shield } from "lucide-react";+import { Settings, Shield, Tag } from "lucide-react";import { useTranslation } from "react-i18next";import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";import { Button } from "@/components/ui/button";@@ -61,6 +61,11 @@ function RouteComponent() {url: "/dashboard/settings/workspace/roles",icon: Shield,},+ {+ title: t("settings:workspaceLabels.title", { defaultValue: "Labels" }),+ url: "/dashboard/settings/workspace/labels",+ icon: Tag,+ },];const isActivePath = (path: string) => location.pathname === path;const workspaceInitials =diff --git a/apps/web/src/routes/_layout/_authenticated/dashboard/settings/workspace/labels.tsx b/apps/web/src/routes/_layout/_authenticated/dashboard/settings/workspace/labels.tsxnew file mode 100644index 000000000..da7e1a7e6--- /dev/null+++ b/apps/web/src/routes/_layout/_authenticated/dashboard/settings/workspace/labels.tsx@@ -0,0 +1,553 @@+import { createFileRoute } from "@tanstack/react-router";+import { Pencil, Plus, Tag, Trash2 } from "lucide-react";+import { useState } from "react";+import { useTranslation } from "react-i18next";+import PageTitle from "@/components/page-title";+import {+ AlertDialog,+ AlertDialogContent,+ AlertDialogDescription,+ AlertDialogFooter,+ AlertDialogHeader,+ AlertDialogTitle,+} from "@/components/ui/alert-dialog";+import { Button } from "@/components/ui/button";+import {+ Card,+ CardAction,+ CardDescription,+ CardFrame,+ CardHeader,+ CardPanel,+ CardTitle,+} from "@/components/ui/card";+import {+ Dialog,+ DialogContent,+ DialogDescription,+ DialogFooter,+ DialogHeader,+ DialogTitle,+} from "@/components/ui/dialog";+import {+ Empty,+ EmptyDescription,+ EmptyHeader,+ EmptyMedia,+ EmptyTitle,+} from "@/components/ui/empty";+import { Input } from "@/components/ui/input";+import { Label } from "@/components/ui/label";+import labelColors from "@/constants/label-colors";+import useCreateLabel from "@/hooks/mutations/label/use-create-label";+import useDeleteLabel from "@/hooks/mutations/label/use-delete-label";+import useUpdateLabel from "@/hooks/mutations/label/use-update-label";+import useGetLabelsByWorkspace from "@/hooks/queries/label/use-get-labels-by-workspace";+import { useWorkspacePermission } from "@/hooks/use-workspace-permission";+import { cn } from "@/lib/cn";+import { toast } from "@/lib/toast";++export const Route = createFileRoute(+ "/_layout/_authenticated/dashboard/settings/workspace/labels",+)({+ component: RouteComponent,+});++function RouteComponent() {+ const { t } = useTranslation();+ const { workspace, canManageLabels } = useWorkspacePermission();+ const canEdit = canManageLabels();++ const workspaceId = workspace?.id ?? "";++ const { data: labels = [] } = useGetLabelsByWorkspace(workspaceId);+ const workspaceLabels = labels.filter((label) => !label.taskId);++ const createLabel = useCreateLabel();+ const updateLabel = useUpdateLabel();+ const deleteLabel = useDeleteLabel();++ // Create dialog state+ const [createOpen, setCreateOpen] = useState(false);+ const [newName, setNewName] = useState("");+ const [newColor, setNewColor] = useState("gray");+ const [createError, setCreateError] = useState("");++ // Edit dialog state+ const [editOpen, setEditOpen] = useState(false);+ const [editingLabel, setEditingLabel] = useState<{+ id: string;+ name: string;+ color: string;+ } | null>(null);+ const [editName, setEditName] = useState("");+ const [editColor, setEditColor] = useState("gray");+ const [editError, setEditError] = useState("");++ // Delete dialog state+ const [deleteOpen, setDeleteOpen] = useState(false);+ const [deletingLabel, setDeletingLabel] = useState<{+ id: string;+ name: string;+ } | null>(null);++ const resetCreate = () => {+ setNewName("");+ setNewColor("gray");+ setCreateError("");+ };++ const openCreate = () => {+ resetCreate();+ setCreateOpen(true);+ };++ const handleCreate = async () => {+ const trimmed = newName.trim();+ if (!trimmed) {+ setCreateError(+ t("settings:workspaceLabels.nameRequired", {+ defaultValue: "Label name is required",+ }),+ );+ return;+ }++ try {+ await createLabel.mutateAsync({+ name: trimmed,+ color: newColor,+ workspaceId,+ });+ toast.success(+ t("settings:workspaceLabels.createSuccess", {+ defaultValue: "Label created",+ }),+ );+ setCreateOpen(false);+ resetCreate();+ } catch (error) {+ toast.error(+ error instanceof Error+ ? error.message+ : t("settings:workspaceLabels.createError", {+ defaultValue: "Failed to create label",+ }),+ );+ }+ };++ const openEdit = (label: { id: string; name: string; color: string }) => {+ setEditingLabel(label);+ setEditName(label.name);+ setEditColor(label.color);+ setEditError("");+ setEditOpen(true);+ };++ const handleEdit = async () => {+ if (!editingLabel) return;++ const trimmed = editName.trim();+ if (!trimmed) {+ setEditError(+ t("settings:workspaceLabels.nameRequired", {+ defaultValue: "Label name is required",+ }),+ );+ return;+ }++ try {+ await updateLabel.mutateAsync({+ id: editingLabel.id,+ name: trimmed,+ color: editColor,+ });+ toast.success(+ t("settings:workspaceLabels.updateSuccess", {+ defaultValue: "Label updated",+ }),+ );+ setEditOpen(false);+ setEditingLabel(null);+ } catch (error) {+ toast.error(+ error instanceof Error+ ? error.message+ : t("settings:workspaceLabels.updateError", {+ defaultValue: "Failed to update label",+ }),+ );+ }+ };++ const openDelete = (label: { id: string; name: string }) => {+ setDeletingLabel(label);+ setDeleteOpen(true);+ };++ const handleDelete = async () => {+ if (!deletingLabel) return;++ try {+ await deleteLabel.mutateAsync({ id: deletingLabel.id });+ toast.success(+ t("settings:workspaceLabels.deleteSuccess", {+ defaultValue: "Label deleted",+ }),+ );+ setDeleteOpen(false);+ setDeletingLabel(null);+ } catch (error) {+ toast.error(+ error instanceof Error+ ? error.message+ : t("settings:workspaceLabels.deleteError", {+ defaultValue: "Failed to delete label",+ }),+ );+ }+ };++ const getColorVar = (colorValue: string) =>+ labelColors.find((c) => c.value === colorValue)?.color ??+ "var(--color-neutral-400)";++ return (+ <>+ <PageTitle title={t("settings:workspaceLabels.pageTitle")} />+ <div className="max-w-4xl mx-auto space-y-8">+ <div className="space-y-2">+ <h1 className="text-2xl font-semibold">+ {t("settings:workspaceLabels.title", { defaultValue: "Labels" })}+ </h1>+ <p className="text-muted-foreground">+ {t("settings:workspaceLabels.subtitle", {+ defaultValue: "Create, edit, and delete workspace-level labels.",+ })}+ </p>+ </div>++ <CardFrame>+ <Card className="!rounded-none !border-t-0">+ <CardHeader>+ <CardTitle className="inline-flex items-center gap-2 text-base">+ <Tag className="size-4" />+ {t("settings:workspaceLabels.title", {+ defaultValue: "Labels",+ })}+ </CardTitle>+ <CardDescription>+ {t("settings:workspaceLabels.cardDescription", {+ defaultValue: "Manage labels that can be assigned to tasks.",+ })}+ </CardDescription>+ {canEdit && (+ <CardAction>+ <Button onClick={openCreate} className="gap-2">+ <Plus className="size-4" />+ {t("settings:workspaceLabels.createLabel", {+ defaultValue: "Create Label",+ })}+ </Button>+ </CardAction>+ )}+ </CardHeader>+ </Card>++ <Card className="!rounded-none">+ <CardPanel className="p-4">+ {workspaceLabels.length === 0 ? (+ <Empty>+ <EmptyHeader>+ <EmptyMedia>+ <Tag className="size-8 text-muted-foreground" />+ </EmptyMedia>+ <EmptyTitle>+ {t("settings:workspaceLabels.empty", {+ defaultValue:+ "No labels yet. Create your first label to get started.",+ })}+ </EmptyTitle>+ <EmptyDescription />+ </EmptyHeader>+ </Empty>+ ) : (+ <div className="divide-y divide-border">+ {workspaceLabels.map((label) => (+ <div+ key={label.id}+ className="flex items-center justify-between py-2.5 px-1"+ >+ <div className="flex items-center gap-2.5 min-w-0">+ <span+ className="w-3 h-3 rounded-full flex-shrink-0"+ style={{+ backgroundColor: getColorVar(label.color),+ }}+ />+ <span className="text-sm truncate">{label.name}</span>+ </div>+ {canEdit && (+ <div className="flex items-center gap-1 flex-shrink-0">+ <Button+ variant="ghost"+ size="icon"+ className="h-8 w-8"+ onClick={() =>+ openEdit({+ id: label.id,+ name: label.name,+ color: label.color,+ })+ }+ >+ <Pencil className="size-3.5" />+ </Button>+ <Button+ variant="ghost"+ size="icon"+ className="h-8 w-8 text-destructive hover:text-destructive"+ onClick={() =>+ openDelete({+ id: label.id,+ name: label.name,+ })+ }+ >+ <Trash2 className="size-3.5" />+ </Button>+ </div>+ )}+ </div>+ ))}+ </div>+ )}+ </CardPanel>+ </Card>+ </CardFrame>+ </div>++ {/* Create Dialog */}+ <Dialog open={createOpen} onClose={() => setCreateOpen(false)}>+ <DialogContent className="sm:max-w-md">+ <DialogHeader>+ <DialogTitle>+ {t("settings:workspaceLabels.createLabel", {+ defaultValue: "Create Label",+ })}+ </DialogTitle>+ <DialogDescription>+ {t("settings:workspaceLabels.createDescription", {+ defaultValue:+ "Create a new label that can be used across tasks in this workspace.",+ })}+ </DialogDescription>+ </DialogHeader>++ <div className="p-6 pt-1 space-y-4">+ <div className="space-y-2">+ <Label htmlFor="new-label-name">+ {t("settings:workspaceLabels.nameLabel", {+ defaultValue: "Label name",+ })}+ </Label>+ <Input+ id="new-label-name"+ value={newName}+ onChange={(e) => {+ setNewName(e.target.value);+ setCreateError("");+ }}+ placeholder={t("settings:workspaceLabels.namePlaceholder", {+ defaultValue: "Enter label name",+ })}+ onKeyDown={(e) => {+ if (e.key === "Enter") handleCreate();+ }}+ />+ {createError && (+ <p className="text-sm text-destructive">{createError}</p>+ )}+ </div>++ <div className="space-y-2">+ <Label>+ {t("settings:workspaceLabels.colorLabel", {+ defaultValue: "Color",+ })}+ </Label>+ <div className="flex flex-wrap gap-2">+ {labelColors.map((c) => (+ <button+ key={c.value}+ type="button"+ title={c.label}+ className={cn(+ "w-8 h-8 rounded-full border-2 transition-all",+ newColor === c.value+ ? "border-foreground scale-110"+ : "border-transparent hover:scale-110",+ )}+ style={{ backgroundColor: c.color }}+ onClick={() => setNewColor(c.value)}+ />+ ))}+ </div>+ </div>+ </div>++ <DialogFooter>+ <Button variant="outline" onClick={() => setCreateOpen(false)}>+ {t("common:actions.cancel", { defaultValue: "Cancel" })}+ </Button>+ <Button onClick={handleCreate} disabled={createLabel.isPending}>+ {t("settings:workspaceLabels.createLabel", {+ defaultValue: "Create Label",+ })}+ </Button>+ </DialogFooter>+ </DialogContent>+ </Dialog>++ {/* Edit Dialog */}+ <Dialog+ open={editOpen}+ onClose={() => {+ setEditOpen(false);+ setEditingLabel(null);+ }}+ >+ <DialogContent className="sm:max-w-md">+ <DialogHeader>+ <DialogTitle>+ {t("settings:workspaceLabels.editLabel", {+ defaultValue: "Edit Label",+ })}+ </DialogTitle>+ <DialogDescription>+ {t("settings:workspaceLabels.editDescription", {+ defaultValue: "Update the name or color of this label.",+ })}+ </DialogDescription>+ </DialogHeader>++ <div className="p-6 pt-1 space-y-4">+ <div className="space-y-2">+ <Label htmlFor="edit-label-name">+ {t("settings:workspaceLabels.nameLabel", {+ defaultValue: "Label name",+ })}+ </Label>+ <Input+ id="edit-label-name"+ value={editName}+ onChange={(e) => {+ setEditName(e.target.value);+ setEditError("");+ }}+ placeholder={t("settings:workspaceLabels.namePlaceholder", {+ defaultValue: "Enter label name",+ })}+ onKeyDown={(e) => {+ if (e.key === "Enter") handleEdit();+ }}+ />+ {editError && (+ <p className="text-sm text-destructive">{editError}</p>+ )}+ </div>++ <div className="space-y-2">+ <Label>+ {t("settings:workspaceLabels.colorLabel", {+ defaultValue: "Color",+ })}+ </Label>+ <div className="flex flex-wrap gap-2">+ {labelColors.map((c) => (+ <button+ key={c.value}+ type="button"+ title={c.label}+ className={cn(+ "w-8 h-8 rounded-full border-2 transition-all",+ editColor === c.value+ ? "border-foreground scale-110"+ : "border-transparent hover:scale-110",+ )}+ style={{ backgroundColor: c.color }}+ onClick={() => setEditColor(c.value)}+ />+ ))}+ </div>+ </div>+ </div>++ <DialogFooter>+ <Button+ variant="outline"+ onClick={() => {+ setEditOpen(false);+ setEditingLabel(null);+ }}+ >+ {t("common:actions.cancel", { defaultValue: "Cancel" })}+ </Button>+ <Button onClick={handleEdit} disabled={updateLabel.isPending}>+ {t("settings:workspaceLabels.saveLabel", {+ defaultValue: "Save",+ })}+ </Button>+ </DialogFooter>+ </DialogContent>+ </Dialog>++ {/* Delete Confirmation */}+ <AlertDialog+ open={deleteOpen}+ onClose={() => {+ setDeleteOpen(false);+ setDeletingLabel(null);+ }}+ >+ <AlertDialogContent>+ <AlertDialogHeader>+ <AlertDialogTitle>+ {t("settings:workspaceLabels.deleteConfirmTitle", {+ defaultValue: "Delete this label?",+ })}+ </AlertDialogTitle>+ <AlertDialogDescription>+ {t("settings:workspaceLabels.deleteConfirmDescription", {+ defaultValue:+ "This will permanently remove this label from all tasks. This action cannot be undone.",+ })}+ </AlertDialogDescription>+ </AlertDialogHeader>+ <AlertDialogFooter>+ <Button+ variant="outline"+ onClick={() => {+ setDeleteOpen(false);+ setDeletingLabel(null);+ }}+ >+ {t("common:actions.cancel", { defaultValue: "Cancel" })}+ </Button>+ <Button+ variant="destructive"+ onClick={handleDelete}+ disabled={deleteLabel.isPending}+ >+ {t("settings:workspaceLabels.deleteLabel", {+ defaultValue: "Delete",+ })}+ </Button>+ </AlertDialogFooter>+ </AlertDialogContent>+ </AlertDialog>+ </>+ );+}diff --git a/i18n/en-US.json b/i18n/en-US.jsonindex f51680cf3..57b8c72cb 100644--- a/i18n/en-US.json+++ b/i18n/en-US.json@@ -576,9 +576,9 @@"allChangesSaved": "All changes saved","saveChanges": "Save changes","defaultRoleDescriptions": {- "viewer": "Read-only access to projects, tasks, and workspace.",- "member": "Can create and update projects and tasks.",- "admin": "Full project and task management plus workspace settings."+ "viewer": "Can view and comment on tasks.",+ "member": "Can create and manage tasks and projects.",+ "admin": "Has full access to the workspace."},"resources": {"project": "Projects",@@ -589,89 +589,89 @@"permissions": {"project": {"create": {- "label": "Create projects",- "description": "Create new projects in this workspace."+ "label": "Create",+ "description": "Can create new projects"},"read": {- "label": "View projects",- "description": "View projects and their details."+ "label": "Read",+ "description": "Can view projects"},"update": {- "label": "Edit projects",- "description": "Update project name, icon, description, and settings."+ "label": "Update",+ "description": "Can edit project settings"},"delete": {- "label": "Delete projects",- "description": "Permanently delete projects in this workspace."+ "label": "Delete",+ "description": "Can delete projects"},"share": {- "label": "Share projects",- "description": "Make projects publicly accessible via share links."+ "label": "Share",+ "description": "Can share projects"}},"task": {"create": {- "label": "Create tasks",- "description": "Create new tasks in any project."+ "label": "Create",+ "description": "Can create tasks"},"read": {- "label": "View tasks",- "description": "View tasks across projects."+ "label": "Read",+ "description": "Can view tasks"},"update": {- "label": "Edit tasks",- "description": "Edit task content, status, priority, due date, and labels."+ "label": "Update",+ "description": "Can edit tasks"},"delete": {- "label": "Delete tasks",- "description": "Permanently delete tasks."+ "label": "Delete",+ "description": "Can delete tasks"},"assign": {- "label": "Assign tasks",- "description": "Assign tasks to other workspace members."+ "label": "Assign",+ "description": "Can assign tasks to members"}},"label": {"create": {- "label": "Create labels",- "description": "Add new labels to tasks in this workspace."+ "label": "Create",+ "description": "Can create labels"},"read": {- "label": "View labels",- "description": "View labels attached to tasks."+ "label": "Read",+ "description": "Can view labels"},"update": {- "label": "Edit labels",- "description": "Rename, recolor, and reassign labels."+ "label": "Update",+ "description": "Can edit labels"},"delete": {- "label": "Delete labels",- "description": "Permanently delete labels from this workspace."+ "label": "Delete",+ "description": "Can delete labels"}},"workspace": {"read": {- "label": "Access workspace",- "description": "Read workspace metadata and members."+ "label": "Read",+ "description": "Can view workspace settings"},"update": {- "label": "Edit workspace",- "description": "Edit workspace name and description."+ "label": "Update",+ "description": "Can update workspace settings"},"delete": {- "label": "Delete workspace",- "description": "Permanently delete this workspace."+ "label": "Delete",+ "description": "Can delete workspace"},"manage_settings": {- "label": "Manage settings",- "description": "Configure integrations, notification rules, and workspace preferences."+ "label": "Manage Settings",+ "description": "Can manage workspace settings"}}},"validation": {- "nameRequired": "Name is required",- "nameExists": "A role with that name already exists",- "permissionRequired": "Select at least one permission"+ "nameRequired": "Role name is required",+ "nameExists": "A role with this name already exists",+ "permissionRequired": "At least one permission must be selected"},"toast": {"created": "Role created",@@ -686,6 +686,31 @@"description": "This will permanently delete the role \"{{role}}\". Members assigned to this role will lose its permissions."}},+ "workspaceLabels": {+ "pageTitle": "Label Settings",+ "title": "Labels",+ "subtitle": "Create, edit, and delete workspace-level labels.",+ "cardDescription": "Manage labels that can be assigned to tasks.",+ "createLabel": "Create Label",+ "editLabel": "Edit Label",+ "deleteLabel": "Delete",+ "saveLabel": "Save",+ "nameLabel": "Label name",+ "namePlaceholder": "Enter label name",+ "colorLabel": "Color",+ "createDescription": "Create a new label that can be used across tasks in this workspace.",+ "editDescription": "Update the name or color of this label.",+ "deleteConfirmTitle": "Delete this label?",+ "deleteConfirmDescription": "This will permanently remove this label from all tasks. This action cannot be undone.",+ "empty": "No labels yet. Create your first label to get started.",+ "createSuccess": "Label created",+ "updateSuccess": "Label updated",+ "deleteSuccess": "Label deleted",+ "createError": "Failed to create label",+ "updateError": "Failed to update label",+ "deleteError": "Failed to delete label",+ "nameRequired": "Label name is required"+ },"projectGeneral": {"pageTitle": "Project Settings","title": "General Settings",diff --git a/i18n/schema.json b/i18n/schema.jsonindex d8cd876b2..d0011edcd 100644--- a/i18n/schema.json+++ b/i18n/schema.json@@ -2665,6 +2665,60 @@"deleteDialog"]},+ "workspaceLabels": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "pageTitle": { "type": "string" },+ "title": { "type": "string" },+ "subtitle": { "type": "string" },+ "cardDescription": { "type": "string" },+ "createLabel": { "type": "string" },+ "editLabel": { "type": "string" },+ "deleteLabel": { "type": "string" },+ "saveLabel": { "type": "string" },+ "nameLabel": { "type": "string" },+ "namePlaceholder": { "type": "string" },+ "colorLabel": { "type": "string" },+ "createDescription": { "type": "string" },+ "editDescription": { "type": "string" },+ "deleteConfirmTitle": { "type": "string" },+ "deleteConfirmDescription": { "type": "string" },+ "empty": { "type": "string" },+ "createSuccess": { "type": "string" },+ "updateSuccess": { "type": "string" },+ "deleteSuccess": { "type": "string" },+ "createError": { "type": "string" },+ "updateError": { "type": "string" },+ "deleteError": { "type": "string" },+ "nameRequired": { "type": "string" }+ },+ "required": [+ "pageTitle",+ "title",+ "subtitle",+ "cardDescription",+ "createLabel",+ "editLabel",+ "deleteLabel",+ "saveLabel",+ "nameLabel",+ "namePlaceholder",+ "colorLabel",+ "createDescription",+ "editDescription",+ "deleteConfirmTitle",+ "deleteConfirmDescription",+ "empty",+ "createSuccess",+ "updateSuccess",+ "deleteSuccess",+ "createError",+ "updateError",+ "deleteError",+ "nameRequired"+ ]+ },"projectGeneral": {"type": "object","additionalProperties": false,@@ -4557,6 +4611,7 @@"apiKey","workspaceGeneral","workspaceRoles",+ "workspaceLabels","projectGeneral","projectIntegrations","projectVisibility",