@@ -17,6 +17,9 @@ export default function Manage() {
1717 const [ imagePreview , setImagePreview ] = useState ( null ) ;
1818 const [ deleteType , setDeleteType ] = useState ( "" ) ;
1919 const [ userReady , setUserReady ] = useState ( false ) ;
20+ const [ showDeleteModal , setShowDeleteModal ] = useState ( false ) ;
21+ const [ pendingDelete , setPendingDelete ] = useState ( null ) ;
22+
2023const [ copiedId , setCopiedId ] = useState ( null ) ;
2124
2225const copyToClipboard = async ( text ) => {
@@ -36,6 +39,14 @@ const copyToClipboard = async (text) => {
3639 useEffect ( ( ) => {
3740 if ( userReady && auth . currentUser ) fetchQuestions ( ) ;
3841 } , [ category ] ) ;
42+ const isAddDisabled =
43+ ! newQuestion . trim ( ) ||
44+ ( questionType === "MCQ" &&
45+ (
46+ correctIndex === "" ||
47+ mcqOptions . filter ( o => o . trim ( ) !== "" ) . length !== 4
48+ ) ) ;
49+
3950
4051 const fetchQuestions = async ( ) => {
4152 try {
@@ -160,6 +171,47 @@ const copyToClipboard = async (text) => {
160171
161172 return (
162173 < div className = "min-h-screen w-full bg-black p-4 sm:p-8 flex justify-center" >
174+
175+
176+ { showDeleteModal && (
177+ < div className = "fixed inset-0 z-50 flex items-center justify-center bg-black/70 backdrop-blur-sm" >
178+ < div className = "bg-neutral-900 border border-red-500/30 rounded-2xl p-6 w-full max-w-sm shadow-2xl" >
179+ < h3 className = "text-lg font-semibold text-white mb-2" >
180+ Delete Question?
181+ </ h3 >
182+
183+ < p className = "text-sm text-neutral-400 mb-6" >
184+ This action cannot be undone.
185+ </ p >
186+
187+ < div className = "flex justify-end gap-3" >
188+ < button
189+ onClick = { ( ) => {
190+ setShowDeleteModal ( false ) ;
191+ setPendingDelete ( null ) ;
192+ } }
193+ className = "px-4 py-2 rounded-lg bg-neutral-700 hover:bg-neutral-600 text-sm"
194+ >
195+ Cancel
196+ </ button >
197+
198+ < button
199+ onClick = { ( ) => {
200+ handleDeleteQuestion (
201+ pendingDelete . id ,
202+ pendingDelete . type
203+ ) ;
204+ setShowDeleteModal ( false ) ;
205+ setPendingDelete ( null ) ;
206+ } }
207+ className = "px-4 py-2 rounded-lg bg-red-600 hover:bg-red-700 text-sm font-semibold"
208+ >
209+ Delete
210+ </ button >
211+ </ div >
212+ </ div >
213+ </ div >
214+ ) }
163215 < div className = "bg-white/10 p-6 sm:p-10 rounded-2xl w-full max-w-5xl border border-yellow-500/20 shadow-xl" >
164216
165217 < div className = "flex flex-col sm:flex-row items-center sm:items-start justify-between gap-6 mb-10" >
@@ -261,29 +313,33 @@ const copyToClipboard = async (text) => {
261313 value = { correctIndex }
262314 onChange = { ( e ) => setCorrectIndex ( Number ( e . target . value ) ) }
263315 >
264- < option value = "" > Select an option </ option >
316+ < option value = "" > Enter Correct Option </ option >
265317 { mcqOptions . map ( ( opt , idx ) => (
266318 < option key = { idx } value = { idx } className = "bg-black text-white" >
267319 { opt . trim ( ) || `Option ${ idx + 1 } ` }
268320 </ option >
269321 ) ) }
270322 </ select >
271323
272- < button
273- onClick = { addOptionField }
274- className = "mt-4 ml-4 bg-blue-500 hover:bg-blue-400 text-white px-5 py-2 rounded-xl transition"
275- >
276- + Add Option
277- </ button >
324+ < button
325+ onClick = { addOptionField }
326+ disabled = { mcqOptions . filter ( o => o . trim ( ) !== "" ) . length >= 4 }
327+ className = "mt-4 ml-4 bg-blue-500 disabled:bg-blue-500/40 disabled:cursor-not-allowed hover:bg-blue-400 text-white px-5 py-2 rounded-xl transition"
328+ >
329+ + Add Option
330+ </ button >
331+
278332 </ div >
279333 ) }
280334
281- < button
282- onClick = { handleAddQuestion }
283- className = "mt-8 w-full bg-green-500 hover:bg-green-400 transition text-white py-3 rounded-xl text-lg font-bold"
284- >
285- Add Question
286- </ button >
335+ < button
336+ onClick = { handleAddQuestion }
337+ disabled = { isAddDisabled }
338+ className = "mt-8 w-full bg-green-500 disabled:bg-green-500/40 disabled:cursor-not-allowed hover:bg-green-400 transition text-white py-3 rounded-xl text-lg font-bold"
339+ >
340+ Add Question
341+ </ button >
342+
287343 </ div >
288344
289345 < input
@@ -308,12 +364,16 @@ const copyToClipboard = async (text) => {
308364 key = { q . id }
309365 className = "relative p-5 bg-black/20 border border-yellow-500/20 rounded-2xl"
310366>
311- < button
312- onClick = { ( ) => handleDeleteQuestion ( q . id , q . type ) }
313- className = "absolute top-4 right-4 bg-red-600 hover:bg-red-700 px-3 py-1.5 rounded-lg text-xs font-semibold"
314- >
315- Delete
316- </ button >
367+ < button
368+ onClick = { ( ) => {
369+ setPendingDelete ( { id : q . id , type : q . type } ) ;
370+ setShowDeleteModal ( true ) ;
371+ } }
372+ className = "absolute top-4 right-4 bg-red-600 hover:bg-red-700 px-3 py-1.5 rounded-lg text-xs font-semibold"
373+ >
374+ Delete
375+ </ button >
376+
317377
318378 < p className = "text-white font-semibold" > { q . text } </ p >
319379
0 commit comments