'use client'; import { useState, type FormEvent } from 'react'; import { Loader2, Trash2 } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Dialog, DialogBody, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from '@/components/ui/dialog'; import { Label } from '@/components/ui/label'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@/components/ui/select'; import { Textarea } from '@/components/ui/textarea'; import type { DetectionDiscardReason, DiscardDetectionPayload } from '@/types'; const DISCARD_REASON_OPTIONS: Array<{ value: DetectionDiscardReason; label: string; }> = [ { value: 'not_a_defect', label: 'Not a defect' }, { value: 'wrong_class', label: 'Wrong classification' }, { value: 'duplicate', label: 'Duplicate detection' }, { value: 'poor_image_quality', label: 'Poor image quality' }, { value: 'incorrect_location', label: 'Incorrect location' }, { value: 'already_repaired', label: 'Already repaired' }, { value: 'other', label: 'Other' }, ]; interface DetectionDiscardDialogProps { open: boolean; detectionLabel: string; isPending: boolean; onOpenChange: (open: boolean) => void; onSubmit: (payload: DiscardDetectionPayload) => Promise; } export function DetectionDiscardDialog({ open, detectionLabel, isPending, onOpenChange, onSubmit, }: DetectionDiscardDialogProps) { const [reason, setReason] = useState(''); const [comment, setComment] = useState(''); const resetForm = () => { setReason(''); setComment(''); }; const handleOpenChange = (nextOpen: boolean) => { if (isPending) return; if (!nextOpen) resetForm(); onOpenChange(nextOpen); }; const handleSubmit = async (event: FormEvent) => { event.preventDefault(); if (!reason || isPending) return; try { await onSubmit({ reason, comment: comment.trim() || undefined, }); resetForm(); } catch { // The mutation displays the request error and keeps the dialog open. } }; return (
Discard detection Remove {detectionLabel} from this ticket and record why the AI result is incorrect.
Optional | {comment.length}/500