1+ import { useState } from "react" ;
2+ import { motion } from "framer-motion" ;
3+ import { ApiService } from "@/lib/api" ;
4+ import type { Team } from "@/lib/types" ;
5+
6+ interface DeleteConfirmationModalProps {
7+ team : Team ;
8+ isOpen : boolean ;
9+ onClose : ( ) => void ;
10+ onDelete : ( deletedTeamId : number ) => void ;
11+ }
12+
13+ export default function DeleteConfirmationModal ( {
14+ team,
15+ isOpen,
16+ onClose,
17+ onDelete
18+ } : DeleteConfirmationModalProps ) {
19+ const [ isDeleting , setIsDeleting ] = useState ( false ) ;
20+ const [ error , setError ] = useState < string | null > ( null ) ;
21+
22+ const handleDelete = async ( ) => {
23+ setIsDeleting ( true ) ;
24+ setError ( null ) ;
25+
26+ try {
27+ const response = await ApiService . admin . deleteTeam ( team . teamId ) ;
28+
29+ if ( response . success ) {
30+ onDelete ( team . teamId ) ;
31+ onClose ( ) ;
32+ }
33+ } catch ( error : any ) {
34+ console . error ( "Failed to delete team:" , error ) ;
35+ setError ( error . response ?. data ?. message || "Failed to delete team. Please try again." ) ;
36+ } finally {
37+ setIsDeleting ( false ) ;
38+ }
39+ } ;
40+
41+ if ( ! isOpen ) return null ;
42+
43+ return (
44+ < div className = "fixed inset-0 z-[70] flex items-center justify-center" >
45+ { /* Background overlay */ }
46+ < div
47+ className = "absolute inset-0 bg-black/50"
48+ onClick = { ! isDeleting ? onClose : undefined }
49+ />
50+
51+ { /* Modal */ }
52+ < motion . div
53+ className = "relative bg-white dark:bg-gray-900 rounded-lg shadow-xl w-full max-w-md mx-4 p-6"
54+ initial = { { opacity : 0 , scale : 0.95 } }
55+ animate = { { opacity : 1 , scale : 1 } }
56+ exit = { { opacity : 0 , scale : 0.95 } }
57+ transition = { { duration : 0.2 } }
58+ >
59+ { /* Warning Icon */ }
60+ < div className = "flex items-center justify-center w-12 h-12 mx-auto mb-4 bg-red-100 dark:bg-red-900/20 rounded-full" >
61+ < svg className = "w-6 h-6 text-red-600 dark:text-red-400" fill = "none" stroke = "currentColor" viewBox = "0 0 24 24" >
62+ < path strokeLinecap = "round" strokeLinejoin = "round" strokeWidth = { 2 } d = "M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.732-.833-2.464 0L4.732 15.5c-.77.833.192 2.5 1.732 2.5z" />
63+ </ svg >
64+ </ div >
65+
66+ < div className = "text-center mb-6" >
67+ < h2 className = "text-xl font-bold text-gray-900 dark:text-white mb-2" >
68+ Delete Team?
69+ </ h2 >
70+ < p className = "text-gray-600 dark:text-gray-400 mb-4" >
71+ Are you sure you want to delete < span className = "font-semibold text-gray-900 dark:text-white" > "{ team . title } "</ span > ?
72+ </ p >
73+ < div className = "bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-3 mb-4" >
74+ < p className = "text-sm text-red-800 dark:text-red-300" >
75+ < strong > This action cannot be undone.</ strong > All team data, members, and associated records will be permanently deleted.
76+ </ p >
77+ </ div >
78+ < div className = "text-sm text-gray-500 dark:text-gray-400 space-y-1" >
79+ < p > < strong > Team ID:</ strong > { team . teamId } </ p >
80+ < p > < strong > SCC ID:</ strong > { team . scc_id } </ p >
81+ < p > < strong > Members:</ strong > { team . members ?. length || 0 } people</ p >
82+ </ div >
83+ </ div >
84+
85+ { /* Error Display */ }
86+ { error && (
87+ < div className = "mb-4 p-3 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg" >
88+ < p className = "text-sm text-red-600 dark:text-red-400" > { error } </ p >
89+ </ div >
90+ ) }
91+
92+ { /* Action buttons */ }
93+ < div className = "flex gap-3" >
94+ < button
95+ type = "button"
96+ onClick = { onClose }
97+ className = "flex-1 px-4 py-2 text-gray-700 dark:text-gray-300 bg-gray-100 dark:bg-gray-700 hover:bg-gray-200 dark:hover:bg-gray-600 rounded-lg transition-colors"
98+ disabled = { isDeleting }
99+ >
100+ Cancel
101+ </ button >
102+ < button
103+ onClick = { handleDelete }
104+ className = "flex-1 px-4 py-2 text-white bg-red-600 hover:bg-red-700 disabled:bg-gray-400 rounded-lg transition-colors flex items-center justify-center"
105+ disabled = { isDeleting }
106+ >
107+ { isDeleting ? (
108+ < >
109+ < div className = "w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin mr-2" />
110+ Deleting...
111+ </ >
112+ ) : (
113+ < >
114+ < svg className = "w-4 h-4 mr-2" fill = "none" stroke = "currentColor" viewBox = "0 0 24 24" >
115+ < path strokeLinecap = "round" strokeLinejoin = "round" strokeWidth = { 2 } d = "M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
116+ </ svg >
117+ Delete Team
118+ </ >
119+ ) }
120+ </ button >
121+ </ div >
122+ </ motion . div >
123+ </ div >
124+ ) ;
125+ }
0 commit comments