@@ -8,9 +8,19 @@ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/com
88import { Badge } from '@/components/ui/badge'
99import { Input } from '@/components/ui/input'
1010import { Table , TableBody , TableCell , TableHead , TableHeader , TableRow } from '@/components/ui/table'
11- import { Trophy , Search , Plus , Edit , Eye , Clock , CheckCircle , XCircle , AlertCircle } from 'lucide-react'
11+ import { Trophy , Search , Plus , Edit , Eye , Clock , CheckCircle , XCircle , AlertCircle , Trash2 } from 'lucide-react'
1212import { toast } from 'sonner'
1313import Link from 'next/link'
14+ import {
15+ AlertDialog ,
16+ AlertDialogAction ,
17+ AlertDialogCancel ,
18+ AlertDialogContent ,
19+ AlertDialogDescription ,
20+ AlertDialogFooter ,
21+ AlertDialogHeader ,
22+ AlertDialogTitle ,
23+ } from '@/components/ui/alert-dialog'
1424
1525interface Hackathon {
1626 id : string
@@ -34,6 +44,9 @@ export default function CompanyHackathonsPage() {
3444 const [ hackathons , setHackathons ] = useState < Hackathon [ ] > ( [ ] )
3545 const [ loading , setLoading ] = useState ( true )
3646 const [ searchTerm , setSearchTerm ] = useState ( '' )
47+ const [ deleteDialogOpen , setDeleteDialogOpen ] = useState ( false )
48+ const [ hackathonToDelete , setHackathonToDelete ] = useState < Hackathon | null > ( null )
49+ const [ isDeleting , setIsDeleting ] = useState ( false )
3750
3851 const canManageEvents = userRole && [ 'owner' , 'admin' , 'editor' ] . includes ( userRole )
3952
@@ -65,6 +78,40 @@ export default function CompanyHackathonsPage() {
6578 }
6679 } , [ currentCompany , fetchHackathons ] )
6780
81+ const handleDeleteClick = ( hackathon : Hackathon ) => {
82+ setHackathonToDelete ( hackathon )
83+ setDeleteDialogOpen ( true )
84+ }
85+
86+ const handleDeleteConfirm = async ( ) => {
87+ if ( ! hackathonToDelete || ! currentCompany ) return
88+
89+ try {
90+ setIsDeleting ( true )
91+ // Use slug instead of id for the API endpoint
92+ const response = await fetch ( `/api/hackathons/${ hackathonToDelete . slug } ` , {
93+ method : 'DELETE' ,
94+ } )
95+
96+ if ( ! response . ok ) {
97+ const errorData = await response . json ( )
98+ throw new Error ( errorData . error || 'Failed to delete hackathon' )
99+ }
100+
101+ toast . success ( 'Hackathon deleted successfully' )
102+ setDeleteDialogOpen ( false )
103+ setHackathonToDelete ( null )
104+
105+ // Refresh the list
106+ fetchHackathons ( )
107+ } catch ( error ) {
108+ console . error ( 'Error deleting hackathon:' , error )
109+ toast . error ( error instanceof Error ? error . message : 'Failed to delete hackathon' )
110+ } finally {
111+ setIsDeleting ( false )
112+ }
113+ }
114+
68115 if ( companyLoading || isPendingInvitation ) {
69116 return (
70117 < div className = "flex items-center justify-center min-h-[60vh]" >
@@ -287,17 +334,26 @@ export default function CompanyHackathonsPage() {
287334 < TableCell >
288335 < div className = "flex items-center gap-2" >
289336 < Link href = { `/dashboard/company/${ currentCompany . slug } /hackathons/${ hackathon . slug } /edit` } >
290- < Button variant = "outline" size = "sm" >
337+ < Button variant = "outline" size = "sm" title = "Edit hackathon" >
291338 < Edit className = "h-4 w-4" />
292339 </ Button >
293340 </ Link >
294341 { hackathon . approval_status === 'approved' && (
295342 < Link href = { `/hackathons/${ hackathon . slug } ` } target = "_blank" >
296- < Button variant = "outline" size = "sm" >
343+ < Button variant = "outline" size = "sm" title = "View public page" >
297344 < Eye className = "h-4 w-4" />
298345 </ Button >
299346 </ Link >
300347 ) }
348+ < Button
349+ variant = "outline"
350+ size = "sm"
351+ onClick = { ( ) => handleDeleteClick ( hackathon ) }
352+ className = "text-red-600 hover:text-red-700 hover:bg-red-50"
353+ title = "Delete hackathon"
354+ >
355+ < Trash2 className = "h-4 w-4" />
356+ </ Button >
301357 </ div >
302358 </ TableCell >
303359 ) : (
@@ -318,6 +374,29 @@ export default function CompanyHackathonsPage() {
318374 ) }
319375 </ CardContent >
320376 </ Card >
377+
378+ { /* Delete Confirmation Dialog */ }
379+ < AlertDialog open = { deleteDialogOpen } onOpenChange = { setDeleteDialogOpen } >
380+ < AlertDialogContent >
381+ < AlertDialogHeader >
382+ < AlertDialogTitle > Are you sure?</ AlertDialogTitle >
383+ < AlertDialogDescription >
384+ This will permanently delete the hackathon "{ hackathonToDelete ?. title } ".
385+ This action cannot be undone.
386+ </ AlertDialogDescription >
387+ </ AlertDialogHeader >
388+ < AlertDialogFooter >
389+ < AlertDialogCancel disabled = { isDeleting } > Cancel</ AlertDialogCancel >
390+ < AlertDialogAction
391+ onClick = { handleDeleteConfirm }
392+ disabled = { isDeleting }
393+ className = "bg-red-600 hover:bg-red-700"
394+ >
395+ { isDeleting ? 'Deleting...' : 'Delete' }
396+ </ AlertDialogAction >
397+ </ AlertDialogFooter >
398+ </ AlertDialogContent >
399+ </ AlertDialog >
321400 </ div >
322401 )
323402}
0 commit comments