diff --git a/src/components/collections/apply-collection-workflow-dialog.tsx b/src/components/collections/apply-collection-workflow-dialog.tsx index e725b46..eb76263 100644 --- a/src/components/collections/apply-collection-workflow-dialog.tsx +++ b/src/components/collections/apply-collection-workflow-dialog.tsx @@ -50,6 +50,7 @@ export function ApplyCollectionWorkflowDialog({ supabase .from("workflow_templates") .select("id, name") + .eq("kind", "collection") .order("name") .then(({ data }) => setTemplates((data ?? []) as Template[])); setTemplateId(null); diff --git a/src/components/tasks/apply-workflow-dialog.tsx b/src/components/tasks/apply-workflow-dialog.tsx index e55754a..0fe0421 100644 --- a/src/components/tasks/apply-workflow-dialog.tsx +++ b/src/components/tasks/apply-workflow-dialog.tsx @@ -51,6 +51,7 @@ export function ApplyWorkflowDialog({ supabase .from("workflow_templates") .select("id, name") + .eq("kind", "task") .order("name") .then(({ data }) => setTemplates((data ?? []) as Template[])); setTemplateId(null); diff --git a/src/components/tasks/apply-workflow-picker-dialog.tsx b/src/components/tasks/apply-workflow-picker-dialog.tsx index cf84d08..edd33e0 100644 --- a/src/components/tasks/apply-workflow-picker-dialog.tsx +++ b/src/components/tasks/apply-workflow-picker-dialog.tsx @@ -61,7 +61,7 @@ export function ApplyWorkflowPickerDialog({ setCaseId(null); setStartDate(new Date()); Promise.all([ - supabase.from("workflow_templates").select("id, name").order("name"), + supabase.from("workflow_templates").select("id, name").eq("kind", "task").order("name"), supabase .from("cases") .select("id, case_number, title") diff --git a/src/integrations/supabase/types.ts b/src/integrations/supabase/types.ts index 8107b43..cf66644 100644 --- a/src/integrations/supabase/types.ts +++ b/src/integrations/supabase/types.ts @@ -3013,6 +3013,7 @@ export type Database = { created_by: string | null description: string | null id: string + kind: string name: string updated_at: string } @@ -3021,6 +3022,7 @@ export type Database = { created_by?: string | null description?: string | null id?: string + kind?: string name: string updated_at?: string } @@ -3029,6 +3031,7 @@ export type Database = { created_by?: string | null description?: string | null id?: string + kind?: string name?: string updated_at?: string } diff --git a/src/routes/settings.workflows.tsx b/src/routes/settings.workflows.tsx index 4137aaf..3cef2da 100644 --- a/src/routes/settings.workflows.tsx +++ b/src/routes/settings.workflows.tsx @@ -32,6 +32,7 @@ interface Template { name: string; description: string | null; created_by: string | null; + kind: "task" | "collection"; } interface TemplateTask { id: string; @@ -58,6 +59,7 @@ function WorkflowsPage() { const [newOpen, setNewOpen] = useState(false); const [newName, setNewName] = useState(""); const [newDesc, setNewDesc] = useState(""); + const [newKind, setNewKind] = useState<"task" | "collection">("task"); const [newTask, setNewTask] = useState({ title: "", days: 7, priority: "normal" as const }); const loadTemplates = useCallback(async () => { @@ -95,7 +97,12 @@ function WorkflowsPage() { if (!user || !newName.trim()) return; const { data, error } = await supabase .from("workflow_templates") - .insert({ name: newName.trim(), description: newDesc.trim() || null, created_by: user.id }) + .insert({ + name: newName.trim(), + description: newDesc.trim() || null, + kind: newKind, + created_by: user.id, + }) .select() .single(); if (error) { @@ -104,11 +111,18 @@ function WorkflowsPage() { } setNewName(""); setNewDesc(""); + setNewKind("task"); setNewOpen(false); await loadTemplates(); setSelected(data as Template); }; + const updateTemplateKind = async (id: string, kind: "task" | "collection") => { + await supabase.from("workflow_templates").update({ kind }).eq("id", id); + await loadTemplates(); + if (selected?.id === id) setSelected({ ...selected, kind }); + }; + const deleteTemplate = async (id: string) => { if (!confirm("Delete this workflow template?")) return; await supabase.from("workflow_templates").delete().eq("id", id); @@ -167,7 +181,16 @@ function WorkflowsPage() { selected?.id === t.id ? "bg-accent" : "" }`} > -
{t.name}
+
+
{t.name}
+ + {t.kind === "collection" ? "Collection" : "Task"} + +
{t.description &&
{t.description}
} ))} @@ -181,16 +204,31 @@ function WorkflowsPage() { ) : (
-
-
-
{selected.name}
+
+
+
{selected.name}
{selected.description && ( -
{selected.description}
+
{selected.description}
)}
- +
+ + + +
{tasks.map((t) => ( @@ -283,6 +321,18 @@ function WorkflowsPage() {