"use client"; import * as React from "react"; import { useRouter } from "next/navigation"; import { CheckCircle2, Plus, Undo2 } from "lucide-react"; import { createIncident, resolveIncident } from "@/actions/admin"; import { Button } from "@/components/ui/button"; import { Input, NativeSelect, Textarea } from "@/components/ui/input"; import { Field, Hint, Label } from "@/components/ui/label"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog"; import { ActionButton } from "./action-button"; const COMPONENTS = ["api", "dashboard", "residential", "datacenter", "isp", "mobile", "sessions", "billing", "website"]; export function ResolveIncidentButton({ id, resolved }: { id: string; resolved: boolean }) { return resolved ? ( resolveIncident(id, false)}> Reopen ) : ( resolveIncident(id, true)}> Resolve ); } export function NewIncidentDialog() { const router = useRouter(); const [open, setOpen] = React.useState(false); const [pending, start] = React.useTransition(); const [error, setError] = React.useState(null); const [form, setForm] = React.useState({ component: "api", severity: "minor", title: "", body: "" }); const set = (k: keyof typeof form) => (e: React.ChangeEvent) => setForm((f) => ({ ...f, [k]: e.target.value })); return ( <> setOpen(true)}> Open incident Open a status incident Published immediately on the public /status page. Write for customers: describe impact and workaround, never upstream provider names. { e.preventDefault(); start(async () => { setError(null); const r = await createIncident(form as Parameters[0]); if (!r.ok) return setError(r.error); setOpen(false); setForm({ component: "api", severity: "minor", title: "", body: "" }); router.refresh(); }); }} > Component {COMPONENTS.map((c) => ( {c} ))} Severity minor major critical maintenance Title Update Public. Uses network classes only. {error ? ( {error} ) : null} setOpen(false)}> Cancel Publish > ); }
{error}