Implement Prototype 1 improvements: unified members, project filters, audit expansion, filtering rounds, special awards
- Unified Member Management: merge /admin/users and /admin/mentors into /admin/members with role tabs, search, pagination - Project List Filters: add search, multi-status filter, round/category/country selects, boolean toggles, URL persistence - Audit Log Expansion: track logins, round state changes, evaluation submissions, file access, role changes via shared logAudit utility - Founding Date Field: add foundedAt to Project model with CSV import support - Filtering Round System: configurable rules (field-based, document check, AI screening), execution engine, results review with override/reinstate - Special Awards System: named awards with eligibility criteria, dedicated jury, PICK_WINNER/RANKED/SCORED voting modes, AI eligibility - Dashboard resilience: wrap heavy queries in try-catch to prevent error boundary on transient DB failures - Reusable pagination component extracted to src/components/shared/pagination.tsx - Old /admin/users and /admin/mentors routes redirect to /admin/members - Prisma migration for all schema additions (additive, no data loss) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
511
src/app/(admin)/admin/awards/[id]/page.tsx
Normal file
511
src/app/(admin)/admin/awards/[id]/page.tsx
Normal file
@@ -0,0 +1,511 @@
|
||||
'use client'
|
||||
|
||||
import { use, useState } from 'react'
|
||||
import Link from 'next/link'
|
||||
import { trpc } from '@/lib/trpc/client'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardDescription,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from '@/components/ui/card'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
import { Switch } from '@/components/ui/switch'
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from '@/components/ui/table'
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/components/ui/select'
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'
|
||||
import { UserAvatar } from '@/components/shared/user-avatar'
|
||||
import { Pagination } from '@/components/shared/pagination'
|
||||
import { toast } from 'sonner'
|
||||
import {
|
||||
ArrowLeft,
|
||||
Trophy,
|
||||
Users,
|
||||
CheckCircle2,
|
||||
Brain,
|
||||
BarChart3,
|
||||
Loader2,
|
||||
Crown,
|
||||
UserPlus,
|
||||
X,
|
||||
Play,
|
||||
Pause,
|
||||
Lock,
|
||||
} from 'lucide-react'
|
||||
|
||||
const STATUS_COLORS: Record<string, 'default' | 'secondary' | 'destructive' | 'outline'> = {
|
||||
DRAFT: 'secondary',
|
||||
NOMINATIONS_OPEN: 'default',
|
||||
VOTING_OPEN: 'default',
|
||||
CLOSED: 'outline',
|
||||
ARCHIVED: 'secondary',
|
||||
}
|
||||
|
||||
export default function AwardDetailPage({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ id: string }>
|
||||
}) {
|
||||
const { id: awardId } = use(params)
|
||||
|
||||
const { data: award, isLoading, refetch } =
|
||||
trpc.specialAward.get.useQuery({ id: awardId })
|
||||
const { data: eligibilityData, refetch: refetchEligibility } =
|
||||
trpc.specialAward.listEligible.useQuery({
|
||||
awardId,
|
||||
page: 1,
|
||||
perPage: 50,
|
||||
})
|
||||
const { data: jurors, refetch: refetchJurors } =
|
||||
trpc.specialAward.listJurors.useQuery({ awardId })
|
||||
const { data: voteResults } =
|
||||
trpc.specialAward.getVoteResults.useQuery({ awardId })
|
||||
const { data: allUsers } = trpc.user.list.useQuery({ page: 1, perPage: 200 })
|
||||
|
||||
const updateStatus = trpc.specialAward.updateStatus.useMutation()
|
||||
const runEligibility = trpc.specialAward.runEligibility.useMutation()
|
||||
const setEligibility = trpc.specialAward.setEligibility.useMutation()
|
||||
const addJuror = trpc.specialAward.addJuror.useMutation()
|
||||
const removeJuror = trpc.specialAward.removeJuror.useMutation()
|
||||
const setWinner = trpc.specialAward.setWinner.useMutation()
|
||||
|
||||
const [selectedJurorId, setSelectedJurorId] = useState('')
|
||||
|
||||
const handleStatusChange = async (
|
||||
status: 'DRAFT' | 'NOMINATIONS_OPEN' | 'VOTING_OPEN' | 'CLOSED' | 'ARCHIVED'
|
||||
) => {
|
||||
try {
|
||||
await updateStatus.mutateAsync({ id: awardId, status })
|
||||
toast.success(`Status updated to ${status.replace('_', ' ')}`)
|
||||
refetch()
|
||||
} catch (error) {
|
||||
toast.error(
|
||||
error instanceof Error ? error.message : 'Failed to update status'
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
const handleRunEligibility = async () => {
|
||||
try {
|
||||
const result = await runEligibility.mutateAsync({ awardId })
|
||||
toast.success(
|
||||
`Eligibility run: ${result.eligible} eligible, ${result.ineligible} ineligible`
|
||||
)
|
||||
refetchEligibility()
|
||||
refetch()
|
||||
} catch (error) {
|
||||
toast.error(
|
||||
error instanceof Error ? error.message : 'Failed to run eligibility'
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
const handleToggleEligibility = async (
|
||||
projectId: string,
|
||||
eligible: boolean
|
||||
) => {
|
||||
try {
|
||||
await setEligibility.mutateAsync({ awardId, projectId, eligible })
|
||||
refetchEligibility()
|
||||
} catch {
|
||||
toast.error('Failed to update eligibility')
|
||||
}
|
||||
}
|
||||
|
||||
const handleAddJuror = async () => {
|
||||
if (!selectedJurorId) return
|
||||
try {
|
||||
await addJuror.mutateAsync({ awardId, userId: selectedJurorId })
|
||||
toast.success('Juror added')
|
||||
setSelectedJurorId('')
|
||||
refetchJurors()
|
||||
} catch {
|
||||
toast.error('Failed to add juror')
|
||||
}
|
||||
}
|
||||
|
||||
const handleRemoveJuror = async (userId: string) => {
|
||||
try {
|
||||
await removeJuror.mutateAsync({ awardId, userId })
|
||||
refetchJurors()
|
||||
} catch {
|
||||
toast.error('Failed to remove juror')
|
||||
}
|
||||
}
|
||||
|
||||
const handleSetWinner = async (projectId: string) => {
|
||||
try {
|
||||
await setWinner.mutateAsync({
|
||||
awardId,
|
||||
projectId,
|
||||
overridden: true,
|
||||
})
|
||||
toast.success('Winner set')
|
||||
refetch()
|
||||
} catch {
|
||||
toast.error('Failed to set winner')
|
||||
}
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<Skeleton className="h-9 w-48" />
|
||||
<Skeleton className="h-40 w-full" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (!award) return null
|
||||
|
||||
const jurorUserIds = new Set(jurors?.map((j) => j.userId) || [])
|
||||
const availableUsers =
|
||||
allUsers?.users.filter((u) => !jurorUserIds.has(u.id)) || []
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{/* Header */}
|
||||
<div className="flex items-center gap-4">
|
||||
<Button variant="ghost" asChild className="-ml-4">
|
||||
<Link href="/admin/awards">
|
||||
<ArrowLeft className="mr-2 h-4 w-4" />
|
||||
Back to Awards
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="flex items-start justify-between">
|
||||
<div>
|
||||
<h1 className="text-2xl font-semibold tracking-tight flex items-center gap-2">
|
||||
<Trophy className="h-6 w-6 text-amber-500" />
|
||||
{award.name}
|
||||
</h1>
|
||||
<div className="flex items-center gap-2 mt-1">
|
||||
<Badge variant={STATUS_COLORS[award.status] || 'secondary'}>
|
||||
{award.status.replace('_', ' ')}
|
||||
</Badge>
|
||||
<span className="text-muted-foreground">
|
||||
{award.program.name}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
{award.status === 'DRAFT' && (
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => handleStatusChange('NOMINATIONS_OPEN')}
|
||||
disabled={updateStatus.isPending}
|
||||
>
|
||||
<Play className="mr-2 h-4 w-4" />
|
||||
Open Nominations
|
||||
</Button>
|
||||
)}
|
||||
{award.status === 'NOMINATIONS_OPEN' && (
|
||||
<Button
|
||||
onClick={() => handleStatusChange('VOTING_OPEN')}
|
||||
disabled={updateStatus.isPending}
|
||||
>
|
||||
<Play className="mr-2 h-4 w-4" />
|
||||
Open Voting
|
||||
</Button>
|
||||
)}
|
||||
{award.status === 'VOTING_OPEN' && (
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => handleStatusChange('CLOSED')}
|
||||
disabled={updateStatus.isPending}
|
||||
>
|
||||
<Lock className="mr-2 h-4 w-4" />
|
||||
Close Voting
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Description */}
|
||||
{award.description && (
|
||||
<p className="text-muted-foreground">{award.description}</p>
|
||||
)}
|
||||
|
||||
{/* Tabs */}
|
||||
<Tabs defaultValue="eligibility">
|
||||
<TabsList>
|
||||
<TabsTrigger value="eligibility">
|
||||
<CheckCircle2 className="mr-2 h-4 w-4" />
|
||||
Eligibility ({award.eligibleCount})
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value="jurors">
|
||||
<Users className="mr-2 h-4 w-4" />
|
||||
Jurors ({award._count.jurors})
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value="results">
|
||||
<BarChart3 className="mr-2 h-4 w-4" />
|
||||
Results
|
||||
</TabsTrigger>
|
||||
</TabsList>
|
||||
|
||||
{/* Eligibility Tab */}
|
||||
<TabsContent value="eligibility" className="space-y-4">
|
||||
<div className="flex justify-between items-center">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{award.eligibleCount} of {award._count.eligibilities} projects
|
||||
eligible
|
||||
</p>
|
||||
<Button
|
||||
onClick={handleRunEligibility}
|
||||
disabled={runEligibility.isPending}
|
||||
>
|
||||
{runEligibility.isPending ? (
|
||||
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
||||
) : (
|
||||
<Brain className="mr-2 h-4 w-4" />
|
||||
)}
|
||||
Run AI Eligibility
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{eligibilityData && eligibilityData.eligibilities.length > 0 ? (
|
||||
<Card>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Project</TableHead>
|
||||
<TableHead>Category</TableHead>
|
||||
<TableHead>Country</TableHead>
|
||||
<TableHead>Eligible</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{eligibilityData.eligibilities.map((e) => (
|
||||
<TableRow key={e.id}>
|
||||
<TableCell>
|
||||
<div>
|
||||
<p className="font-medium">{e.project.title}</p>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{e.project.teamName}
|
||||
</p>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{e.project.competitionCategory ? (
|
||||
<Badge variant="outline">
|
||||
{e.project.competitionCategory.replace('_', ' ')}
|
||||
</Badge>
|
||||
) : (
|
||||
'-'
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell>{e.project.country || '-'}</TableCell>
|
||||
<TableCell>
|
||||
<Switch
|
||||
checked={e.eligible}
|
||||
onCheckedChange={(checked) =>
|
||||
handleToggleEligibility(e.projectId, checked)
|
||||
}
|
||||
/>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</Card>
|
||||
) : (
|
||||
<Card>
|
||||
<CardContent className="flex flex-col items-center justify-center py-12 text-center">
|
||||
<Brain className="h-12 w-12 text-muted-foreground/50" />
|
||||
<p className="mt-2 font-medium">No eligibility data</p>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Run AI eligibility to evaluate projects against criteria
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
</TabsContent>
|
||||
|
||||
{/* Jurors Tab */}
|
||||
<TabsContent value="jurors" className="space-y-4">
|
||||
<div className="flex gap-2">
|
||||
<Select value={selectedJurorId} onValueChange={setSelectedJurorId}>
|
||||
<SelectTrigger className="w-64">
|
||||
<SelectValue placeholder="Select a member..." />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{availableUsers.map((u) => (
|
||||
<SelectItem key={u.id} value={u.id}>
|
||||
{u.name || u.email}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Button
|
||||
onClick={handleAddJuror}
|
||||
disabled={!selectedJurorId || addJuror.isPending}
|
||||
>
|
||||
<UserPlus className="mr-2 h-4 w-4" />
|
||||
Add Juror
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{jurors && jurors.length > 0 ? (
|
||||
<Card>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Member</TableHead>
|
||||
<TableHead>Role</TableHead>
|
||||
<TableHead className="text-right">Actions</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{jurors.map((j) => (
|
||||
<TableRow key={j.id}>
|
||||
<TableCell>
|
||||
<div className="flex items-center gap-3">
|
||||
<UserAvatar user={j.user} size="sm" />
|
||||
<div>
|
||||
<p className="font-medium">
|
||||
{j.user.name || 'Unnamed'}
|
||||
</p>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{j.user.email}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Badge variant="outline">
|
||||
{j.user.role.replace('_', ' ')}
|
||||
</Badge>
|
||||
</TableCell>
|
||||
<TableCell className="text-right">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => handleRemoveJuror(j.userId)}
|
||||
disabled={removeJuror.isPending}
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
</Button>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</Card>
|
||||
) : (
|
||||
<Card>
|
||||
<CardContent className="flex flex-col items-center justify-center py-12 text-center">
|
||||
<Users className="h-12 w-12 text-muted-foreground/50" />
|
||||
<p className="mt-2 font-medium">No jurors assigned</p>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Add members as jurors for this award
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
</TabsContent>
|
||||
|
||||
{/* Results Tab */}
|
||||
<TabsContent value="results" className="space-y-4">
|
||||
{voteResults && voteResults.results.length > 0 ? (
|
||||
<>
|
||||
<div className="flex items-center gap-4 text-sm text-muted-foreground">
|
||||
<span>
|
||||
{voteResults.votedJurorCount} of {voteResults.jurorCount}{' '}
|
||||
jurors voted
|
||||
</span>
|
||||
<Badge variant="outline">
|
||||
{voteResults.scoringMode.replace('_', ' ')}
|
||||
</Badge>
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead className="w-12">#</TableHead>
|
||||
<TableHead>Project</TableHead>
|
||||
<TableHead>Votes</TableHead>
|
||||
<TableHead>Points</TableHead>
|
||||
<TableHead className="text-right">Actions</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{voteResults.results.map((r, i) => (
|
||||
<TableRow
|
||||
key={r.project.id}
|
||||
className={
|
||||
r.project.id === voteResults.winnerId
|
||||
? 'bg-amber-50 dark:bg-amber-950/20'
|
||||
: ''
|
||||
}
|
||||
>
|
||||
<TableCell className="font-bold">{i + 1}</TableCell>
|
||||
<TableCell>
|
||||
<div className="flex items-center gap-2">
|
||||
{r.project.id === voteResults.winnerId && (
|
||||
<Crown className="h-4 w-4 text-amber-500" />
|
||||
)}
|
||||
<div>
|
||||
<p className="font-medium">{r.project.title}</p>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{r.project.teamName}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell>{r.votes}</TableCell>
|
||||
<TableCell className="font-semibold">
|
||||
{r.points}
|
||||
</TableCell>
|
||||
<TableCell className="text-right">
|
||||
{r.project.id !== voteResults.winnerId && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => handleSetWinner(r.project.id)}
|
||||
disabled={setWinner.isPending}
|
||||
>
|
||||
<Crown className="mr-1 h-3 w-3" />
|
||||
Set Winner
|
||||
</Button>
|
||||
)}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</Card>
|
||||
</>
|
||||
) : (
|
||||
<Card>
|
||||
<CardContent className="flex flex-col items-center justify-center py-12 text-center">
|
||||
<BarChart3 className="h-12 w-12 text-muted-foreground/50" />
|
||||
<p className="mt-2 font-medium">No votes yet</p>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Votes will appear here once jurors submit their selections
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
206
src/app/(admin)/admin/awards/new/page.tsx
Normal file
206
src/app/(admin)/admin/awards/new/page.tsx
Normal file
@@ -0,0 +1,206 @@
|
||||
'use client'
|
||||
|
||||
import { useState } from 'react'
|
||||
import Link from 'next/link'
|
||||
import { useRouter } from 'next/navigation'
|
||||
import { trpc } from '@/lib/trpc/client'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardDescription,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from '@/components/ui/card'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { Textarea } from '@/components/ui/textarea'
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/components/ui/select'
|
||||
import { toast } from 'sonner'
|
||||
import { ArrowLeft, Save, Loader2 } from 'lucide-react'
|
||||
|
||||
export default function CreateAwardPage() {
|
||||
const router = useRouter()
|
||||
const [name, setName] = useState('')
|
||||
const [description, setDescription] = useState('')
|
||||
const [criteriaText, setCriteriaText] = useState('')
|
||||
const [scoringMode, setScoringMode] = useState<
|
||||
'PICK_WINNER' | 'RANKED' | 'SCORED'
|
||||
>('PICK_WINNER')
|
||||
const [maxRankedPicks, setMaxRankedPicks] = useState('3')
|
||||
const [programId, setProgramId] = useState('')
|
||||
|
||||
const { data: programs } = trpc.program.list.useQuery()
|
||||
const createAward = trpc.specialAward.create.useMutation()
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!name.trim() || !programId) return
|
||||
try {
|
||||
const award = await createAward.mutateAsync({
|
||||
programId,
|
||||
name: name.trim(),
|
||||
description: description.trim() || undefined,
|
||||
criteriaText: criteriaText.trim() || undefined,
|
||||
scoringMode,
|
||||
maxRankedPicks:
|
||||
scoringMode === 'RANKED' ? parseInt(maxRankedPicks) : undefined,
|
||||
})
|
||||
toast.success('Award created')
|
||||
router.push(`/admin/awards/${award.id}`)
|
||||
} catch (error) {
|
||||
toast.error(
|
||||
error instanceof Error ? error.message : 'Failed to create award'
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex items-center gap-4">
|
||||
<Button variant="ghost" asChild className="-ml-4">
|
||||
<Link href="/admin/awards">
|
||||
<ArrowLeft className="mr-2 h-4 w-4" />
|
||||
Back to Awards
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h1 className="text-2xl font-semibold tracking-tight">
|
||||
Create Special Award
|
||||
</h1>
|
||||
<p className="text-muted-foreground">
|
||||
Define a new award with eligibility criteria and voting rules
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Award Details</CardTitle>
|
||||
<CardDescription>
|
||||
Configure the award name, criteria, and scoring mode
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="program">Program</Label>
|
||||
<Select value={programId} onValueChange={setProgramId}>
|
||||
<SelectTrigger id="program">
|
||||
<SelectValue placeholder="Select a program" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{programs?.map((p) => (
|
||||
<SelectItem key={p.id} value={p.id}>
|
||||
{p.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="name">Award Name</Label>
|
||||
<Input
|
||||
id="name"
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
placeholder="e.g., Mediterranean Entrepreneurship Award"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="description">Description</Label>
|
||||
<Textarea
|
||||
id="description"
|
||||
value={description}
|
||||
onChange={(e) => setDescription(e.target.value)}
|
||||
placeholder="Brief description of this award"
|
||||
rows={3}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="criteria">Eligibility Criteria</Label>
|
||||
<Textarea
|
||||
id="criteria"
|
||||
value={criteriaText}
|
||||
onChange={(e) => setCriteriaText(e.target.value)}
|
||||
placeholder="Describe the criteria in plain language. AI will interpret this to evaluate project eligibility."
|
||||
rows={4}
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
This text will be used by AI to determine which projects are
|
||||
eligible for this award.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="scoring">Scoring Mode</Label>
|
||||
<Select
|
||||
value={scoringMode}
|
||||
onValueChange={(v) =>
|
||||
setScoringMode(
|
||||
v as 'PICK_WINNER' | 'RANKED' | 'SCORED'
|
||||
)
|
||||
}
|
||||
>
|
||||
<SelectTrigger id="scoring">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="PICK_WINNER">
|
||||
Pick Winner — Each juror picks 1
|
||||
</SelectItem>
|
||||
<SelectItem value="RANKED">
|
||||
Ranked — Each juror ranks top N
|
||||
</SelectItem>
|
||||
<SelectItem value="SCORED">
|
||||
Scored — Use evaluation form
|
||||
</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{scoringMode === 'RANKED' && (
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="maxPicks">Max Ranked Picks</Label>
|
||||
<Input
|
||||
id="maxPicks"
|
||||
type="number"
|
||||
min="1"
|
||||
max="20"
|
||||
value={maxRankedPicks}
|
||||
onChange={(e) => setMaxRankedPicks(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<div className="flex justify-end gap-4">
|
||||
<Button variant="outline" asChild>
|
||||
<Link href="/admin/awards">Cancel</Link>
|
||||
</Button>
|
||||
<Button
|
||||
onClick={handleSubmit}
|
||||
disabled={createAward.isPending || !name.trim() || !programId}
|
||||
>
|
||||
{createAward.isPending ? (
|
||||
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
||||
) : (
|
||||
<Save className="mr-2 h-4 w-4" />
|
||||
)}
|
||||
Create Award
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
140
src/app/(admin)/admin/awards/page.tsx
Normal file
140
src/app/(admin)/admin/awards/page.tsx
Normal file
@@ -0,0 +1,140 @@
|
||||
'use client'
|
||||
|
||||
import Link from 'next/link'
|
||||
import { trpc } from '@/lib/trpc/client'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardDescription,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from '@/components/ui/card'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
import { Plus, Trophy, Users, CheckCircle2 } from 'lucide-react'
|
||||
|
||||
const STATUS_COLORS: Record<string, 'default' | 'secondary' | 'destructive' | 'outline'> = {
|
||||
DRAFT: 'secondary',
|
||||
NOMINATIONS_OPEN: 'default',
|
||||
VOTING_OPEN: 'default',
|
||||
CLOSED: 'outline',
|
||||
ARCHIVED: 'secondary',
|
||||
}
|
||||
|
||||
const SCORING_LABELS: Record<string, string> = {
|
||||
PICK_WINNER: 'Pick Winner',
|
||||
RANKED: 'Ranked',
|
||||
SCORED: 'Scored',
|
||||
}
|
||||
|
||||
export default function AwardsListPage() {
|
||||
const { data: awards, isLoading } = trpc.specialAward.list.useQuery({})
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex items-center justify-between">
|
||||
<Skeleton className="h-9 w-48" />
|
||||
<Skeleton className="h-9 w-32" />
|
||||
</div>
|
||||
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{[...Array(3)].map((_, i) => (
|
||||
<Skeleton key={i} className="h-48" />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 className="text-2xl font-semibold tracking-tight">
|
||||
Special Awards
|
||||
</h1>
|
||||
<p className="text-muted-foreground">
|
||||
Manage named awards with eligibility criteria and jury voting
|
||||
</p>
|
||||
</div>
|
||||
<Button asChild>
|
||||
<Link href="/admin/awards/new">
|
||||
<Plus className="mr-2 h-4 w-4" />
|
||||
Create Award
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* Awards Grid */}
|
||||
{awards && awards.length > 0 ? (
|
||||
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{awards.map((award) => (
|
||||
<Link key={award.id} href={`/admin/awards/${award.id}`}>
|
||||
<Card className="transition-colors hover:bg-muted/50 cursor-pointer h-full">
|
||||
<CardHeader className="pb-3">
|
||||
<div className="flex items-start justify-between">
|
||||
<CardTitle className="text-lg flex items-center gap-2">
|
||||
<Trophy className="h-5 w-5 text-amber-500" />
|
||||
{award.name}
|
||||
</CardTitle>
|
||||
<Badge variant={STATUS_COLORS[award.status] || 'secondary'}>
|
||||
{award.status.replace('_', ' ')}
|
||||
</Badge>
|
||||
</div>
|
||||
{award.description && (
|
||||
<CardDescription className="line-clamp-2">
|
||||
{award.description}
|
||||
</CardDescription>
|
||||
)}
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="flex items-center gap-4 text-sm text-muted-foreground">
|
||||
<div className="flex items-center gap-1">
|
||||
<CheckCircle2 className="h-4 w-4" />
|
||||
{award._count.eligibilities} eligible
|
||||
</div>
|
||||
<div className="flex items-center gap-1">
|
||||
<Users className="h-4 w-4" />
|
||||
{award._count.jurors} jurors
|
||||
</div>
|
||||
<Badge variant="outline" className="text-xs">
|
||||
{SCORING_LABELS[award.scoringMode] || award.scoringMode}
|
||||
</Badge>
|
||||
</div>
|
||||
{award.winnerProject && (
|
||||
<div className="mt-3 pt-3 border-t">
|
||||
<p className="text-sm">
|
||||
<span className="text-muted-foreground">Winner:</span>{' '}
|
||||
<span className="font-medium">
|
||||
{award.winnerProject.title}
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<Card>
|
||||
<CardContent className="flex flex-col items-center justify-center py-12 text-center">
|
||||
<Trophy className="h-12 w-12 text-muted-foreground/50" />
|
||||
<p className="mt-2 font-medium">No awards yet</p>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Create special awards for outstanding projects
|
||||
</p>
|
||||
<Button className="mt-4" asChild>
|
||||
<Link href="/admin/awards/new">
|
||||
<Plus className="mr-2 h-4 w-4" />
|
||||
Create Award
|
||||
</Link>
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user