1- import React , { useState } from "react" ;
1+ import React , { useState , useEffect } from "react" ;
22import { Link , useNavigate } from "react-router-dom" ;
33import "../styles/App.css" ;
44import { FaEnvelope , FaLock , FaEye , FaEyeSlash } from "react-icons/fa" ;
@@ -13,20 +13,28 @@ function Home() {
1313 const [ formData , setFormData ] = useState ( {
1414 email : "" ,
1515 password : "" ,
16+
1617 role : "student" ,
1718 } ) ;
1819 const [ showPassword , setShowPassword ] = useState ( false ) ;
20+ const [ role ] = useState ( "student" ) ;
21+
22+ // Sync role into formData.role
23+ useEffect ( ( ) => {
24+ setFormData ( ( prev ) => ( { ...prev , role } ) ) ;
25+ } , [ role ] ) ;
1926
2027 const handleInputChange = ( e ) => {
2128 const { name, value } = e . target ;
22- setFormData ( ( prev ) => ( {
23- ...prev ,
29+ setFormData ( {
30+ ...formData ,
2431 [ name ] : value ,
25- } ) ) ;
32+ } ) ;
2633 } ;
2734
2835 const handleSubmit = async ( e ) => {
2936 e . preventDefault ( ) ;
37+
3038 const { email : ouEmail , password, role } = formData ;
3139
3240
@@ -47,7 +55,7 @@ function Home() {
4755 "Content-Type" : "application/json" ,
4856 } ,
4957 body : JSON . stringify ( { ouEmail, password, role } ) ,
50- }
58+ } ,
5159 ) ;
5260
5361 const data = await response . json ( ) ;
@@ -56,29 +64,22 @@ function Home() {
5664 const user = data . user ;
5765 if ( role === "student" ) {
5866 // Store only required fields
59- const limitedUserInfo = {
60- fullName : user . fullName ,
61- id : user . _id ,
62- email :user . ouEmail
63- } ;
64-
65- localStorage . setItem ( "ipmsUser" , JSON . stringify ( limitedUserInfo ) ) ;
66- navigate ( "/student-dashboard" ) ;
67- } else if ( role === "supervisor" ) {
67+ const limitedUserInfo = {
68+ fullName : user . fullName ,
69+ id : user . _id ,
70+ email :user . ouEmail
71+ } ;
72+
73+ localStorage . setItem ( "ipmsUser" , JSON . stringify ( limitedUserInfo ) ) ;
74+ navigate ( "/student-dashboard" ) ;
75+ } else if ( role === "supervisor" ) {
6876 Swal . fire ( {
6977 icon : "success" ,
7078 title : "Login Successful 🌟" ,
7179 text : `Welcome back, ${ role } !` ,
7280 } ) ;
7381 navigate ( "/supervisor-dashboard" ) ;
74- } else if ( role === "coordinator" ) {
75- Swal . fire ( {
76- icon : "success" ,
77- title : "Login Successful 🌟" ,
78- text : `Welcome back, ${ role } !` ,
79- } ) ;
80- navigate ( "/coordinator-dashboard" ) ;
81- } else {
82+ } else {
8283 Swal . fire ( {
8384 icon : "success" ,
8485 title : "Login Successful 🌟" ,
@@ -100,7 +101,6 @@ function Home() {
100101 Swal . fire ( {
101102 icon : "error" ,
102103 title : "Login Failed" ,
103- text : data . message || "Something went wrong" ,
104104 html : data . message + " " +
105105 ( data . renewalLink
106106 ? `Please click <a href="${ data . renewalLink } " target="_blank" rel="noopener noreferrer">here</a> to request a new token.`
@@ -125,7 +125,9 @@ function Home() {
125125 </ div >
126126
127127 < div className = "login-options" >
128- < h2 style = { { fontWeight : "600" , fontSize : "1.9rem" } } > Welcome back</ h2 >
128+ < h2 style = { { fontWeight : "600" , fontSize : "1.9rem" } } >
129+ Welcome back
130+ </ h2 >
129131
130132 < form className = "login-form" onSubmit = { handleSubmit } >
131133 < div className = "form-group" >
@@ -144,32 +146,27 @@ function Home() {
144146 formData . role === r ? "selected" : ""
145147 } `}
146148 onClick = { ( ) =>
147- setFormData ( ( prev ) => ( { ...prev , role : r } ) )
149+ setFormData ( {
150+ ...formData ,
151+ role : r ,
152+ } )
148153 }
149154
150155 >
151156 < Icon />
152157 < p className = "role-label" >
153158 { r . charAt ( 0 ) . toUpperCase ( ) + r . slice ( 1 ) }
154159 </ p >
155- < span
156- className = "info-icon"
157- title = {
158- r === "student"
159- ? "Students request internships and submit weekly reports."
160- : r === "supervisor"
161- ? "Supervisors review and approve student progress."
162- : "Coordinators manage the internship workflow and approvals."
163- }
164- > </ span >
165160 </ div >
166161 ) ) }
167162 </ div >
168163 </ div >
169164
170165 < div className = "form-group clean-input" >
171166 < label htmlFor = "email" >
172- < FaEnvelope style = { { marginRight : "6px" , verticalAlign : "middle" } } />
167+ < FaEnvelope
168+ style = { { marginRight : "6px" , verticalAlign : "middle" } }
169+ />
173170 Email
174171 </ label >
175172 < input
@@ -185,7 +182,9 @@ function Home() {
185182
186183 < div className = "form-group clean-input" >
187184 < label htmlFor = "password" >
188- < FaLock style = { { marginRight : "6px" , verticalAlign : "middle" } } />
185+ < FaLock
186+ style = { { marginRight : "6px" , verticalAlign : "middle" } }
187+ />
189188 Password
190189 </ label >
191190 < div className = "password-wrapper" >
@@ -207,7 +206,15 @@ function Home() {
207206 </ div >
208207 </ div >
209208
210- < div className = "form-subtext" >
209+ < div
210+ className = "form-subtext"
211+ style = { {
212+ display : "flex" ,
213+ justifyContent : "space-between" ,
214+ fontSize : "0.9rem" ,
215+ marginBottom : "1rem" ,
216+ } }
217+ >
211218 < label className = "d-flex align-items-center" >
212219 < input type = "checkbox" style = { { marginRight : "6px" } } />
213220 Remember me
0 commit comments