"use client"; import { useEffect, useMemo, useState } from "react"; import { Check, Loader2, Search } from "lucide-react"; import { listWorkflows } from "@/app/lib/mikeApi"; import { Modal } from "@/app/components/shared/Modal"; import type { Workflow } from "@/app/components/shared/types"; import { BUILT_IN_WORKFLOWS } from "../workflows/builtinWorkflows"; import { cn } from "@/lib/utils"; interface Props { open: boolean; applying?: boolean; onClose: () => void; onApply: (workflow: Workflow) => Promise | void; } export function ApplyWorkflowPresetModal({ open, applying = false, onClose, onApply, }: Props) { const [workflows, setWorkflows] = useState([]); const [selectedWorkflowId, setSelectedWorkflowId] = useState( null, ); const [search, setSearch] = useState(""); const [loading, setLoading] = useState(false); useEffect(() => { if (!open) return; const builtinTabular = BUILT_IN_WORKFLOWS.filter( (workflow) => workflow.type === "tabular", ); setLoading(true); setSearch(""); setSelectedWorkflowId(null); listWorkflows("tabular") .then((custom) => setWorkflows([...builtinTabular, ...custom])) .catch(() => setWorkflows(builtinTabular)) .finally(() => setLoading(false)); }, [open]); const filteredWorkflows = useMemo(() => { const q = search.trim().toLowerCase(); if (!q) return workflows; return workflows.filter((workflow) => [workflow.title, workflow.practice ?? ""] .join(" ") .toLowerCase() .includes(q), ); }, [search, workflows]); const selectedWorkflow = workflows.find((workflow) => workflow.id === selectedWorkflowId) ?? null; const canApply = !!selectedWorkflow && !applying && !loading && !!selectedWorkflow.columns_config?.length; return ( { if (selectedWorkflow) void onApply(selectedWorkflow); }, disabled: !canApply, icon: applying ? ( ) : undefined, }} cancelAction={{ label: "Cancel", onClick: onClose }} >

Choose a tabular review workflow. Applying it will replace the current review columns with the workflow preset.

setSearch(event.target.value)} placeholder="Search workflows..." className="min-w-0 flex-1 bg-transparent text-sm text-gray-800 outline-none placeholder:text-gray-400" />
{loading ? (
{[1, 2, 3, 4].map((index) => (
))}
) : filteredWorkflows.length === 0 ? (
No workflows found
) : ( filteredWorkflows.map((workflow) => { const selected = workflow.id === selectedWorkflowId; const columnCount = workflow.columns_config?.length ?? 0; return ( ); }) )}
); }