@@ -137,6 +137,7 @@ export default function HackathonsPage() {
137137 const [ hackathonToDelete , setHackathonToDelete ] = useState < {
138138 id : string ;
139139 title : string ;
140+ type : 'draft' | 'hackathon' ;
140141 } | null > ( null ) ;
141142
142143 const { hackathons, hackathonsLoading, drafts, draftsLoading, refetchAll } =
@@ -148,13 +149,12 @@ export default function HackathonsPage() {
148149 // Use the separate delete hook
149150 const { isDeleting, deleteHackathon } = useDeleteHackathon ( {
150151 organizationId,
151- hackathonId : hackathonToDelete ?. id || '' , // This will be set when we have a hackathon to delete
152+ hackathonId : hackathonToDelete ?. id || '' ,
153+ type : hackathonToDelete ?. type ?? 'hackathon' ,
154+ suppressToast : true ,
152155 onSuccess : ( ) => {
153156 // Refresh the hackathons list after successful deletion
154157 refetchAll ( ) ;
155- toast . success ( 'Hackathon deleted successfully' , {
156- description : `"${ hackathonToDelete ?. title } " has been permanently deleted.` ,
157- } ) ;
158158 } ,
159159 onError : error => {
160160 toast . error ( 'Failed to delete hackathon' , {
@@ -217,37 +217,47 @@ export default function HackathonsPage() {
217217 return { published, drafts : drafts . length , total } ;
218218 } , [ hackathons , drafts ] ) ;
219219
220- const handleDeleteClick = ( hackathonId : string ) => {
221- // Try to find in published hackathons
222- const published = publishedHackathons . find ( h => h . id === hackathonId ) ;
223- if ( published ) {
224- setHackathonToDelete ( {
225- id : hackathonId ,
226- title : published . name || 'Untitled Hackathon' ,
227- } ) ;
228- setDeleteDialogOpen ( true ) ;
229- return ;
230- }
231- // Try to find in drafts
232- const draft = draftHackathons . find ( d => d . id === hackathonId ) ;
233- if ( draft ) {
234- setHackathonToDelete ( {
235- id : hackathonId ,
236- title : draft . data . information ?. name || 'Untitled Hackathon' ,
237- } ) ;
238- setDeleteDialogOpen ( true ) ;
220+ const handleDeleteClick = (
221+ hackathonId : string ,
222+ type : 'draft' | 'hackathon'
223+ ) => {
224+ if ( type === 'hackathon' ) {
225+ const published = publishedHackathons . find ( h => h . id === hackathonId ) ;
226+ if ( published ) {
227+ setHackathonToDelete ( {
228+ id : hackathonId ,
229+ title : published . name || 'Untitled Hackathon' ,
230+ type : 'hackathon' ,
231+ } ) ;
232+ setDeleteDialogOpen ( true ) ;
233+ }
234+ } else {
235+ const draft = draftHackathons . find ( d => d . id === hackathonId ) ;
236+ if ( draft ) {
237+ setHackathonToDelete ( {
238+ id : hackathonId ,
239+ title : draft . data . information ?. name || 'Untitled Hackathon' ,
240+ type : 'draft' ,
241+ } ) ;
242+ setDeleteDialogOpen ( true ) ;
243+ }
239244 }
240245 } ;
241246
242247 const handleDeleteConfirm = async ( ) => {
243248 if ( ! hackathonToDelete ) return ;
244249
250+ const { title } = hackathonToDelete ; // ✅ snapshot before state clears
251+
245252 setDeleteDialogOpen ( false ) ;
246253
247254 try {
248255 await deleteHackathon ( ) ;
256+ toast . success ( 'Hackathon deleted successfully' , {
257+ description : `"${ title } " has been permanently deleted.` ,
258+ } ) ;
249259 } catch {
250- // Error handled by toast in deleteHackathon hook
260+ // error toast handled by onError in hook
251261 } finally {
252262 setHackathonToDelete ( null ) ;
253263 }
@@ -520,7 +530,7 @@ export default function HackathonsPage() {
520530 < button
521531 onClick = { e => {
522532 e . stopPropagation ( ) ;
523- handleDeleteClick ( hackathon . id ) ;
533+ handleDeleteClick ( hackathon . id , 'hackathon' ) ;
524534 } }
525535 className = 'flex h-9 w-9 items-center justify-center rounded-lg border border-zinc-800 bg-zinc-900/70 text-zinc-400 hover:border-red-600 hover:text-red-500'
526536 title = 'Delete Hackathon'
@@ -636,7 +646,7 @@ export default function HackathonsPage() {
636646 < button
637647 onClick = { e => {
638648 e . stopPropagation ( ) ;
639- handleDeleteClick ( draft . id ) ;
649+ handleDeleteClick ( draft . id , 'draft' ) ;
640650 } }
641651 className = 'flex h-9 w-9 items-center justify-center rounded-lg border border-zinc-800 bg-zinc-900/70 text-zinc-400 hover:border-red-600 hover:text-red-500'
642652 title = 'Delete Draft'
0 commit comments