import { Show, createEffect, createSignal } from "solid-js"; import { patchSchool } from "@/api/schools"; import { formatApiError, type School, type SchoolStatus } from "@/api/client"; import { Alert } from "@/components/ui/alert"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Select } from "@/components/ui/select"; import { SidePanel } from "@/components/ui/side-panel"; import { useT } from "@/stores/preferences-context"; /** * A tenant school's edit form (name, status). One component for the builder * school detail header and the builder schools list's row menu, so both send * the same PATCH. The panel closes itself on success; the caller refetches * and shows its own flash in `onSaved`. */ export function SchoolEditPanel(props: { school: School | null; open: boolean; onOpenChange: (open: boolean) => void; onSaved: () => void | Promise; }) { const t = useT(); const [name, setName] = createSignal(""); const [status, setStatus] = createSignal("active"); const [error, setError] = createSignal(""); const [pending, setPending] = createSignal(false); // Seed the form each time it opens, from the school it opens for. createEffect(() => { const current = props.school; if (!props.open || !current) return; setName(current.name); setStatus(current.status); setError(""); }); const submit = async (event: SubmitEvent) => { event.preventDefault(); const current = props.school; if (!current || pending()) return; setError(""); setPending(true); try { await patchSchool(current.id, { name: name().trim(), status: status() }); props.onOpenChange(false); await props.onSaved(); } catch (err) { setError(formatApiError(err)); } finally { setPending(false); } }; return (
{error()}
setName(e.currentTarget.value)} />

{t("builder.suspendHint")}

); }