import { useState } from 'react'; import { useQueryClient } from '@tanstack/react-query'; import { X } from 'lucide-react'; import { toast } from 'sonner'; import { Button } from '@/components/ui/button'; import { useClient } from 'hooks/useClient'; import { usePanelChannel } from 'hooks/usePanelChannel'; import type { AutomationSelection } from './AutomationRightPanel'; type NewSkillProps = { selection: NonNullable; }; export const NewSkill = ({ selection }: NewSkillProps) => { const client = useClient(); const qc = useQueryClient(); const [, setSelection] = usePanelChannel('automation:selected-capability', null); const [name, setName] = useState(''); const [description, setDescription] = useState(''); const [submitting, setSubmitting] = useState(false); const handleCreate = async () => { const trimmed = name.trim(); if (!trimmed) return; setSubmitting(true); try { const res = await client.post<{ name: string; dirName: string }>(selection.endpoint, { name: trimmed }); await qc.invalidateQueries({ queryKey: [selection.queryKey] }); setSelection({ kind: selection.kind, endpoint: selection.endpoint, queryKey: selection.queryKey, dirName: res.dirName, isNew: true, editing: true, description: description.trim() || undefined, }); } catch { toast.error('Failed to create skill'); setSubmitting(false); } }; return (
New Skill
setName(ev.target.value)} onKeyDown={(ev) => { if (ev.key === 'Enter') { ev.preventDefault(); handleCreate(); } }} placeholder="Skill name..." autoFocus className="rounded border border-duck-dark/20 dark:border-foreground/20 bg-background px-3 py-2 text-sm text-duck-dark dark:text-foreground placeholder:text-duck-dark/30 dark:placeholder:text-foreground/30 focus:outline-none focus:ring-1 focus:ring-duck-teal/30" />