import * as React from 'react' import { AlertCircle, Bot, CheckCircle2, Lightbulb, Send } from 'lucide-react' import { AppField } from '@/components/app/AppField' import { AppPage } from '@/components/app/AppPage' import { AppPageHeader } from '@/components/app/AppPageHeader' import { AppSection } from '@/components/app/AppSection' import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert' import { Badge } from '@/components/ui/badge' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select' import { Textarea } from '@/components/ui/textarea' import { createTicket } from './api' import type { TicketInput } from './types' const initialForm: TicketInput = { title: '', description: '', priority: 'medium', impact_scope: '', environment: '', related_system: '' } export function TicketCreatePage() { const [form, setForm] = React.useState(initialForm) const [error, setError] = React.useState('') const [submitting, setSubmitting] = React.useState(false) function updateField(field: Key, value: TicketInput[Key]) { setForm((current) => ({ ...current, [field]: value })) } async function handleSubmit(event: React.FormEvent) { event.preventDefault() setError('') setSubmitting(true) try { const ticket = await createTicket(form) window.location.hash = `/tickets/${ticket.id}` } catch (reason) { setError(reason instanceof Error ? reason.message : '创建工单失败,请检查必填信息或稍后重试。') } finally { setSubmitting(false) } } return (
{error ? ( 创建工单失败 {error} ) : null} updateField('title', event.target.value)} />
updateField('impact_scope', event.target.value)} />
updateField('related_system', event.target.value)} /> updateField('environment', event.target.value)} />