'use client' import { useState } from 'react' import { trpc } from '@/lib/trpc/client' import { AlertDialog, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from '@/components/ui/alert-dialog' import { Button } from '@/components/ui/button' import { Label } from '@/components/ui/label' import { Textarea } from '@/components/ui/textarea' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@/components/ui/select' import { Loader2, ShieldAlert } from 'lucide-react' import { toast } from 'sonner' interface COIDeclarationDialogProps { open: boolean assignmentId: string projectTitle: string onComplete: (hasConflict: boolean) => void } export function COIDeclarationDialog({ open, assignmentId, projectTitle, onComplete, }: COIDeclarationDialogProps) { const [hasConflict, setHasConflict] = useState(null) const [conflictType, setConflictType] = useState('') const [description, setDescription] = useState('') const declareCOI = trpc.evaluation.declareCOI.useMutation({ onSuccess: (data) => { if (data.hasConflict) { toast.info('Conflict of interest recorded. An admin will review your declaration.') } onComplete(data.hasConflict) }, onError: (error) => { toast.error(error.message || 'Failed to submit COI declaration') }, }) const handleSubmit = () => { if (hasConflict === null) return declareCOI.mutate({ assignmentId, hasConflict, conflictType: hasConflict ? conflictType : undefined, description: hasConflict ? description : undefined, }) } const canSubmit = hasConflict !== null && (!hasConflict || (hasConflict && conflictType)) && !declareCOI.isPending return ( Conflict of Interest Declaration Before evaluating “{projectTitle}”, please declare whether you have any conflict of interest with this project.
{hasConflict && ( <>