import { useState } from "react" import { useNavigate } from "react-router-dom" import { useQueryClient } from "@tanstack/react-query" import { Check } from "lucide-react" import { apiClient } from "@/services/api/client" import type { ComponentDetail } from "@/types" import { ComponentFields } from "@/components/ComponentFields" interface ConfigPanelProps { component: ComponentDetail configSection: "services" | "jobs" | "components" onRefetch: () => void } export function ConfigPanel({ component, configSection, onRefetch }: ConfigPanelProps) { const navigate = useNavigate() const qc = useQueryClient() const [message, setMessage] = useState<{ type: "ok" | "error"; text: string } | null>(null) const handleSave = async (compName: string, config: Record) => { setMessage(null) try { await apiClient.put(`/config/${configSection}/${compName}`, { config }) setMessage({ type: "ok", text: "Saved to castle.yaml" }) onRefetch() qc.invalidateQueries({ queryKey: ["components"] }) } catch (e: unknown) { const msg = e instanceof Error ? e.message : String(e) setMessage({ type: "error", text: msg }) } } const handleDelete = async (compName: string) => { try { await apiClient.delete(`/config/${configSection}/${compName}`) qc.invalidateQueries({ queryKey: ["components"] }) navigate("/") } catch (e: unknown) { const msg = e instanceof Error ? e.message : String(e) setMessage({ type: "error", text: msg }) } } return ( <> {message && (
{message.type === "ok" && } {message.text}
)}

Configuration

) }