Files
kandev/apps/web/hooks/use-workflows.ts
T
2026-04-16 10:14:45 +01:00

28 lines
967 B
TypeScript

import { useEffect } from "react";
import { useAppStore } from "@/components/state-provider";
import { listWorkflows } from "@/lib/api";
export function useWorkflows(workspaceId: string | null, enabled = true) {
const workflows = useAppStore((state) => state.workflows.items);
const setWorkflows = useAppStore((state) => state.setWorkflows);
useEffect(() => {
if (!enabled || !workspaceId) return;
listWorkflows(workspaceId, { cache: "no-store" })
.then((response) => {
const mapped = response.workflows.map((workflow) => ({
id: workflow.id,
workspaceId: workflow.workspace_id,
name: workflow.name,
description: workflow.description,
sortOrder: workflow.sort_order ?? 0,
agent_profile_id: workflow.agent_profile_id,
}));
setWorkflows(mapped);
})
.catch(() => setWorkflows([]));
}, [enabled, setWorkflows, workspaceId]);
return { workflows };
}