1- import React , { useState , useContext } from "react" ;
2- import { AdminContext } from "../../context/AdminContext" ;
3- import { registerUser } from "../../services/auth" ;
4- import isIITBhilaiEmail from "../../utils/emailValidator" ;
5- import { useNavigate } from "react-router-dom" ;
61import GoogleIcon from "@mui/icons-material/Google" ;
72import cosa from "../../assets/COSA.png" ;
83import backgroundImage from "../../assets/iitbh.jpg" ;
9- import { toast } from "react-toastify" ;
104
115export default function Register ( ) {
12- const { setIsUserLoggedIn } = useContext ( AdminContext ) ;
13- const [ name , setName ] = useState ( "" ) ;
14- const [ ID , setId ] = useState ( "" ) ;
15- const [ email , setEmail ] = useState ( "" ) ;
16- const [ password , setPassword ] = useState ( "" ) ;
17- const [ loading , setLoading ] = useState ( false ) ;
18- const navigate = useNavigate ( ) ;
19-
20- const handleSubmit = async ( e ) => {
21- e . preventDefault ( ) ;
22- setLoading ( true ) ;
23-
24- if ( ! isIITBhilaiEmail ( email ) ) {
25- toast . error ( "Please use an @iitbhilai.ac.in email address." ) ;
26- setLoading ( false ) ;
27- return ;
28- }
29-
30- try {
31- const status = await registerUser ( name , ID , email , password ) ;
32- if ( status ) {
33- setIsUserLoggedIn ( true ) ;
34- toast . success ( "Registration successful! 🎉" ) ;
35- navigate ( "/" , { replace : true } ) ;
36- } else {
37- toast . error ( "Registration failed. Please try again." ) ;
38- }
39- } catch ( error ) {
40- console . error ( "Register failed:" , error ) ;
41- toast . error ( "Something went wrong. Please try again." ) ;
42- } finally {
43- setLoading ( false ) ;
44- }
45- } ;
46-
476 return (
487 < div
498 className = "min-h-screen w-full flex items-center justify-center p-4 relative"
@@ -64,102 +23,40 @@ export default function Register() {
6423 />
6524 { /* Shade Overlay */ }
6625 < div className = "absolute inset-0 bg-black/40" style = { { zIndex : 1 } } />
67-
26+
6827 { /* Main container */ }
6928 < div
7029 className = "flex flex-wrap flex-col-reverse lg:flex-row items-center justify-center gap-12 lg:gap-16 w-full max-w-7xl relative"
7130 style = { { zIndex : 2 } }
7231 >
73- < div >
74- < form
75- onSubmit = { handleSubmit }
76- className = "bg-white p-8 rounded-xl shadow-md w-full max-w-md sm:max-w-lg md:max-w-xl"
32+ < div className = "w-full max-w-md" >
33+ < div
34+ className = "bg-white p-12 rounded-xl shadow-md"
7735 style = { {
7836 boxShadow : `
7937 0 20px 40px rgba(0, 0, 0, 0.15),
80- 0 10px 20px rgba(0, 0, 0, 0.1),
81- 0 4px 8px rgba(0, 0, 0, 0.08),
82- inset 0 1px 0 rgba(255, 255, 255, 0.8)
38+ 0 10px 20px rgba(0, 0, 0, 0.1)
8339 ` ,
8440 } }
8541 >
8642 < h2 className = "text-2xl font-bold text-center mb-6" > Sign Up</ h2 >
8743 < hr className = "mb-6" />
8844
89- { /* Name */ }
90- < label className = "block text-sm mb-2 font-medium" > Name</ label >
91- < input
92- type = "text"
93- value = { name }
94- onChange = { ( e ) => setName ( e . target . value ) }
95- className = "w-full border border-gray-300 rounded-md px-3 py-1 mb-3 focus:outline-none focus:ring-2 focus:ring-black"
96- required
97- />
98-
99- { /* ID */ }
100- < label className = "block text-sm mb-2 font-medium" > ID</ label >
101- < input
102- type = "number"
103- value = { ID }
104- onChange = { ( e ) => setId ( e . target . value ) }
105- className = "w-full border border-gray-300 rounded-md px-3 py-1 mb-3 focus:outline-none focus:ring-2 focus:ring-black"
106- required
107- />
108-
109- { /* Email */ }
110- < label className = "block text-sm mb-2 font-medium" > Email</ label >
111- < input
112- type = "email"
113- value = { email }
114- onChange = { ( e ) => setEmail ( e . target . value ) }
115- className = "w-full border border-gray-300 rounded-md px-3 py-1 mb-3 focus:outline-none focus:ring-2 focus:ring-black"
116- required
117- />
118-
119- { /* Password */ }
120- < label className = "block text-sm mb-2 font-medium" > Password</ label >
121- < input
122- type = "password"
123- value = { password }
124- onChange = { ( e ) => setPassword ( e . target . value ) }
125- className = "w-full border border-gray-300 rounded-md px-3 py-1 mb-4 focus:outline-none focus:ring-2 focus:ring-black"
126- required
127- />
128-
129- { /* Register Button */ }
130- < button
131- type = "submit"
132- disabled = { loading }
133- className = { `w-full py-2 rounded-md mb-3 font-medium ${
134- loading
135- ? "bg-gray-400 cursor-not-allowed"
136- : "bg-black text-white hover:opacity-90"
137- } `}
138- >
139- { loading ? "Registering..." : "Register" }
140- </ button >
141-
142- < div className = "flex items-center my-1" >
143- < hr className = "flex-1 border-gray-300" />
144- < span className = "mx-3 text-gray-500 text-sm" > OR</ span >
145- < hr className = "flex-1 border-gray-300" />
146- </ div >
147-
14845 { /* Google Register */ }
14946 < a
15047 href = { `${ process . env . REACT_APP_BACKEND_URL } /auth/google` }
15148 className = "block"
15249 >
15350 < button
15451 type = "button"
155- className = "w-full bg-[#23659C] text-white py-2 rounded-md flex items-center justify-center space-x-2 hover:opacity-90 font-medium"
52+ className = "w-full bg-[#23659C] text-white py-3 rounded-md flex items-center justify-center space-x-2 hover:opacity-90 font-medium transition-all "
15653 >
15754 < span > Sign up with Google</ span >
15855 < GoogleIcon />
15956 </ button >
16057 </ a >
16158
162- < p className = "text-center text-sm mt-4 " >
59+ < p className = "text-center text-sm mt-6 p-2 " >
16360 Already have an account?{ " " }
16461 < a
16562 href = "/login"
@@ -168,10 +65,10 @@ export default function Register() {
16865 Login
16966 </ a >
17067 </ p >
171- </ form >
68+ </ div >
17269 </ div >
17370
174- { /* CoSA Logo outside form */ }
71+ { /* CoSA Logo */ }
17572 < div className = "flex flex-col items-center text-white w-full max-w-xs mb-8 lg:mb-0" >
17673 < img src = { cosa } alt = "CoSA Logo" className = "w-52 h-52 mb-6" />
17774 < h1 className = "text-2xl font-semibold" > CoSA</ h1 >
0 commit comments