Report Issue
Bug report and support ticket form card: Area and Severity selects, a one-line subject and a details textarea, preset to Billing and Serious and ending in a Send report button.
import { IssueReportForm } from "@/components/contact/issue-report-form"
// The copy: change text here, not in the markup.
const COPY = {
title: "Report an issue",
body: "Tell us what broke and how much it is in your way.",
} as const
const LABELS = {
area: "Area",
severity: "Severity",
select: "Select",
subject: "Subject",
subjectPlaceholder: "One line, like “Invoice shows the wrong plan”",
details: "What happened",
detailsPlaceholder:
"What you did, what you saw, and what you expected instead.",
submit: "Send report",
} as const
const AREAS = [
{ value: "team", label: "Team" },
{ value: "billing", label: "Billing" },
{ value: "account", label: "Account" },
{ value: "deployments", label: "Deployments" },
{ value: "support", label: "Support" },
]
const SEVERITIES = [
{ value: "1", label: "Blocking" },
{ value: "2", label: "Serious" },
{ value: "3", label: "Annoying" },
{ value: "4", label: "Cosmetic" },
]
export default function ReportIssue() {
return (
<IssueReportForm
title={COPY.title}
description={COPY.body}
areas={AREAS}
severities={SEVERITIES}
defaultArea="billing"
defaultSeverity="2"
labels={LABELS}
className="mx-auto w-full max-w-sm"
/>
)
}
"use client"
import {
useEffect,
useId,
useMemo,
useRef,
useTransition,
type ComponentProps,
type ReactNode,
} from "react"
import { zodResolver } from "@hookform/resolvers/zod"
import { cn } from "cn"
import { Controller, useForm } from "react-hook-form"
import { z } from "zod"
import { Button } from "@/components/ui/button"
import {
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from "@/components/ui/card"
import {
Field,
FieldError,
FieldGroup,
FieldLabel,
} from "@/components/ui/field"
import { Input } from "@/components/ui/input"
import {
Select,
SelectContent,
SelectGroup,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select"
import { Textarea } from "@/components/ui/textarea"
// shadcn's stock field: an edge on the page, a light fill only in dark
const FIELD = "border-input bg-transparent dark:bg-input/30"
// The label look: mono, uppercase, wide tracking
const LABEL =
"font-mono text-xs font-normal tracking-widest text-muted-foreground uppercase"
type IssueOption = { value: string; label: string }
type IssueReportValues = {
area: string
severity: string
subject: string
details: string
}
type IssueReportFormProps = Omit<
ComponentProps<typeof Card>,
"title" | "children"
> & {
/** The card's title. */
title: ReactNode
/** A line under the title. */
description?: ReactNode
/** The choices in the area select: a stored `value` and a shown `label`. */
areas: readonly IssueOption[]
/**
* The choices in the severity select: a stored `value` and a shown `label`.
*/
severities: readonly IssueOption[]
/** The area `value` chosen at first, and again after each reset. */
defaultArea?: string
/** The severity `value` chosen at first, and again after each reset. */
defaultSeverity?: string
/** Every word the form shows. */
labels: {
/** The area select's label. */
area: string
/** The severity select's label. */
severity: string
/** Shown in both selects before a choice. */
select: string
/** The subject field's label. */
subject: string
/** Text inside the empty subject field. */
subjectPlaceholder: string
/** The details field's label. */
details: string
/** Text inside the empty details field. */
detailsPlaceholder: string
/** The submit button's text. */
submit: ReactNode
/** Shown under a field left empty; one message serves all four. */
required?: string
}
/**
* Receives validated FormData as a React Action. Fields reset after the
* transition completes, including work queued by a useActionState dispatch.
*/
action?: (formData: FormData) => void | Promise<void>
}
/**
* A card with a form for reporting an issue: area, severity, subject and
* details. The area and severity fields sit side by side from the `sm`
* breakpoint.
*/
function IssueReportForm({
title,
description,
areas,
severities,
defaultArea,
defaultSeverity,
labels,
action,
className,
...props
}: IssueReportFormProps) {
const id = useId()
const [pending, startTransition] = useTransition()
const resetAfterAction = useRef(false)
const required = labels.required ?? "Required."
const schema = useMemo(
() =>
z.object({
area: z.string().min(1, required),
severity: z.string().min(1, required),
subject: z.string().trim().min(1, required),
details: z.string().trim().min(1, required),
}),
[required]
)
const form = useForm<IssueReportValues>({
resolver: zodResolver(schema),
defaultValues: {
area: defaultArea ?? "",
severity: defaultSeverity ?? "",
subject: "",
details: "",
},
})
const { reset } = form
useEffect(() => {
if (pending || !resetAfterAction.current) return
resetAfterAction.current = false
reset()
}, [pending, reset])
function onSubmit(values: IssueReportValues) {
if (!action) return
const formData = new FormData()
for (const [key, value] of Object.entries(values)) formData.set(key, value)
startTransition(async () => {
await action(formData)
resetAfterAction.current = true
})
}
return (
<Card
data-slot="issue-report-form"
className={cn("gap-8", className)}
{...props}
>
<CardHeader>
<CardTitle>{title}</CardTitle>
{description != null && (
<CardDescription>{description}</CardDescription>
)}
</CardHeader>
<CardContent>
<form
id={`form-${id}`}
onSubmit={form.handleSubmit(onSubmit)}
noValidate
>
<FieldGroup>
<FieldGroup className="grid gap-4 sm:grid-cols-2">
<Controller
name="area"
control={form.control}
render={({ field, fieldState }) => (
<Field data-invalid={fieldState.invalid}>
<FieldLabel htmlFor={`area-${id}`} className={LABEL}>
{labels.area}
</FieldLabel>
<Select
name={field.name}
items={areas}
value={field.value || null}
onValueChange={(value) => field.onChange(value ?? "")}
>
<SelectTrigger
ref={field.ref}
id={`area-${id}`}
aria-label={labels.area}
aria-invalid={fieldState.invalid}
className={`${FIELD} w-full`}
onBlur={field.onBlur}
>
<SelectValue placeholder={labels.select} />
</SelectTrigger>
<SelectContent>
<SelectGroup>
{areas.map((area) => (
<SelectItem key={area.value} value={area.value}>
{area.label}
</SelectItem>
))}
</SelectGroup>
</SelectContent>
</Select>
<FieldError errors={[fieldState.error]} />
</Field>
)}
/>
<Controller
name="severity"
control={form.control}
render={({ field, fieldState }) => (
<Field data-invalid={fieldState.invalid}>
<FieldLabel htmlFor={`severity-${id}`} className={LABEL}>
{labels.severity}
</FieldLabel>
<Select
name={field.name}
items={severities}
value={field.value || null}
onValueChange={(value) => field.onChange(value ?? "")}
>
<SelectTrigger
ref={field.ref}
id={`severity-${id}`}
aria-label={labels.severity}
aria-invalid={fieldState.invalid}
className={`${FIELD} w-full`}
onBlur={field.onBlur}
>
<SelectValue placeholder={labels.select} />
</SelectTrigger>
<SelectContent>
<SelectGroup>
{severities.map((severity) => (
<SelectItem
key={severity.value}
value={severity.value}
>
{severity.label}
</SelectItem>
))}
</SelectGroup>
</SelectContent>
</Select>
<FieldError errors={[fieldState.error]} />
</Field>
)}
/>
</FieldGroup>
<Controller
name="subject"
control={form.control}
render={({ field, fieldState }) => (
<Field data-invalid={fieldState.invalid}>
<FieldLabel htmlFor={`subject-${id}`} className={LABEL}>
{labels.subject}
</FieldLabel>
<Input
{...field}
className={FIELD}
id={`subject-${id}`}
placeholder={labels.subjectPlaceholder}
aria-invalid={fieldState.invalid}
/>
<FieldError errors={[fieldState.error]} />
</Field>
)}
/>
<Controller
name="details"
control={form.control}
render={({ field, fieldState }) => (
<Field data-invalid={fieldState.invalid}>
<FieldLabel htmlFor={`details-${id}`} className={LABEL}>
{labels.details}
</FieldLabel>
<Textarea
{...field}
id={`details-${id}`}
placeholder={labels.detailsPlaceholder}
className={`${FIELD} min-h-24`}
aria-invalid={fieldState.invalid}
/>
<FieldError errors={[fieldState.error]} />
</Field>
)}
/>
</FieldGroup>
</form>
</CardContent>
<CardFooter>
<Button
type="submit"
form={`form-${id}`}
className="w-full"
size="lg"
disabled={pending}
>
{labels.submit}
</Button>
</CardFooter>
</Card>
)
}
export { IssueReportForm }
Installation
pnpm dlx shadcn@latest add @01orbital/report-issuenpx shadcn@latest add @01orbital/report-issueyarn dlx shadcn@latest add @01orbital/report-issuebunx --bun shadcn@latest add @01orbital/report-issueMake it yours
- Its words are in
COPYat the top ofcomponents/blocks/contact/report-issue/index.tsx: change them there, not in the markup. LABELS,AREASandSEVERITIES, also at the top of the file, hold its lists and settings.
Built from
Built from these parts. The CLI adds each one that is missing and won't replace a file you already have unless you choose to:
Last updated on