Round detail overhaul, file requirements, project management, audit log fix
All checks were successful
Build and Push Docker Image / build (push) Successful in 7m32s
All checks were successful
Build and Push Docker Image / build (push) Successful in 7m32s
- Redesign round detail page with 6 tabs (overview, projects, filtering, assignments, config, documents) - Add jury group assignment selector in round stats bar - Add FileRequirementsEditor component replacing SubmissionWindowManager - Add FilteringDashboard component for AI-powered project screening - Add project removal from rounds (single + bulk) with cascading to subsequent rounds - Add project add/remove UI in ProjectStatesTable with confirmation dialogs - Fix logAudit inside $transaction pattern across all 12 router files (PostgreSQL aborted-transaction state caused silent operation failures) - Fix special awards creation, deletion, status update, and winner assignment Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
399
src/components/admin/round/file-requirements-editor.tsx
Normal file
399
src/components/admin/round/file-requirements-editor.tsx
Normal file
@@ -0,0 +1,399 @@
|
||||
'use client'
|
||||
|
||||
import { useState } from 'react'
|
||||
import { trpc } from '@/lib/trpc/client'
|
||||
import { toast } from 'sonner'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Textarea } from '@/components/ui/textarea'
|
||||
import { Checkbox } from '@/components/ui/checkbox'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
AlertDialogTrigger,
|
||||
} from '@/components/ui/alert-dialog'
|
||||
import {
|
||||
Loader2,
|
||||
Plus,
|
||||
Pencil,
|
||||
Trash2,
|
||||
FileText,
|
||||
GripVertical,
|
||||
FileCheck,
|
||||
FileQuestion,
|
||||
} from 'lucide-react'
|
||||
|
||||
type FileRequirementsEditorProps = {
|
||||
roundId: string
|
||||
windowOpenAt?: Date | string | null
|
||||
windowCloseAt?: Date | string | null
|
||||
}
|
||||
|
||||
type FormState = {
|
||||
name: string
|
||||
description: string
|
||||
acceptedMimeTypes: string
|
||||
maxSizeMB: string
|
||||
isRequired: boolean
|
||||
}
|
||||
|
||||
const emptyForm: FormState = {
|
||||
name: '',
|
||||
description: '',
|
||||
acceptedMimeTypes: '',
|
||||
maxSizeMB: '',
|
||||
isRequired: true,
|
||||
}
|
||||
|
||||
const COMMON_MIME_PRESETS: { label: string; value: string }[] = [
|
||||
{ label: 'PDF only', value: 'application/pdf' },
|
||||
{ label: 'Images', value: 'image/png, image/jpeg, image/webp' },
|
||||
{ label: 'Video', value: 'video/mp4, video/quicktime, video/webm' },
|
||||
{ label: 'Documents', value: 'application/pdf, application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document' },
|
||||
{ label: 'Spreadsheets', value: 'application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, text/csv' },
|
||||
{ label: 'Presentations', value: 'application/vnd.ms-powerpoint, application/vnd.openxmlformats-officedocument.presentationml.presentation' },
|
||||
{ label: 'Any file', value: '' },
|
||||
]
|
||||
|
||||
export function FileRequirementsEditor({ roundId, windowOpenAt, windowCloseAt }: FileRequirementsEditorProps) {
|
||||
const [dialogOpen, setDialogOpen] = useState(false)
|
||||
const [editingId, setEditingId] = useState<string | null>(null)
|
||||
const [form, setForm] = useState<FormState>(emptyForm)
|
||||
|
||||
const utils = trpc.useUtils()
|
||||
|
||||
const { data: requirements, isLoading } = trpc.file.listRequirements.useQuery({ roundId })
|
||||
|
||||
const createMutation = trpc.file.createRequirement.useMutation({
|
||||
onSuccess: () => {
|
||||
utils.file.listRequirements.invalidate({ roundId })
|
||||
toast.success('Requirement added')
|
||||
closeDialog()
|
||||
},
|
||||
onError: (err) => toast.error(err.message),
|
||||
})
|
||||
|
||||
const updateMutation = trpc.file.updateRequirement.useMutation({
|
||||
onSuccess: () => {
|
||||
utils.file.listRequirements.invalidate({ roundId })
|
||||
toast.success('Requirement updated')
|
||||
closeDialog()
|
||||
},
|
||||
onError: (err) => toast.error(err.message),
|
||||
})
|
||||
|
||||
const deleteMutation = trpc.file.deleteRequirement.useMutation({
|
||||
onSuccess: () => {
|
||||
utils.file.listRequirements.invalidate({ roundId })
|
||||
toast.success('Requirement removed')
|
||||
},
|
||||
onError: (err) => toast.error(err.message),
|
||||
})
|
||||
|
||||
const closeDialog = () => {
|
||||
setDialogOpen(false)
|
||||
setEditingId(null)
|
||||
setForm(emptyForm)
|
||||
}
|
||||
|
||||
const openCreateDialog = () => {
|
||||
setForm(emptyForm)
|
||||
setEditingId(null)
|
||||
setDialogOpen(true)
|
||||
}
|
||||
|
||||
const openEditDialog = (req: any) => {
|
||||
setForm({
|
||||
name: req.name,
|
||||
description: req.description || '',
|
||||
acceptedMimeTypes: (req.acceptedMimeTypes || []).join(', '),
|
||||
maxSizeMB: req.maxSizeMB?.toString() || '',
|
||||
isRequired: req.isRequired ?? true,
|
||||
})
|
||||
setEditingId(req.id)
|
||||
setDialogOpen(true)
|
||||
}
|
||||
|
||||
const handleSubmit = () => {
|
||||
const mimeTypes = form.acceptedMimeTypes
|
||||
.split(',')
|
||||
.map((s) => s.trim())
|
||||
.filter(Boolean)
|
||||
|
||||
const maxSize = form.maxSizeMB ? parseInt(form.maxSizeMB, 10) : undefined
|
||||
|
||||
if (editingId) {
|
||||
updateMutation.mutate({
|
||||
id: editingId,
|
||||
name: form.name,
|
||||
description: form.description || null,
|
||||
acceptedMimeTypes: mimeTypes,
|
||||
maxSizeMB: maxSize ?? null,
|
||||
isRequired: form.isRequired,
|
||||
})
|
||||
} else {
|
||||
createMutation.mutate({
|
||||
roundId,
|
||||
name: form.name,
|
||||
description: form.description || undefined,
|
||||
acceptedMimeTypes: mimeTypes,
|
||||
maxSizeMB: maxSize,
|
||||
isRequired: form.isRequired,
|
||||
sortOrder: (requirements?.length ?? 0),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const isSaving = createMutation.isPending || updateMutation.isPending
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<Skeleton className="h-10 w-full" />
|
||||
{[1, 2, 3].map((i) => <Skeleton key={i} className="h-20 w-full" />)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
{/* Submission period info */}
|
||||
<Card>
|
||||
<CardContent className="pt-4 pb-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<p className="text-sm font-medium">Submission Period</p>
|
||||
<p className="text-xs text-muted-foreground mt-0.5">
|
||||
Applicants can upload documents during the round's active window
|
||||
</p>
|
||||
</div>
|
||||
<div className="text-right text-sm">
|
||||
{windowOpenAt || windowCloseAt ? (
|
||||
<>
|
||||
<p className="font-medium">
|
||||
{windowOpenAt ? new Date(windowOpenAt).toLocaleDateString() : 'No start'} —{' '}
|
||||
{windowCloseAt ? new Date(windowCloseAt).toLocaleDateString() : 'No deadline'}
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Set in the Config tab under round time windows
|
||||
</p>
|
||||
</>
|
||||
) : (
|
||||
<p className="text-muted-foreground">No dates configured — set in Config tab</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Requirements list */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<CardTitle className="text-base">Required Documents</CardTitle>
|
||||
<CardDescription>
|
||||
Define what files applicants must submit for this round
|
||||
</CardDescription>
|
||||
</div>
|
||||
<Button size="sm" onClick={openCreateDialog}>
|
||||
<Plus className="h-4 w-4 mr-1.5" />
|
||||
Add Requirement
|
||||
</Button>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{!requirements || requirements.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center py-10 text-center">
|
||||
<div className="rounded-full bg-muted p-4 mb-4">
|
||||
<FileText className="h-8 w-8 text-muted-foreground" />
|
||||
</div>
|
||||
<p className="text-sm font-medium">No Document Requirements</p>
|
||||
<p className="text-xs text-muted-foreground mt-1 max-w-sm">
|
||||
Add requirements to specify what documents applicants must upload during this round.
|
||||
</p>
|
||||
<Button size="sm" variant="outline" className="mt-4" onClick={openCreateDialog}>
|
||||
<Plus className="h-4 w-4 mr-1.5" />
|
||||
Add First Requirement
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-2">
|
||||
{requirements.map((req: any) => (
|
||||
<div
|
||||
key={req.id}
|
||||
className="flex items-start gap-3 p-3 rounded-lg border hover:bg-muted/30 transition-colors"
|
||||
>
|
||||
<div className="mt-0.5 text-muted-foreground">
|
||||
{req.isRequired ? (
|
||||
<FileCheck className="h-4 w-4 text-blue-500" />
|
||||
) : (
|
||||
<FileQuestion className="h-4 w-4 text-gray-400" />
|
||||
)}
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-2">
|
||||
<p className="text-sm font-medium">{req.name}</p>
|
||||
<Badge variant={req.isRequired ? 'default' : 'secondary'} className="text-[10px]">
|
||||
{req.isRequired ? 'Required' : 'Optional'}
|
||||
</Badge>
|
||||
</div>
|
||||
{req.description && (
|
||||
<p className="text-xs text-muted-foreground mt-0.5">{req.description}</p>
|
||||
)}
|
||||
<div className="flex flex-wrap gap-2 mt-1.5">
|
||||
{req.acceptedMimeTypes?.length > 0 ? (
|
||||
<span className="text-[10px] text-muted-foreground bg-muted px-1.5 py-0.5 rounded">
|
||||
{req.acceptedMimeTypes.map((t: string) => {
|
||||
if (t === 'application/pdf') return 'PDF'
|
||||
if (t.startsWith('image/')) return t.replace('image/', '').toUpperCase()
|
||||
if (t.startsWith('video/')) return t.replace('video/', '').toUpperCase()
|
||||
return t.split('/').pop()?.toUpperCase() || t
|
||||
}).join(', ')}
|
||||
</span>
|
||||
) : (
|
||||
<span className="text-[10px] text-muted-foreground bg-muted px-1.5 py-0.5 rounded">
|
||||
Any file type
|
||||
</span>
|
||||
)}
|
||||
{req.maxSizeMB && (
|
||||
<span className="text-[10px] text-muted-foreground bg-muted px-1.5 py-0.5 rounded">
|
||||
Max {req.maxSizeMB} MB
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-1 shrink-0">
|
||||
<Button variant="ghost" size="icon" className="h-7 w-7" onClick={() => openEditDialog(req)}>
|
||||
<Pencil className="h-3.5 w-3.5" />
|
||||
</Button>
|
||||
<AlertDialog>
|
||||
<AlertDialogTrigger asChild>
|
||||
<Button variant="ghost" size="icon" className="h-7 w-7 text-destructive hover:text-destructive">
|
||||
<Trash2 className="h-3.5 w-3.5" />
|
||||
</Button>
|
||||
</AlertDialogTrigger>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Delete requirement?</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
This will remove "{req.name}" from the round. Previously uploaded files will not be deleted.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={() => deleteMutation.mutate({ id: req.id })}
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
>
|
||||
Delete
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Create / Edit Dialog */}
|
||||
<Dialog open={dialogOpen} onOpenChange={(open) => { if (!open) closeDialog() }}>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>{editingId ? 'Edit Requirement' : 'Add Document Requirement'}</DialogTitle>
|
||||
<DialogDescription>
|
||||
{editingId
|
||||
? 'Update the document requirement details.'
|
||||
: 'Define a new document that applicants must submit.'}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<label className="text-sm font-medium">Name</label>
|
||||
<Input
|
||||
placeholder="e.g. Business Plan, Pitch Deck, Financial Projections"
|
||||
value={form.name}
|
||||
onChange={(e) => setForm((f) => ({ ...f, name: e.target.value }))}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<label className="text-sm font-medium">Description</label>
|
||||
<Textarea
|
||||
placeholder="Describe what this document should contain..."
|
||||
rows={3}
|
||||
value={form.description}
|
||||
onChange={(e) => setForm((f) => ({ ...f, description: e.target.value }))}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<label className="text-sm font-medium">Accepted File Types</label>
|
||||
<Input
|
||||
placeholder="application/pdf, image/png (leave empty for any)"
|
||||
value={form.acceptedMimeTypes}
|
||||
onChange={(e) => setForm((f) => ({ ...f, acceptedMimeTypes: e.target.value }))}
|
||||
/>
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{COMMON_MIME_PRESETS.map((preset) => (
|
||||
<button
|
||||
key={preset.label}
|
||||
type="button"
|
||||
onClick={() => setForm((f) => ({ ...f, acceptedMimeTypes: preset.value }))}
|
||||
className="text-[10px] px-2 py-1 rounded-full border hover:bg-muted transition-colors"
|
||||
>
|
||||
{preset.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<label className="text-sm font-medium">Max File Size (MB)</label>
|
||||
<Input
|
||||
type="number"
|
||||
placeholder="e.g. 50"
|
||||
value={form.maxSizeMB}
|
||||
onChange={(e) => setForm((f) => ({ ...f, maxSizeMB: e.target.value }))}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Checkbox
|
||||
id="isRequired"
|
||||
checked={form.isRequired}
|
||||
onCheckedChange={(checked) => setForm((f) => ({ ...f, isRequired: !!checked }))}
|
||||
/>
|
||||
<label htmlFor="isRequired" className="text-sm">
|
||||
Required document (applicant must upload to proceed)
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={closeDialog}>Cancel</Button>
|
||||
<Button onClick={handleSubmit} disabled={isSaving || !form.name.trim()}>
|
||||
{isSaving && <Loader2 className="h-4 w-4 mr-2 animate-spin" />}
|
||||
{editingId ? 'Update' : 'Add Requirement'}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
841
src/components/admin/round/filtering-dashboard.tsx
Normal file
841
src/components/admin/round/filtering-dashboard.tsx
Normal file
@@ -0,0 +1,841 @@
|
||||
'use client'
|
||||
|
||||
import { useState, useEffect, useCallback } from 'react'
|
||||
import { trpc } from '@/lib/trpc/client'
|
||||
import { toast } from 'sonner'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Progress } from '@/components/ui/progress'
|
||||
import { Checkbox } from '@/components/ui/checkbox'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
import { Textarea } from '@/components/ui/textarea'
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/components/ui/select'
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
AlertDialogTrigger,
|
||||
} from '@/components/ui/alert-dialog'
|
||||
import {
|
||||
Play,
|
||||
Loader2,
|
||||
CheckCircle2,
|
||||
XCircle,
|
||||
AlertTriangle,
|
||||
RefreshCw,
|
||||
Eye,
|
||||
ChevronLeft,
|
||||
ChevronRight,
|
||||
Shield,
|
||||
Sparkles,
|
||||
Ban,
|
||||
Flag,
|
||||
RotateCcw,
|
||||
} from 'lucide-react'
|
||||
|
||||
type FilteringDashboardProps = {
|
||||
competitionId: string
|
||||
roundId: string
|
||||
}
|
||||
|
||||
type OutcomeFilter = 'ALL' | 'PASSED' | 'FILTERED_OUT' | 'FLAGGED'
|
||||
|
||||
type AIScreeningData = {
|
||||
meetsCriteria?: boolean
|
||||
confidence?: number
|
||||
reasoning?: string
|
||||
qualityScore?: number
|
||||
spamRisk?: boolean
|
||||
}
|
||||
|
||||
export function FilteringDashboard({ competitionId, roundId }: FilteringDashboardProps) {
|
||||
const [outcomeFilter, setOutcomeFilter] = useState<OutcomeFilter>('ALL')
|
||||
const [page, setPage] = useState(1)
|
||||
const [selectedIds, setSelectedIds] = useState<Set<string>>(new Set())
|
||||
const [pollingJobId, setPollingJobId] = useState<string | null>(null)
|
||||
const [overrideDialogOpen, setOverrideDialogOpen] = useState(false)
|
||||
const [overrideTarget, setOverrideTarget] = useState<{ id: string; name: string } | null>(null)
|
||||
const [overrideOutcome, setOverrideOutcome] = useState<'PASSED' | 'FILTERED_OUT' | 'FLAGGED'>('PASSED')
|
||||
const [overrideReason, setOverrideReason] = useState('')
|
||||
const [bulkOverrideDialogOpen, setBulkOverrideDialogOpen] = useState(false)
|
||||
const [bulkOutcome, setBulkOutcome] = useState<'PASSED' | 'FILTERED_OUT' | 'FLAGGED'>('PASSED')
|
||||
const [bulkReason, setBulkReason] = useState('')
|
||||
const [detailResult, setDetailResult] = useState<any>(null)
|
||||
|
||||
const utils = trpc.useUtils()
|
||||
|
||||
// -- Queries --
|
||||
const { data: stats, isLoading: statsLoading } = trpc.filtering.getResultStats.useQuery(
|
||||
{ roundId },
|
||||
)
|
||||
|
||||
const { data: latestJob, isLoading: jobLoading } = trpc.filtering.getLatestJob.useQuery(
|
||||
{ roundId },
|
||||
)
|
||||
|
||||
const { data: rules } = trpc.filtering.getRules.useQuery({ roundId })
|
||||
|
||||
const { data: resultsPage, isLoading: resultsLoading } = trpc.filtering.getResults.useQuery(
|
||||
{
|
||||
roundId,
|
||||
outcome: outcomeFilter === 'ALL' ? undefined : outcomeFilter,
|
||||
page,
|
||||
perPage: 25,
|
||||
},
|
||||
)
|
||||
|
||||
const { data: jobStatus } = trpc.filtering.getJobStatus.useQuery(
|
||||
{ jobId: pollingJobId! },
|
||||
{
|
||||
enabled: !!pollingJobId,
|
||||
refetchInterval: 2000,
|
||||
},
|
||||
)
|
||||
|
||||
// Stop polling when job completes
|
||||
useEffect(() => {
|
||||
if (jobStatus && (jobStatus.status === 'COMPLETED' || jobStatus.status === 'FAILED')) {
|
||||
setPollingJobId(null)
|
||||
utils.filtering.getLatestJob.invalidate({ roundId })
|
||||
utils.filtering.getResults.invalidate()
|
||||
utils.filtering.getResultStats.invalidate({ roundId })
|
||||
if (jobStatus.status === 'COMPLETED') {
|
||||
toast.success(`Filtering complete: ${jobStatus.passedCount} passed, ${jobStatus.filteredCount} filtered, ${jobStatus.flaggedCount} flagged`)
|
||||
} else {
|
||||
toast.error(`Filtering failed: ${jobStatus.errorMessage || 'Unknown error'}`)
|
||||
}
|
||||
}
|
||||
}, [jobStatus, roundId, utils])
|
||||
|
||||
// Auto-detect running job on mount
|
||||
useEffect(() => {
|
||||
if (latestJob && latestJob.status === 'RUNNING') {
|
||||
setPollingJobId(latestJob.id)
|
||||
}
|
||||
}, [latestJob])
|
||||
|
||||
// -- Mutations --
|
||||
const startJobMutation = trpc.filtering.startJob.useMutation({
|
||||
onSuccess: (data) => {
|
||||
setPollingJobId(data.jobId)
|
||||
toast.success('Filtering job started')
|
||||
},
|
||||
onError: (err) => toast.error(err.message),
|
||||
})
|
||||
|
||||
const overrideMutation = trpc.filtering.overrideResult.useMutation({
|
||||
onSuccess: () => {
|
||||
utils.filtering.getResults.invalidate()
|
||||
utils.filtering.getResultStats.invalidate({ roundId })
|
||||
setOverrideDialogOpen(false)
|
||||
setOverrideTarget(null)
|
||||
setOverrideReason('')
|
||||
toast.success('Override applied')
|
||||
},
|
||||
onError: (err) => toast.error(err.message),
|
||||
})
|
||||
|
||||
const bulkOverrideMutation = trpc.filtering.bulkOverride.useMutation({
|
||||
onSuccess: (data) => {
|
||||
utils.filtering.getResults.invalidate()
|
||||
utils.filtering.getResultStats.invalidate({ roundId })
|
||||
setBulkOverrideDialogOpen(false)
|
||||
setSelectedIds(new Set())
|
||||
setBulkReason('')
|
||||
toast.success(`${data.updated} results overridden`)
|
||||
},
|
||||
onError: (err) => toast.error(err.message),
|
||||
})
|
||||
|
||||
const finalizeMutation = trpc.filtering.finalizeResults.useMutation({
|
||||
onSuccess: (data) => {
|
||||
utils.filtering.getResults.invalidate()
|
||||
utils.filtering.getResultStats.invalidate({ roundId })
|
||||
toast.success(
|
||||
`Finalized: ${data.passed} passed, ${data.filteredOut} filtered out` +
|
||||
(data.advancedToStageName ? `. Next round: ${data.advancedToStageName}` : '')
|
||||
)
|
||||
if (data.categoryWarnings.length > 0) {
|
||||
data.categoryWarnings.forEach((w) => toast.warning(w))
|
||||
}
|
||||
},
|
||||
onError: (err) => toast.error(err.message),
|
||||
})
|
||||
|
||||
// -- Handlers --
|
||||
const handleStartJob = () => {
|
||||
startJobMutation.mutate({ roundId })
|
||||
}
|
||||
|
||||
const handleOverride = () => {
|
||||
if (!overrideTarget) return
|
||||
overrideMutation.mutate({
|
||||
id: overrideTarget.id,
|
||||
finalOutcome: overrideOutcome,
|
||||
reason: overrideReason,
|
||||
})
|
||||
}
|
||||
|
||||
const handleBulkOverride = () => {
|
||||
bulkOverrideMutation.mutate({
|
||||
ids: Array.from(selectedIds),
|
||||
finalOutcome: bulkOutcome,
|
||||
reason: bulkReason,
|
||||
})
|
||||
}
|
||||
|
||||
const handleFinalize = () => {
|
||||
finalizeMutation.mutate({ roundId })
|
||||
}
|
||||
|
||||
const toggleSelect = (id: string) => {
|
||||
setSelectedIds((prev) => {
|
||||
const next = new Set(prev)
|
||||
if (next.has(id)) next.delete(id)
|
||||
else next.add(id)
|
||||
return next
|
||||
})
|
||||
}
|
||||
|
||||
const toggleSelectAll = useCallback(() => {
|
||||
if (!resultsPage) return
|
||||
const allIds = resultsPage.results.map((r: any) => r.id)
|
||||
const allSelected = allIds.every((id: string) => selectedIds.has(id))
|
||||
if (allSelected) {
|
||||
setSelectedIds((prev) => {
|
||||
const next = new Set(prev)
|
||||
allIds.forEach((id: string) => next.delete(id))
|
||||
return next
|
||||
})
|
||||
} else {
|
||||
setSelectedIds((prev) => {
|
||||
const next = new Set(prev)
|
||||
allIds.forEach((id: string) => next.add(id))
|
||||
return next
|
||||
})
|
||||
}
|
||||
}, [resultsPage, selectedIds])
|
||||
|
||||
const parseAIData = (json: unknown): AIScreeningData | null => {
|
||||
if (!json || typeof json !== 'object') return null
|
||||
return json as AIScreeningData
|
||||
}
|
||||
|
||||
// Is there a running job?
|
||||
const isRunning = !!pollingJobId || latestJob?.status === 'RUNNING'
|
||||
const activeJob = jobStatus || (latestJob?.status === 'RUNNING' ? latestJob : null)
|
||||
const hasResults = stats && stats.total > 0
|
||||
const hasRules = rules && rules.length > 0
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{/* Job Control */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3">
|
||||
<div>
|
||||
<CardTitle className="text-base">AI Filtering</CardTitle>
|
||||
<CardDescription>
|
||||
Run AI screening against {hasRules ? rules.length : 0} active rule{rules?.length !== 1 ? 's' : ''}
|
||||
</CardDescription>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
onClick={handleStartJob}
|
||||
disabled={isRunning || startJobMutation.isPending || !hasRules}
|
||||
size="sm"
|
||||
>
|
||||
{isRunning ? (
|
||||
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
|
||||
) : (
|
||||
<Play className="h-4 w-4 mr-2" />
|
||||
)}
|
||||
{isRunning ? 'Running...' : 'Run Filtering'}
|
||||
</Button>
|
||||
{hasResults && (
|
||||
<AlertDialog>
|
||||
<AlertDialogTrigger asChild>
|
||||
<Button variant="outline" size="sm" disabled={isRunning || finalizeMutation.isPending}>
|
||||
<Shield className="h-4 w-4 mr-2" />
|
||||
Finalize Results
|
||||
</Button>
|
||||
</AlertDialogTrigger>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Finalize Filtering Results?</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
This will mark PASSED projects as eligible and FILTERED_OUT projects as rejected.
|
||||
{stats && (
|
||||
<span className="block mt-2 font-medium">
|
||||
{stats.passed} will pass, {stats.filteredOut} will be filtered out, {stats.flagged} flagged for review.
|
||||
</span>
|
||||
)}
|
||||
This action can be reversed but requires manual intervention.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction onClick={handleFinalize}>
|
||||
{finalizeMutation.isPending && <Loader2 className="h-4 w-4 mr-2 animate-spin" />}
|
||||
Finalize
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</CardHeader>
|
||||
|
||||
{/* Job Progress */}
|
||||
{isRunning && activeJob && (
|
||||
<CardContent className="pt-0">
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center justify-between text-sm">
|
||||
<span className="text-muted-foreground">
|
||||
Processing batch {activeJob.currentBatch} of {activeJob.totalBatches || '?'}
|
||||
</span>
|
||||
<span className="font-mono">
|
||||
{activeJob.processedCount}/{activeJob.totalProjects}
|
||||
</span>
|
||||
</div>
|
||||
<Progress
|
||||
value={activeJob.totalProjects > 0
|
||||
? (activeJob.processedCount / activeJob.totalProjects) * 100
|
||||
: 0
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</CardContent>
|
||||
)}
|
||||
|
||||
{/* Last job summary */}
|
||||
{!isRunning && latestJob && latestJob.status === 'COMPLETED' && (
|
||||
<CardContent className="pt-0">
|
||||
<div className="flex items-center gap-2 text-sm text-muted-foreground">
|
||||
<CheckCircle2 className="h-4 w-4 text-green-600" />
|
||||
Last run completed: {latestJob.passedCount} passed, {latestJob.filteredCount} filtered, {latestJob.flaggedCount} flagged
|
||||
<span className="text-xs">
|
||||
({new Date(latestJob.completedAt!).toLocaleDateString()})
|
||||
</span>
|
||||
</div>
|
||||
</CardContent>
|
||||
)}
|
||||
|
||||
{!isRunning && latestJob && latestJob.status === 'FAILED' && (
|
||||
<CardContent className="pt-0">
|
||||
<div className="flex items-center gap-2 text-sm text-red-600">
|
||||
<XCircle className="h-4 w-4" />
|
||||
Last run failed: {latestJob.errorMessage || 'Unknown error'}
|
||||
</div>
|
||||
</CardContent>
|
||||
)}
|
||||
|
||||
{!hasRules && (
|
||||
<CardContent className="pt-0">
|
||||
<p className="text-sm text-amber-600">
|
||||
No active filtering rules configured. Add rules in the Configuration tab first.
|
||||
</p>
|
||||
</CardContent>
|
||||
)}
|
||||
</Card>
|
||||
|
||||
{/* Stats Cards */}
|
||||
{statsLoading ? (
|
||||
<div className="grid gap-4 grid-cols-2 lg:grid-cols-5">
|
||||
{[1, 2, 3, 4, 5].map((i) => (
|
||||
<Skeleton key={i} className="h-24" />
|
||||
))}
|
||||
</div>
|
||||
) : stats && stats.total > 0 ? (
|
||||
<div className="grid gap-4 grid-cols-2 lg:grid-cols-5">
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||
<CardTitle className="text-sm font-medium">Total</CardTitle>
|
||||
<Sparkles className="h-4 w-4 text-blue-600" />
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="text-2xl font-bold">{stats.total}</div>
|
||||
<p className="text-xs text-muted-foreground">Projects screened</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||
<CardTitle className="text-sm font-medium">Passed</CardTitle>
|
||||
<CheckCircle2 className="h-4 w-4 text-green-600" />
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="text-2xl font-bold text-green-700">{stats.passed}</div>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{stats.total > 0 ? `${((stats.passed / stats.total) * 100).toFixed(0)}%` : '0%'}
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||
<CardTitle className="text-sm font-medium">Filtered Out</CardTitle>
|
||||
<Ban className="h-4 w-4 text-red-600" />
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="text-2xl font-bold text-red-700">{stats.filteredOut}</div>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{stats.total > 0 ? `${((stats.filteredOut / stats.total) * 100).toFixed(0)}%` : '0%'}
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||
<CardTitle className="text-sm font-medium">Flagged</CardTitle>
|
||||
<Flag className="h-4 w-4 text-amber-600" />
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="text-2xl font-bold text-amber-700">{stats.flagged}</div>
|
||||
<p className="text-xs text-muted-foreground">Need review</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||
<CardTitle className="text-sm font-medium">Overridden</CardTitle>
|
||||
<RotateCcw className="h-4 w-4 text-purple-600" />
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="text-2xl font-bold text-purple-700">{stats.overridden}</div>
|
||||
<p className="text-xs text-muted-foreground">Manual changes</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{/* Results Table */}
|
||||
{(hasResults || resultsLoading) && (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3">
|
||||
<div>
|
||||
<CardTitle className="text-base">Filtering Results</CardTitle>
|
||||
<CardDescription>
|
||||
Review AI screening outcomes and override decisions
|
||||
</CardDescription>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Select
|
||||
value={outcomeFilter}
|
||||
onValueChange={(v) => {
|
||||
setOutcomeFilter(v as OutcomeFilter)
|
||||
setPage(1)
|
||||
setSelectedIds(new Set())
|
||||
}}
|
||||
>
|
||||
<SelectTrigger className="w-[160px]">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="ALL">All Outcomes</SelectItem>
|
||||
<SelectItem value="PASSED">Passed</SelectItem>
|
||||
<SelectItem value="FILTERED_OUT">Filtered Out</SelectItem>
|
||||
<SelectItem value="FLAGGED">Flagged</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
{selectedIds.size > 0 && (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => setBulkOverrideDialogOpen(true)}
|
||||
>
|
||||
Override {selectedIds.size} Selected
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={() => {
|
||||
utils.filtering.getResults.invalidate()
|
||||
utils.filtering.getResultStats.invalidate({ roundId })
|
||||
}}
|
||||
>
|
||||
<RefreshCw className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{resultsLoading ? (
|
||||
<div className="space-y-2">
|
||||
{[1, 2, 3, 4, 5].map((i) => (
|
||||
<Skeleton key={i} className="h-14 w-full" />
|
||||
))}
|
||||
</div>
|
||||
) : resultsPage && resultsPage.results.length > 0 ? (
|
||||
<div className="space-y-1">
|
||||
{/* Table Header */}
|
||||
<div className="grid grid-cols-[40px_1fr_120px_80px_80px_80px_100px] gap-2 px-3 py-2 text-xs font-medium text-muted-foreground border-b">
|
||||
<div>
|
||||
<Checkbox
|
||||
checked={
|
||||
resultsPage.results.length > 0 &&
|
||||
resultsPage.results.every((r: any) => selectedIds.has(r.id))
|
||||
}
|
||||
onCheckedChange={toggleSelectAll}
|
||||
/>
|
||||
</div>
|
||||
<div>Project</div>
|
||||
<div>Category</div>
|
||||
<div>Outcome</div>
|
||||
<div>Confidence</div>
|
||||
<div>Quality</div>
|
||||
<div>Actions</div>
|
||||
</div>
|
||||
|
||||
{/* Rows */}
|
||||
{resultsPage.results.map((result: any) => {
|
||||
const ai = parseAIData(result.aiScreeningJson)
|
||||
const effectiveOutcome = result.finalOutcome || result.outcome
|
||||
|
||||
return (
|
||||
<div
|
||||
key={result.id}
|
||||
className="grid grid-cols-[40px_1fr_120px_80px_80px_80px_100px] gap-2 px-3 py-2.5 items-center border-b last:border-b-0 hover:bg-muted/50 text-sm"
|
||||
>
|
||||
<div>
|
||||
<Checkbox
|
||||
checked={selectedIds.has(result.id)}
|
||||
onCheckedChange={() => toggleSelect(result.id)}
|
||||
/>
|
||||
</div>
|
||||
<div className="min-w-0">
|
||||
<p className="font-medium truncate">{result.project?.title || 'Unknown'}</p>
|
||||
<p className="text-xs text-muted-foreground truncate">
|
||||
{result.project?.teamName}
|
||||
{result.project?.country && ` · ${result.project.country}`}
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<Badge variant="outline" className="text-xs">
|
||||
{result.project?.competitionCategory || '—'}
|
||||
</Badge>
|
||||
</div>
|
||||
<div>
|
||||
<OutcomeBadge outcome={effectiveOutcome} overridden={!!result.finalOutcome && result.finalOutcome !== result.outcome} />
|
||||
</div>
|
||||
<div>
|
||||
{ai?.confidence != null ? (
|
||||
<ConfidenceIndicator value={ai.confidence} />
|
||||
) : (
|
||||
<span className="text-xs text-muted-foreground">—</span>
|
||||
)}
|
||||
</div>
|
||||
<div>
|
||||
{ai?.qualityScore != null ? (
|
||||
<span className={`text-sm font-mono font-medium ${
|
||||
ai.qualityScore >= 7 ? 'text-green-700' :
|
||||
ai.qualityScore >= 4 ? 'text-amber-700' :
|
||||
'text-red-700'
|
||||
}`}>
|
||||
{ai.qualityScore}/10
|
||||
</span>
|
||||
) : (
|
||||
<span className="text-xs text-muted-foreground">—</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center gap-1">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-7 w-7"
|
||||
onClick={() => setDetailResult(result)}
|
||||
title="View AI feedback"
|
||||
>
|
||||
<Eye className="h-3.5 w-3.5" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-7 w-7"
|
||||
onClick={() => {
|
||||
setOverrideTarget({ id: result.id, name: result.project?.title || 'Unknown' })
|
||||
setOverrideOutcome(effectiveOutcome === 'PASSED' ? 'FILTERED_OUT' : 'PASSED')
|
||||
setOverrideDialogOpen(true)
|
||||
}}
|
||||
title="Override decision"
|
||||
>
|
||||
<RotateCcw className="h-3.5 w-3.5" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
|
||||
{/* Pagination */}
|
||||
{resultsPage.totalPages > 1 && (
|
||||
<div className="flex items-center justify-between pt-4">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Page {resultsPage.page} of {resultsPage.totalPages} ({resultsPage.total} total)
|
||||
</p>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
disabled={page <= 1}
|
||||
onClick={() => setPage((p) => p - 1)}
|
||||
>
|
||||
<ChevronLeft className="h-4 w-4" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
disabled={page >= resultsPage.totalPages}
|
||||
onClick={() => setPage((p) => p + 1)}
|
||||
>
|
||||
<ChevronRight className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex flex-col items-center justify-center py-12 text-center">
|
||||
<Sparkles className="h-8 w-8 text-muted-foreground mb-3" />
|
||||
<p className="text-sm font-medium">No results yet</p>
|
||||
<p className="text-xs text-muted-foreground mt-1">
|
||||
Run the filtering job to screen projects
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{/* AI Detail Dialog */}
|
||||
<Dialog open={!!detailResult} onOpenChange={(open) => !open && setDetailResult(null)}>
|
||||
<DialogContent className="max-w-lg">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{detailResult?.project?.title || 'Project'}</DialogTitle>
|
||||
<DialogDescription>
|
||||
AI screening feedback and reasoning
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
{detailResult && (() => {
|
||||
const ai = parseAIData(detailResult.aiScreeningJson)
|
||||
const effectiveOutcome = detailResult.finalOutcome || detailResult.outcome
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center gap-3">
|
||||
<OutcomeBadge outcome={effectiveOutcome} overridden={!!detailResult.finalOutcome && detailResult.finalOutcome !== detailResult.outcome} />
|
||||
{detailResult.finalOutcome && detailResult.finalOutcome !== detailResult.outcome && (
|
||||
<span className="text-xs text-muted-foreground">
|
||||
Original: <OutcomeBadge outcome={detailResult.outcome} overridden={false} />
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{ai && (
|
||||
<>
|
||||
<div className="grid grid-cols-3 gap-3">
|
||||
<div className="rounded-lg border p-3 text-center">
|
||||
<p className="text-xs text-muted-foreground mb-1">Confidence</p>
|
||||
<p className="text-lg font-bold">
|
||||
{ai.confidence != null ? `${(ai.confidence * 100).toFixed(0)}%` : '—'}
|
||||
</p>
|
||||
</div>
|
||||
<div className="rounded-lg border p-3 text-center">
|
||||
<p className="text-xs text-muted-foreground mb-1">Quality</p>
|
||||
<p className="text-lg font-bold">
|
||||
{ai.qualityScore != null ? `${ai.qualityScore}/10` : '—'}
|
||||
</p>
|
||||
</div>
|
||||
<div className="rounded-lg border p-3 text-center">
|
||||
<p className="text-xs text-muted-foreground mb-1">Spam Risk</p>
|
||||
<p className={`text-lg font-bold ${ai.spamRisk ? 'text-red-600' : 'text-green-600'}`}>
|
||||
{ai.spamRisk ? 'Yes' : 'No'}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{ai.reasoning && (
|
||||
<div>
|
||||
<p className="text-sm font-medium mb-1">AI Reasoning</p>
|
||||
<div className="rounded-lg bg-muted p-3 text-sm whitespace-pre-wrap">
|
||||
{ai.reasoning}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
{detailResult.overrideReason && (
|
||||
<div>
|
||||
<p className="text-sm font-medium mb-1">Override Reason</p>
|
||||
<div className="rounded-lg bg-amber-50 border border-amber-200 p-3 text-sm">
|
||||
{detailResult.overrideReason}
|
||||
{detailResult.overriddenByUser && (
|
||||
<p className="text-xs text-muted-foreground mt-1">
|
||||
By {detailResult.overriddenByUser.name || detailResult.overriddenByUser.email}
|
||||
{detailResult.overriddenAt && ` on ${new Date(detailResult.overriddenAt).toLocaleDateString()}`}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Rule-by-rule results */}
|
||||
{detailResult.ruleResultsJson && Array.isArray(detailResult.ruleResultsJson) && (
|
||||
<div>
|
||||
<p className="text-sm font-medium mb-1">Rule Results</p>
|
||||
<div className="space-y-1">
|
||||
{(detailResult.ruleResultsJson as any[]).map((rule: any, i: number) => (
|
||||
<div key={i} className="flex items-center justify-between text-sm px-2 py-1.5 rounded border">
|
||||
<span>{rule.ruleName || `Rule ${i + 1}`}</span>
|
||||
<Badge variant={rule.passed ? 'default' : 'destructive'} className="text-xs">
|
||||
{rule.passed ? 'Pass' : 'Fail'}
|
||||
</Badge>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
})()}
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
{/* Single Override Dialog */}
|
||||
<Dialog open={overrideDialogOpen} onOpenChange={setOverrideDialogOpen}>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Override Decision</DialogTitle>
|
||||
<DialogDescription>
|
||||
Change the outcome for: {overrideTarget?.name}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<label className="text-sm font-medium mb-1.5 block">New Outcome</label>
|
||||
<Select value={overrideOutcome} onValueChange={(v) => setOverrideOutcome(v as any)}>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="PASSED">Passed</SelectItem>
|
||||
<SelectItem value="FILTERED_OUT">Filtered Out</SelectItem>
|
||||
<SelectItem value="FLAGGED">Flagged</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div>
|
||||
<label className="text-sm font-medium mb-1.5 block">Reason</label>
|
||||
<Textarea
|
||||
placeholder="Explain why you're overriding this decision..."
|
||||
value={overrideReason}
|
||||
onChange={(e) => setOverrideReason(e.target.value)}
|
||||
rows={3}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={() => setOverrideDialogOpen(false)}>Cancel</Button>
|
||||
<Button
|
||||
onClick={handleOverride}
|
||||
disabled={!overrideReason.trim() || overrideMutation.isPending}
|
||||
>
|
||||
{overrideMutation.isPending && <Loader2 className="h-4 w-4 mr-2 animate-spin" />}
|
||||
Apply Override
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
{/* Bulk Override Dialog */}
|
||||
<Dialog open={bulkOverrideDialogOpen} onOpenChange={setBulkOverrideDialogOpen}>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Bulk Override</DialogTitle>
|
||||
<DialogDescription>
|
||||
Override {selectedIds.size} selected results
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<label className="text-sm font-medium mb-1.5 block">Set All To</label>
|
||||
<Select value={bulkOutcome} onValueChange={(v) => setBulkOutcome(v as any)}>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="PASSED">Passed</SelectItem>
|
||||
<SelectItem value="FILTERED_OUT">Filtered Out</SelectItem>
|
||||
<SelectItem value="FLAGGED">Flagged</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div>
|
||||
<label className="text-sm font-medium mb-1.5 block">Reason</label>
|
||||
<Textarea
|
||||
placeholder="Explain why you're overriding these decisions..."
|
||||
value={bulkReason}
|
||||
onChange={(e) => setBulkReason(e.target.value)}
|
||||
rows={3}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={() => setBulkOverrideDialogOpen(false)}>Cancel</Button>
|
||||
<Button
|
||||
onClick={handleBulkOverride}
|
||||
disabled={!bulkReason.trim() || bulkOverrideMutation.isPending}
|
||||
>
|
||||
{bulkOverrideMutation.isPending && <Loader2 className="h-4 w-4 mr-2 animate-spin" />}
|
||||
Override {selectedIds.size} Results
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// -- Sub-components --
|
||||
|
||||
function OutcomeBadge({ outcome, overridden }: { outcome: string; overridden: boolean }) {
|
||||
const styles: Record<string, string> = {
|
||||
PASSED: 'bg-green-100 text-green-800 border-green-200',
|
||||
FILTERED_OUT: 'bg-red-100 text-red-800 border-red-200',
|
||||
FLAGGED: 'bg-amber-100 text-amber-800 border-amber-200',
|
||||
}
|
||||
return (
|
||||
<Badge variant="outline" className={`text-xs ${styles[outcome] || ''} ${overridden ? 'ring-1 ring-purple-400' : ''}`}>
|
||||
{outcome === 'FILTERED_OUT' ? 'Filtered' : outcome === 'PASSED' ? 'Passed' : 'Flagged'}
|
||||
{overridden && ' *'}
|
||||
</Badge>
|
||||
)
|
||||
}
|
||||
|
||||
function ConfidenceIndicator({ value }: { value: number }) {
|
||||
const pct = Math.round(value * 100)
|
||||
const color = pct >= 80 ? 'text-green-700' : pct >= 50 ? 'text-amber-700' : 'text-red-700'
|
||||
return (
|
||||
<span className={`text-sm font-mono font-medium ${color}`}>
|
||||
{pct}%
|
||||
</span>
|
||||
)
|
||||
}
|
||||
@@ -1,7 +1,72 @@
|
||||
'use client'
|
||||
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Layers } from 'lucide-react'
|
||||
import { useState, useCallback } from 'react'
|
||||
import { trpc } from '@/lib/trpc/client'
|
||||
import { toast } from 'sonner'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent } from '@/components/ui/card'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Checkbox } from '@/components/ui/checkbox'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/components/ui/select'
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from '@/components/ui/alert-dialog'
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/components/ui/dropdown-menu'
|
||||
import {
|
||||
Loader2,
|
||||
MoreHorizontal,
|
||||
ArrowRight,
|
||||
XCircle,
|
||||
CheckCircle2,
|
||||
Clock,
|
||||
Play,
|
||||
LogOut,
|
||||
Layers,
|
||||
Trash2,
|
||||
Plus,
|
||||
} from 'lucide-react'
|
||||
import Link from 'next/link'
|
||||
import type { Route } from 'next'
|
||||
|
||||
const PROJECT_STATES = ['PENDING', 'IN_PROGRESS', 'PASSED', 'REJECTED', 'COMPLETED', 'WITHDRAWN'] as const
|
||||
type ProjectState = (typeof PROJECT_STATES)[number]
|
||||
|
||||
const stateConfig: Record<ProjectState, { label: string; color: string; icon: React.ElementType }> = {
|
||||
PENDING: { label: 'Pending', color: 'bg-gray-100 text-gray-700 border-gray-200', icon: Clock },
|
||||
IN_PROGRESS: { label: 'In Progress', color: 'bg-blue-100 text-blue-700 border-blue-200', icon: Play },
|
||||
PASSED: { label: 'Passed', color: 'bg-green-100 text-green-700 border-green-200', icon: CheckCircle2 },
|
||||
REJECTED: { label: 'Rejected', color: 'bg-red-100 text-red-700 border-red-200', icon: XCircle },
|
||||
COMPLETED: { label: 'Completed', color: 'bg-emerald-100 text-emerald-700 border-emerald-200', icon: CheckCircle2 },
|
||||
WITHDRAWN: { label: 'Withdrawn', color: 'bg-orange-100 text-orange-700 border-orange-200', icon: LogOut },
|
||||
}
|
||||
|
||||
type ProjectStatesTableProps = {
|
||||
competitionId: string
|
||||
@@ -9,25 +74,395 @@ type ProjectStatesTableProps = {
|
||||
}
|
||||
|
||||
export function ProjectStatesTable({ competitionId, roundId }: ProjectStatesTableProps) {
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">Project States</CardTitle>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Projects participating in this round
|
||||
</p>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="flex flex-col items-center justify-center py-12 text-center">
|
||||
<div className="rounded-full bg-muted p-4 mb-4">
|
||||
<Layers className="h-8 w-8 text-muted-foreground" />
|
||||
const [selectedIds, setSelectedIds] = useState<Set<string>>(new Set())
|
||||
const [stateFilter, setStateFilter] = useState<string>('ALL')
|
||||
const [batchDialogOpen, setBatchDialogOpen] = useState(false)
|
||||
const [batchNewState, setBatchNewState] = useState<ProjectState>('PASSED')
|
||||
const [removeConfirmId, setRemoveConfirmId] = useState<string | null>(null)
|
||||
const [batchRemoveOpen, setBatchRemoveOpen] = useState(false)
|
||||
|
||||
const utils = trpc.useUtils()
|
||||
|
||||
const { data: projectStates, isLoading } = trpc.roundEngine.getProjectStates.useQuery(
|
||||
{ roundId },
|
||||
)
|
||||
|
||||
const transitionMutation = trpc.roundEngine.transitionProject.useMutation({
|
||||
onSuccess: () => {
|
||||
utils.roundEngine.getProjectStates.invalidate({ roundId })
|
||||
toast.success('Project state updated')
|
||||
},
|
||||
onError: (err) => toast.error(err.message),
|
||||
})
|
||||
|
||||
const batchTransitionMutation = trpc.roundEngine.batchTransition.useMutation({
|
||||
onSuccess: (data) => {
|
||||
utils.roundEngine.getProjectStates.invalidate({ roundId })
|
||||
setSelectedIds(new Set())
|
||||
setBatchDialogOpen(false)
|
||||
toast.success(`${data.succeeded.length} projects updated${data.failed.length > 0 ? `, ${data.failed.length} failed` : ''}`)
|
||||
},
|
||||
onError: (err) => toast.error(err.message),
|
||||
})
|
||||
|
||||
const removeMutation = trpc.roundEngine.removeFromRound.useMutation({
|
||||
onSuccess: (data) => {
|
||||
utils.roundEngine.getProjectStates.invalidate({ roundId })
|
||||
setRemoveConfirmId(null)
|
||||
toast.success(`Removed from ${data.removedFromRounds} round(s)`)
|
||||
},
|
||||
onError: (err) => toast.error(err.message),
|
||||
})
|
||||
|
||||
const batchRemoveMutation = trpc.roundEngine.batchRemoveFromRound.useMutation({
|
||||
onSuccess: (data) => {
|
||||
utils.roundEngine.getProjectStates.invalidate({ roundId })
|
||||
setSelectedIds(new Set())
|
||||
setBatchRemoveOpen(false)
|
||||
toast.success(`${data.removedCount} project(s) removed from this round and later rounds`)
|
||||
},
|
||||
onError: (err) => toast.error(err.message),
|
||||
})
|
||||
|
||||
const handleTransition = (projectId: string, newState: ProjectState) => {
|
||||
transitionMutation.mutate({ projectId, roundId, newState })
|
||||
}
|
||||
|
||||
const handleBatchTransition = () => {
|
||||
batchTransitionMutation.mutate({
|
||||
projectIds: Array.from(selectedIds),
|
||||
roundId,
|
||||
newState: batchNewState,
|
||||
})
|
||||
}
|
||||
|
||||
const toggleSelect = (id: string) => {
|
||||
setSelectedIds((prev) => {
|
||||
const next = new Set(prev)
|
||||
if (next.has(id)) next.delete(id)
|
||||
else next.add(id)
|
||||
return next
|
||||
})
|
||||
}
|
||||
|
||||
const filtered = projectStates?.filter((ps: any) =>
|
||||
stateFilter === 'ALL' ? true : ps.state === stateFilter
|
||||
) ?? []
|
||||
|
||||
const toggleSelectAll = useCallback(() => {
|
||||
const ids = filtered.map((ps: any) => ps.projectId)
|
||||
const allSelected = ids.length > 0 && ids.every((id: string) => selectedIds.has(id))
|
||||
if (allSelected) {
|
||||
setSelectedIds((prev) => {
|
||||
const next = new Set(prev)
|
||||
ids.forEach((id: string) => next.delete(id))
|
||||
return next
|
||||
})
|
||||
} else {
|
||||
setSelectedIds((prev) => {
|
||||
const next = new Set(prev)
|
||||
ids.forEach((id: string) => next.add(id))
|
||||
return next
|
||||
})
|
||||
}
|
||||
}, [filtered, selectedIds])
|
||||
|
||||
// State counts
|
||||
const counts = projectStates?.reduce((acc: Record<string, number>, ps: any) => {
|
||||
acc[ps.state] = (acc[ps.state] || 0) + 1
|
||||
return acc
|
||||
}, {} as Record<string, number>) ?? {}
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<Skeleton className="h-10 w-full" />
|
||||
{[1, 2, 3, 4, 5].map((i) => (
|
||||
<Skeleton key={i} className="h-14 w-full" />
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (!projectStates || projectStates.length === 0) {
|
||||
return (
|
||||
<Card>
|
||||
<CardContent className="py-12">
|
||||
<div className="flex flex-col items-center justify-center text-center">
|
||||
<div className="rounded-full bg-muted p-4 mb-4">
|
||||
<Layers className="h-8 w-8 text-muted-foreground" />
|
||||
</div>
|
||||
<p className="text-sm font-medium">No Projects in This Round</p>
|
||||
<p className="text-xs text-muted-foreground mt-1 max-w-sm">
|
||||
Assign projects from the Project Pool to this round to get started.
|
||||
</p>
|
||||
<Link href={'/admin/projects/pool' as Route}>
|
||||
<Button size="sm" className="mt-4">
|
||||
<Plus className="h-4 w-4 mr-1.5" />
|
||||
Go to Project Pool
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
<p className="text-sm font-medium">No Active Projects</p>
|
||||
<p className="text-xs text-muted-foreground mt-1">
|
||||
Project states will appear here when the round is active
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
{/* Top bar: filters + add button */}
|
||||
<div className="flex items-center justify-between gap-4 flex-wrap">
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<button
|
||||
onClick={() => { setStateFilter('ALL'); setSelectedIds(new Set()) }}
|
||||
className={`text-xs px-3 py-1.5 rounded-full border transition-colors ${
|
||||
stateFilter === 'ALL'
|
||||
? 'bg-foreground text-background border-foreground'
|
||||
: 'bg-muted text-muted-foreground border-transparent hover:border-border'
|
||||
}`}
|
||||
>
|
||||
All ({projectStates.length})
|
||||
</button>
|
||||
{PROJECT_STATES.map((state) => {
|
||||
const count = counts[state] || 0
|
||||
if (count === 0) return null
|
||||
const cfg = stateConfig[state]
|
||||
return (
|
||||
<button
|
||||
key={state}
|
||||
onClick={() => { setStateFilter(state); setSelectedIds(new Set()) }}
|
||||
className={`text-xs px-3 py-1.5 rounded-full border transition-colors ${
|
||||
stateFilter === state
|
||||
? cfg.color + ' border-current'
|
||||
: 'bg-muted text-muted-foreground border-transparent hover:border-border'
|
||||
}`}
|
||||
>
|
||||
{cfg.label} ({count})
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Link href={'/admin/projects/pool' as Route}>
|
||||
<Button size="sm" variant="outline">
|
||||
<Plus className="h-4 w-4 mr-1.5" />
|
||||
Add from Pool
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
{/* Bulk actions bar */}
|
||||
{selectedIds.size > 0 && (
|
||||
<div className="flex items-center gap-3 p-3 rounded-lg bg-muted/50 border">
|
||||
<span className="text-sm font-medium">{selectedIds.size} selected</span>
|
||||
<div className="flex items-center gap-2 ml-auto">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => setBatchDialogOpen(true)}
|
||||
>
|
||||
<ArrowRight className="h-3.5 w-3.5 mr-1.5" />
|
||||
Change State
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="text-destructive border-destructive/30 hover:bg-destructive/10"
|
||||
onClick={() => setBatchRemoveOpen(true)}
|
||||
>
|
||||
<Trash2 className="h-3.5 w-3.5 mr-1.5" />
|
||||
Remove from Round
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => setSelectedIds(new Set())}
|
||||
>
|
||||
Clear
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Table */}
|
||||
<div className="border rounded-lg overflow-hidden">
|
||||
{/* Header */}
|
||||
<div className="grid grid-cols-[40px_1fr_140px_120px_100px_48px] gap-2 px-4 py-2.5 bg-muted/40 text-xs font-medium text-muted-foreground border-b">
|
||||
<div>
|
||||
<Checkbox
|
||||
checked={filtered.length > 0 && filtered.every((ps: any) => selectedIds.has(ps.projectId))}
|
||||
onCheckedChange={toggleSelectAll}
|
||||
/>
|
||||
</div>
|
||||
<div>Project</div>
|
||||
<div>Category</div>
|
||||
<div>State</div>
|
||||
<div>Entered</div>
|
||||
<div />
|
||||
</div>
|
||||
|
||||
{/* Rows */}
|
||||
{filtered.map((ps: any) => {
|
||||
const cfg = stateConfig[ps.state as ProjectState] || stateConfig.PENDING
|
||||
const StateIcon = cfg.icon
|
||||
return (
|
||||
<div
|
||||
key={ps.id}
|
||||
className="grid grid-cols-[40px_1fr_140px_120px_100px_48px] gap-2 px-4 py-3 items-center border-b last:border-b-0 hover:bg-muted/30 text-sm"
|
||||
>
|
||||
<div>
|
||||
<Checkbox
|
||||
checked={selectedIds.has(ps.projectId)}
|
||||
onCheckedChange={() => toggleSelect(ps.projectId)}
|
||||
/>
|
||||
</div>
|
||||
<div className="min-w-0">
|
||||
<p className="font-medium truncate">{ps.project?.title || 'Unknown'}</p>
|
||||
<p className="text-xs text-muted-foreground truncate">{ps.project?.teamName}</p>
|
||||
</div>
|
||||
<div>
|
||||
<Badge variant="outline" className="text-xs">
|
||||
{ps.project?.competitionCategory || '—'}
|
||||
</Badge>
|
||||
</div>
|
||||
<div>
|
||||
<Badge variant="outline" className={`text-xs ${cfg.color}`}>
|
||||
<StateIcon className="h-3 w-3 mr-1" />
|
||||
{cfg.label}
|
||||
</Badge>
|
||||
</div>
|
||||
<div className="text-xs text-muted-foreground">
|
||||
{ps.enteredAt ? new Date(ps.enteredAt).toLocaleDateString() : '—'}
|
||||
</div>
|
||||
<div>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon" className="h-7 w-7">
|
||||
<MoreHorizontal className="h-3.5 w-3.5" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
{PROJECT_STATES.filter((s) => s !== ps.state).map((state) => {
|
||||
const sCfg = stateConfig[state]
|
||||
return (
|
||||
<DropdownMenuItem
|
||||
key={state}
|
||||
onClick={() => handleTransition(ps.projectId, state)}
|
||||
disabled={transitionMutation.isPending}
|
||||
>
|
||||
<sCfg.icon className="h-3.5 w-3.5 mr-2" />
|
||||
Move to {sCfg.label}
|
||||
</DropdownMenuItem>
|
||||
)
|
||||
})}
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem
|
||||
onClick={() => setRemoveConfirmId(ps.projectId)}
|
||||
className="text-destructive focus:text-destructive"
|
||||
>
|
||||
<Trash2 className="h-3.5 w-3.5 mr-2" />
|
||||
Remove from Round
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
|
||||
{/* Single Remove Confirmation */}
|
||||
<AlertDialog open={!!removeConfirmId} onOpenChange={(open) => { if (!open) setRemoveConfirmId(null) }}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Remove project from this round?</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
The project will be removed from this round and all subsequent rounds.
|
||||
It will remain in any prior rounds it was already assigned to.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={() => {
|
||||
if (removeConfirmId) {
|
||||
removeMutation.mutate({ projectId: removeConfirmId, roundId })
|
||||
}
|
||||
}}
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
disabled={removeMutation.isPending}
|
||||
>
|
||||
{removeMutation.isPending && <Loader2 className="h-4 w-4 mr-2 animate-spin" />}
|
||||
Remove
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
|
||||
{/* Batch Remove Confirmation */}
|
||||
<AlertDialog open={batchRemoveOpen} onOpenChange={setBatchRemoveOpen}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Remove {selectedIds.size} projects from this round?</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
These projects will be removed from this round and all subsequent rounds in the competition.
|
||||
They will remain in any prior rounds they were already assigned to.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={() => {
|
||||
batchRemoveMutation.mutate({
|
||||
projectIds: Array.from(selectedIds),
|
||||
roundId,
|
||||
})
|
||||
}}
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
disabled={batchRemoveMutation.isPending}
|
||||
>
|
||||
{batchRemoveMutation.isPending && <Loader2 className="h-4 w-4 mr-2 animate-spin" />}
|
||||
Remove {selectedIds.size} Projects
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
|
||||
{/* Batch Transition Dialog */}
|
||||
<Dialog open={batchDialogOpen} onOpenChange={setBatchDialogOpen}>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Change State for {selectedIds.size} Projects</DialogTitle>
|
||||
<DialogDescription>
|
||||
All selected projects will be moved to the new state.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="space-y-3">
|
||||
<label className="text-sm font-medium">New State</label>
|
||||
<Select value={batchNewState} onValueChange={(v) => setBatchNewState(v as ProjectState)}>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{PROJECT_STATES.map((state) => (
|
||||
<SelectItem key={state} value={state}>
|
||||
{stateConfig[state].label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={() => setBatchDialogOpen(false)}>Cancel</Button>
|
||||
<Button
|
||||
onClick={handleBatchTransition}
|
||||
disabled={batchTransitionMutation.isPending}
|
||||
>
|
||||
{batchTransitionMutation.isPending && <Loader2 className="h-4 w-4 mr-2 animate-spin" />}
|
||||
Update {selectedIds.size} Projects
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user