2026-01-30 13:41:32 +01:00
|
|
|
'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 {
|
|
|
|
|
DropdownMenu,
|
|
|
|
|
DropdownMenuContent,
|
|
|
|
|
DropdownMenuItem,
|
|
|
|
|
DropdownMenuSeparator,
|
|
|
|
|
DropdownMenuTrigger,
|
|
|
|
|
} from '@/components/ui/dropdown-menu'
|
|
|
|
|
import {
|
|
|
|
|
AlertDialog,
|
|
|
|
|
AlertDialogAction,
|
|
|
|
|
AlertDialogCancel,
|
|
|
|
|
AlertDialogContent,
|
|
|
|
|
AlertDialogDescription,
|
|
|
|
|
AlertDialogFooter,
|
|
|
|
|
AlertDialogHeader,
|
|
|
|
|
AlertDialogTitle,
|
|
|
|
|
} from '@/components/ui/alert-dialog'
|
|
|
|
|
import { toast } from 'sonner'
|
|
|
|
|
import {
|
|
|
|
|
MoreHorizontal,
|
|
|
|
|
Mail,
|
|
|
|
|
UserCog,
|
|
|
|
|
Trash2,
|
|
|
|
|
Loader2,
|
|
|
|
|
} from 'lucide-react'
|
|
|
|
|
|
|
|
|
|
interface UserActionsProps {
|
|
|
|
|
userId: string
|
|
|
|
|
userEmail: string
|
|
|
|
|
userStatus: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function UserActions({ userId, userEmail, userStatus }: UserActionsProps) {
|
|
|
|
|
const router = useRouter()
|
|
|
|
|
const [showDeleteDialog, setShowDeleteDialog] = useState(false)
|
|
|
|
|
const [isSending, setIsSending] = useState(false)
|
|
|
|
|
|
|
|
|
|
const sendInvitation = trpc.user.sendInvitation.useMutation()
|
|
|
|
|
const deleteUser = trpc.user.delete.useMutation()
|
|
|
|
|
|
|
|
|
|
const handleSendInvitation = async () => {
|
|
|
|
|
if (userStatus !== 'INVITED') {
|
|
|
|
|
toast.error('User has already accepted their invitation')
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setIsSending(true)
|
|
|
|
|
try {
|
|
|
|
|
await sendInvitation.mutateAsync({ userId })
|
|
|
|
|
toast.success(`Invitation sent to ${userEmail}`)
|
|
|
|
|
} catch (error) {
|
|
|
|
|
toast.error(error instanceof Error ? error.message : 'Failed to send invitation')
|
|
|
|
|
} finally {
|
|
|
|
|
setIsSending(false)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleDelete = async () => {
|
|
|
|
|
try {
|
|
|
|
|
await deleteUser.mutateAsync({ id: userId })
|
|
|
|
|
toast.success('User deleted successfully')
|
|
|
|
|
setShowDeleteDialog(false)
|
|
|
|
|
router.refresh()
|
|
|
|
|
} catch (error) {
|
|
|
|
|
toast.error(error instanceof Error ? error.message : 'Failed to delete user')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<DropdownMenu>
|
|
|
|
|
<DropdownMenuTrigger asChild>
|
|
|
|
|
<Button variant="ghost" size="icon">
|
|
|
|
|
{isSending ? (
|
|
|
|
|
<Loader2 className="h-4 w-4 animate-spin" />
|
|
|
|
|
) : (
|
|
|
|
|
<MoreHorizontal className="h-4 w-4" />
|
|
|
|
|
)}
|
|
|
|
|
<span className="sr-only">Actions</span>
|
|
|
|
|
</Button>
|
|
|
|
|
</DropdownMenuTrigger>
|
|
|
|
|
<DropdownMenuContent align="end">
|
|
|
|
|
<DropdownMenuItem asChild>
|
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>
2026-02-02 16:58:29 +01:00
|
|
|
<Link href={`/admin/members/${userId}`}>
|
2026-01-30 13:41:32 +01:00
|
|
|
<UserCog className="mr-2 h-4 w-4" />
|
|
|
|
|
Edit
|
|
|
|
|
</Link>
|
|
|
|
|
</DropdownMenuItem>
|
|
|
|
|
<DropdownMenuItem
|
|
|
|
|
onClick={handleSendInvitation}
|
|
|
|
|
disabled={userStatus !== 'INVITED' || isSending}
|
|
|
|
|
>
|
|
|
|
|
<Mail className="mr-2 h-4 w-4" />
|
|
|
|
|
{isSending ? 'Sending...' : 'Send Invite'}
|
|
|
|
|
</DropdownMenuItem>
|
|
|
|
|
<DropdownMenuSeparator />
|
|
|
|
|
<DropdownMenuItem
|
|
|
|
|
className="text-destructive focus:text-destructive"
|
|
|
|
|
onClick={() => setShowDeleteDialog(true)}
|
|
|
|
|
>
|
|
|
|
|
<Trash2 className="mr-2 h-4 w-4" />
|
|
|
|
|
Remove
|
|
|
|
|
</DropdownMenuItem>
|
|
|
|
|
</DropdownMenuContent>
|
|
|
|
|
</DropdownMenu>
|
|
|
|
|
|
|
|
|
|
<AlertDialog open={showDeleteDialog} onOpenChange={setShowDeleteDialog}>
|
|
|
|
|
<AlertDialogContent>
|
|
|
|
|
<AlertDialogHeader>
|
|
|
|
|
<AlertDialogTitle>Delete User</AlertDialogTitle>
|
|
|
|
|
<AlertDialogDescription>
|
|
|
|
|
Are you sure you want to delete {userEmail}? This action cannot be
|
|
|
|
|
undone and will remove all their assignments and evaluations.
|
|
|
|
|
</AlertDialogDescription>
|
|
|
|
|
</AlertDialogHeader>
|
|
|
|
|
<AlertDialogFooter>
|
|
|
|
|
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
|
|
|
|
<AlertDialogAction
|
|
|
|
|
onClick={handleDelete}
|
|
|
|
|
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
|
|
|
|
>
|
|
|
|
|
{deleteUser.isPending ? (
|
|
|
|
|
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
|
|
|
|
) : null}
|
|
|
|
|
Delete
|
|
|
|
|
</AlertDialogAction>
|
|
|
|
|
</AlertDialogFooter>
|
|
|
|
|
</AlertDialogContent>
|
|
|
|
|
</AlertDialog>
|
|
|
|
|
</>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface UserMobileActionsProps {
|
|
|
|
|
userId: string
|
|
|
|
|
userEmail: string
|
|
|
|
|
userStatus: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function UserMobileActions({
|
|
|
|
|
userId,
|
|
|
|
|
userEmail,
|
|
|
|
|
userStatus,
|
|
|
|
|
}: UserMobileActionsProps) {
|
|
|
|
|
const [isSending, setIsSending] = useState(false)
|
|
|
|
|
const sendInvitation = trpc.user.sendInvitation.useMutation()
|
|
|
|
|
|
|
|
|
|
const handleSendInvitation = async () => {
|
|
|
|
|
if (userStatus !== 'INVITED') {
|
|
|
|
|
toast.error('User has already accepted their invitation')
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setIsSending(true)
|
|
|
|
|
try {
|
|
|
|
|
await sendInvitation.mutateAsync({ userId })
|
|
|
|
|
toast.success(`Invitation sent to ${userEmail}`)
|
|
|
|
|
} catch (error) {
|
|
|
|
|
toast.error(error instanceof Error ? error.message : 'Failed to send invitation')
|
|
|
|
|
} finally {
|
|
|
|
|
setIsSending(false)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex gap-2 pt-2">
|
|
|
|
|
<Button variant="outline" size="sm" className="flex-1" asChild>
|
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>
2026-02-02 16:58:29 +01:00
|
|
|
<Link href={`/admin/members/${userId}`}>
|
2026-01-30 13:41:32 +01:00
|
|
|
<UserCog className="mr-2 h-4 w-4" />
|
|
|
|
|
Edit
|
|
|
|
|
</Link>
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
|
|
|
|
size="sm"
|
|
|
|
|
className="flex-1"
|
|
|
|
|
onClick={handleSendInvitation}
|
|
|
|
|
disabled={userStatus !== 'INVITED' || isSending}
|
|
|
|
|
>
|
|
|
|
|
{isSending ? (
|
|
|
|
|
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
|
|
|
|
) : (
|
|
|
|
|
<Mail className="mr-2 h-4 w-4" />
|
|
|
|
|
)}
|
|
|
|
|
Invite
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|