@@ -20,6 +20,8 @@ import Box from '@mui/material/Box';
20
20
import { useRouter } from 'next/router' ;
21
21
import { ToastContainer , toast } from 'react-toastify' ;
22
22
import 'react-toastify/dist/ReactToastify.css' ;
23
+ import { Dialog , Transition } from '@headlessui/react' ;
24
+ import { Fragment } from 'react' ;
23
25
24
26
export default function Create ( ) {
25
27
const router = useRouter ( ) ;
@@ -254,6 +256,52 @@ export default function Create() {
254
256
fetchNotifications ( ) ;
255
257
} , [ ] ) ;
256
258
259
+ const [ showCreatorMode , setShowCreatorMode ] = useState ( null ) ;
260
+
261
+ const [ isEnableModalOpen , setIsEnableModalOpen ] = useState ( false ) ;
262
+ const [ isDisableModalOpen , setIsDisableModalOpen ] = useState ( false ) ;
263
+
264
+ const handleEnableCreatorMode = async ( ) => {
265
+ try {
266
+ await request ( `${ process . env . NEXT_PUBLIC_API_URL } /account/creatorMode` , 'POST' , { creatorMode : true } ) ;
267
+ setIsEnableModalOpen ( false ) ;
268
+ // Additional logic to enable creator mode
269
+ setCreatorMode ( true ) ;
270
+ setShowCreatorMode ( true ) ;
271
+ toast . success ( 'Creator mode enabled successfully' ) ;
272
+ } catch ( error ) {
273
+ console . error ( 'Error enabling creator mode:' , error ) ;
274
+ toast . error ( 'Failed to enable creator mode' ) ;
275
+ }
276
+ } ;
277
+
278
+ const handleDisableCreatorMode = async ( ) => {
279
+ try {
280
+ await request ( `${ process . env . NEXT_PUBLIC_API_URL } /account/creatorMode` , 'POST' , { creatorMode : false } ) ;
281
+ setIsDisableModalOpen ( false ) ;
282
+ setCreatorMode ( false ) ;
283
+ setShowCreatorMode ( true ) ;
284
+ toast . success ( 'Creator mode disabled successfully' ) ;
285
+ } catch ( error ) {
286
+ console . error ( 'Error disabling creator mode:' , error ) ;
287
+ }
288
+ } ;
289
+
290
+ const [ creatorMode , setCreatorMode ] = useState ( false ) ;
291
+
292
+ useEffect ( ( ) => {
293
+ const fetchCreatorMode = async ( ) => {
294
+ try {
295
+ const response = await request ( `${ process . env . NEXT_PUBLIC_API_URL } /account` , "GET" , null ) ;
296
+ setCreatorMode ( response . creatorMode ) ;
297
+ } catch ( error ) {
298
+ console . error ( 'Error fetching creator mode:' , error ) ;
299
+ }
300
+ } ;
301
+
302
+ fetchCreatorMode ( ) ;
303
+ } , [ ] ) ;
304
+
257
305
return (
258
306
< >
259
307
< Head >
@@ -489,7 +537,7 @@ export default function Create() {
489
537
) }
490
538
</ div >
491
539
492
- < hr className = 'mt-4 border-neutral-700 ' > </ hr >
540
+ < hr className = 'mt-4 border-neutral-800 ' > </ hr >
493
541
< div className = " mt-4 pb-4 " >
494
542
< div className = "flex items-center" >
495
543
< h1 className = "flex-1 text-2xl font-medium text-white" >
@@ -567,8 +615,8 @@ export default function Create() {
567
615
</ div >
568
616
569
617
570
- < hr className = 'mt-4 border-neutral-700' > </ hr >
571
- < div className = " mt-4 pb-4 " >
618
+ < hr className = 'mt-4 border-neutral-700 hidden ' > </ hr >
619
+ < div className = " mt-4 pb-4 hidden " >
572
620
< div className = "flex items-center" >
573
621
< h1 className = "flex-1 text-2xl font-medium text-white" >
574
622
< div className = "flex" >
@@ -593,7 +641,7 @@ export default function Create() {
593
641
< th scope = "col" className = "px-3 py-3.5 text-left text-sm font-semibold text--white" >
594
642
Module Name
595
643
</ th >
596
-
644
+
597
645
598
646
< th scope = "col" className = "px-3 py-3.5 text-left text-sm font-semibold text--white" >
599
647
Last Updated
@@ -643,6 +691,135 @@ export default function Create() {
643
691
</ div >
644
692
645
693
< div className = " pr-4 sm:pr-6 lg:flex-shrink-0 lg:border-neutral-700 lg:pr-8 xl:pr-0 " >
694
+
695
+ < button
696
+ className = { `mb-4 float-right ${ creatorMode ? 'bg-blue-700 hover:bg-blue-700/90' : 'bg-blue-700 hover:bg-blue-700/90' } text-sm shadow-sm px-2 py-1 text-white rounded-sm mr-3` }
697
+ onClick = { ( ) => creatorMode ? setIsDisableModalOpen ( true ) : setIsEnableModalOpen ( true ) }
698
+ >
699
+ { creatorMode ? 'Disable Creator Mode' : 'Enable Creator Mode' }
700
+ </ button >
701
+
702
+
703
+ < Transition appear show = { isEnableModalOpen } as = { Fragment } >
704
+ < Dialog as = "div" className = "relative z-10" onClose = { ( ) => setIsEnableModalOpen ( false ) } >
705
+ < Transition . Child
706
+ as = { Fragment }
707
+ enter = "ease-out duration-300"
708
+ enterFrom = "opacity-0 scale-95"
709
+ enterTo = "opacity-100 scale-100"
710
+ leave = "ease-in duration-200"
711
+ leaveFrom = "opacity-100 scale-100"
712
+ leaveTo = "opacity-0 scale-95"
713
+ >
714
+ < div className = "fixed inset-0 bg-black bg-opacity-25" />
715
+ </ Transition . Child >
716
+
717
+ < div className = "fixed inset-0 overflow-y-auto" >
718
+ < div className = "flex min-h-full items-center justify-center p-4 text-center" >
719
+ < Transition . Child
720
+ as = { Fragment }
721
+ enter = "ease-out duration-300"
722
+ enterFrom = "opacity-0 scale-95"
723
+ enterTo = "opacity-100 scale-100"
724
+ leave = "ease-in duration-200"
725
+ leaveFrom = "opacity-100 scale-100"
726
+ leaveTo = "opacity-0 scale-95"
727
+ >
728
+ < Dialog . Panel className = "w-full max-w-lg transform overflow-hidden rounded-2xl bg-neutral-800 p-6 text-left align-middle shadow-xl transition-all" >
729
+ < Dialog . Title as = "h3" className = "text-lg font-medium leading-6 text-white" >
730
+ Enable Creator Mode < span className = 'text-sm text-gray-300' > BETA</ span >
731
+ </ Dialog . Title >
732
+ < div className = "mt-2" >
733
+ < img src = "/insightDemo.png" className = 'mt-4 mb-4 w-3/4 mx-auto rounded-lg shadow-lg border-none shadow-blur shadow-blue-900/50' > </ img >
734
+ < p className = "text-md text-gray-300 mt-3" >
735
+ Creator mode will allow you to see insights for every challenge on CTFGuide. You're welcome to leverage this data when creating challenges.
736
+ < br > </ br > < br > </ br >
737
+
738
+ Are you sure you want to enable creator mode?
739
+ </ p >
740
+ </ div >
741
+
742
+ < div className = "mt-4" >
743
+ < button
744
+ type = "button"
745
+ className = "inline-flex justify-center rounded-md border border-transparent bg-blue-900 px-4 py-2 text-sm font-medium text-white hover:bg-blue-800 focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2"
746
+ onClick = { handleEnableCreatorMode }
747
+ >
748
+ Yes, Enable
749
+ </ button >
750
+ < button
751
+ type = "button"
752
+ className = "ml-2 inline-flex justify-center rounded-md border border-transparent bg-red-900 px-4 py-2 text-sm font-medium text-white hover:bg-red-800 focus:outline-none focus-visible:ring-2 focus-visible:ring-red-500 focus-visible:ring-offset-2"
753
+ onClick = { ( ) => setIsEnableModalOpen ( false ) }
754
+ >
755
+ Cancel
756
+ </ button >
757
+ </ div >
758
+ </ Dialog . Panel >
759
+ </ Transition . Child >
760
+ </ div >
761
+ </ div >
762
+ </ Dialog >
763
+ </ Transition >
764
+
765
+ < Transition appear show = { isDisableModalOpen } as = { Fragment } >
766
+ < Dialog as = "div" className = "relative z-10" onClose = { ( ) => setIsDisableModalOpen ( false ) } >
767
+ < Transition . Child
768
+ as = { Fragment }
769
+ enter = "ease-out duration-300"
770
+ enterFrom = "opacity-0 scale-95"
771
+ enterTo = "opacity-100 scale-100"
772
+ leave = "ease-in duration-200"
773
+ leaveFrom = "opacity-100 scale-100"
774
+ leaveTo = "opacity-0 scale-95"
775
+ >
776
+ < div className = "fixed inset-0 bg-black bg-opacity-25" />
777
+ </ Transition . Child >
778
+
779
+ < div className = "fixed inset-0 overflow-y-auto" >
780
+ < div className = "flex min-h-full items-center justify-center p-4 text-center" >
781
+ < Transition . Child
782
+ as = { Fragment }
783
+ enter = "ease-out duration-300"
784
+ enterFrom = "opacity-0 scale-95"
785
+ enterTo = "opacity-100 scale-100"
786
+ leave = "ease-in duration-200"
787
+ leaveFrom = "opacity-100 scale-100"
788
+ leaveTo = "opacity-0 scale-95"
789
+ >
790
+ < Dialog . Panel className = "w-full max-w-md transform overflow-hidden rounded-2xl bg-neutral-800 p-6 text-left align-middle shadow-xl transition-all" >
791
+ < Dialog . Title as = "h3" className = "text-lg font-medium leading-6 text-white" >
792
+ Disable Creator Mode
793
+ </ Dialog . Title >
794
+ < div className = "mt-2" >
795
+ < p className = "text-sm text-gray-300" >
796
+ Are you sure you want to disable creator mode?
797
+ </ p >
798
+ </ div >
799
+
800
+ < div className = "mt-4" >
801
+ < button
802
+ type = "button"
803
+ className = "inline-flex justify-center rounded-md border border-transparent bg-blue-900 px-4 py-2 text-sm font-medium text-white hover:bg-blue-800 focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2"
804
+ onClick = { handleDisableCreatorMode }
805
+ >
806
+ Yes, Disable
807
+ </ button >
808
+ < button
809
+ type = "button"
810
+ className = "ml-2 inline-flex justify-center rounded-md border border-transparent bg-red-900 px-4 py-2 text-sm font-medium text-white hover:bg-red-800 focus:outline-none focus-visible:ring-2 focus-visible:ring-red-500 focus-visible:ring-offset-2"
811
+ onClick = { ( ) => setIsDisableModalOpen ( false ) }
812
+ >
813
+ Cancel
814
+ </ button >
815
+ </ div >
816
+ </ Dialog . Panel >
817
+ </ Transition . Child >
818
+ </ div >
819
+ </ div >
820
+ </ Dialog >
821
+ </ Transition >
822
+
646
823
< div className = "pl-6 lg:w-80" >
647
824
< div className = "pt-6 pb-2" >
648
825
< h2 className = "text-2xl text-white " > Challenge Notifications</ h2 >
@@ -673,6 +850,9 @@ export default function Create() {
673
850
) }
674
851
</ ul >
675
852
</ div >
853
+
854
+
855
+
676
856
</ div >
677
857
</ div >
678
858
</ div >
@@ -711,7 +891,7 @@ export default function Create() {
711
891
712
892
< br > </ br >
713
893
< br > </ br >
714
- < hr className = 'border-neutral-700 ' > </ hr >
894
+ < hr className = 'border-neutral-800 ' > </ hr >
715
895
< br > </ br >
716
896
If you disagree with the changes, please join our < a href = 'https://discord.gg/bH6gu3HCFF' className = 'text-blue-500 hover:text-blue-600' > < i className = 'fab fa-discord ' > </ i > Discord</ a > and voice your opinion.
717
897
< br > </ br >
0 commit comments