src/registry/default/templates/support-ticket-form.tsx
"use client";
import { useForm, Controller } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import * as z from "zod";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { toast } from "sonner";
import { Textarea } from "@/components/ui/textarea";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
const formSchema = z.object({
email: z.string().email("Invalid email address").min(1, "Contact Email is required"),
category: z.enum(["bug", "feature", "billing", "other"]),
priority: z.enum(["low", "medium", "high", "urgent"]),
subject: z.string().min(1, "Subject is required"),
description: z.string().min(1, "Description is required"),
});
type FormValues = z.infer<typeof formSchema>;
export function SupportTicketForm() {
const form = useForm<FormValues>({
resolver: zodResolver(formSchema),
defaultValues: {
email: "",
category: "bug",
priority: "low",
subject: "",
description: "",
},
});
const onSubmit = async (data: FormValues) => {
console.log("Form submitted:", data);
toast.success("Form submitted successfully!");
};
return (
<Card className="w-full max-w-md mx-auto">
<CardHeader>
<CardTitle>Support Ticket</CardTitle>
<CardDescription>Submit a support request or bug report</CardDescription>
</CardHeader>
<CardContent>
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
<div className="space-y-2">
<Label htmlFor="email">Contact Email</Label>
<Input
id="email"
type="email"
placeholder="you@company.com"
{...form.register("email")}
/>
{form.formState.errors.email && (
<p className="text-sm text-destructive">{form.formState.errors.email.message}</p>
)}
</div>
<div className="space-y-2">
<Label htmlFor="category">Issue Category</Label>
<Controller
control={form.control}
name="category"
render={({ field }) => (
<Select onValueChange={field.onChange} defaultValue={field.value}>
<SelectTrigger id="category">
<SelectValue placeholder="Select an option" />
</SelectTrigger>
<SelectContent>
<SelectItem value="bug">Bug Report</SelectItem>
<SelectItem value="feature">Feature Request</SelectItem>
<SelectItem value="billing">Billing</SelectItem>
<SelectItem value="other">Other</SelectItem>
</SelectContent>
</Select>
)}
/>
{form.formState.errors.category && (
<p className="text-sm text-destructive">{form.formState.errors.category.message}</p>
)}
</div>
<div className="space-y-2">
<Label>Priority Level</Label>
<Controller
control={form.control}
name="priority"
render={({ field }) => (
<RadioGroup
onValueChange={field.onChange}
defaultValue={field.value}
className="flex flex-col space-y-1"
>
<div className="flex items-center space-x-2">
<RadioGroupItem value="low" id="priority-low" />
<Label htmlFor="priority-low">Low</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="medium" id="priority-medium" />
<Label htmlFor="priority-medium">Medium</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="high" id="priority-high" />
<Label htmlFor="priority-high">High</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="urgent" id="priority-urgent" />
<Label htmlFor="priority-urgent">Urgent</Label>
</div>
</RadioGroup>
)}
/>
{form.formState.errors.priority && (
<p className="text-sm text-destructive">{form.formState.errors.priority.message}</p>
)}
</div>
<div className="space-y-2">
<Label htmlFor="subject">Subject</Label>
<Input
id="subject"
type="text"
placeholder="Brief summary of the issue"
{...form.register("subject")}
/>
{form.formState.errors.subject && (
<p className="text-sm text-destructive">{form.formState.errors.subject.message}</p>
)}
</div>
<div className="space-y-2">
<Label htmlFor="description">Description</Label>
<Textarea
id="description"
placeholder="Please describe the issue in detail..."
{...form.register("description")}
/>
{form.formState.errors.description && (
<p className="text-sm text-destructive">{form.formState.errors.description.message}</p>
)}
<p className="text-sm text-muted-foreground">Include steps to reproduce if applicable</p>
</div>
<Button type="submit" className="w-full">Submit</Button>
</form>
</CardContent>
</Card>
);
}
































