"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { useTranslations } from "next-intl"; import { Card } from "@/components/ui/card"; import type { SupportTicketCategory } from "@/types"; const CATEGORIES: SupportTicketCategory[] = [ "bug", "feature_request", "question", "billing", "other", ]; export function TicketCreateForm() { const t = useTranslations("support"); const tCommon = useTranslations("common"); const router = useRouter(); const [title, setTitle] = useState(""); const [description, setDescription] = useState(""); const [category, setCategory] = useState("question"); const [submitting, setSubmitting] = useState(false); const [error, setError] = useState(""); const onSubmit = async (e: React.FormEvent) => { e.preventDefault(); setSubmitting(true); setError(""); try { const res = await fetch("/api/support/tickets", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ title, description, category }), }); if (!res.ok) { const data = await res.json().catch(() => ({})); throw new Error(data.error || t("createFailed")); } const data = await res.json(); // Redirect to the new ticket's detail page so the customer can // see the confirmation state and immediately add follow-ups if // they wish. router.push(`/support/${data.ticket.id}`); router.refresh(); } catch (e: any) { setError(e.message); setSubmitting(false); } }; return (
setTitle(e.target.value)} placeholder={t("titlePlaceholder")} className="w-full px-3 py-2 rounded-lg border border-border bg-surface-2 text-text-primary text-sm focus:outline-none focus:border-text-secondary" />