1- import React , { useState } from "react" ;
1+ import React , { useState , useEffect } from "react" ;
22
33export default function AdminDashboard ( ) {
44 const [ formData , setFormData ] = useState ( {
@@ -10,11 +10,13 @@ export default function AdminDashboard() {
1010 role : "auditee" ,
1111 } ) ;
1212 const [ message , setMessage ] = useState ( "" ) ;
13+ const [ users , setUsers ] = useState ( [ ] ) ;
1314
1415 const handleChange = ( e ) => {
1516 setFormData ( { ...formData , [ e . target . name ] : e . target . value } ) ;
1617 } ;
1718
19+ // Create new user
1820 const handleSubmit = async ( e ) => {
1921 e . preventDefault ( ) ;
2022 setMessage ( "Creating user..." ) ;
@@ -29,6 +31,7 @@ export default function AdminDashboard() {
2931 const data = await res . json ( ) ;
3032 if ( data . ok ) {
3133 setMessage ( "✅ User created successfully!" ) ;
34+ fetchUsers ( ) ;
3235 setFormData ( {
3336 name : "" ,
3437 email : "" ,
@@ -45,45 +48,69 @@ export default function AdminDashboard() {
4548 }
4649 } ;
4750
51+ // Fetch users for admin view
52+ const fetchUsers = async ( ) => {
53+ try {
54+ const res = await fetch (
55+ "https://fat-eibl-backend-x1sp.onrender.com/users/all"
56+ ) ;
57+ const data = await res . json ( ) ;
58+ if ( data . ok ) setUsers ( data . users ) ;
59+ } catch ( e ) {
60+ console . error ( "Failed to load users" , e ) ;
61+ }
62+ } ;
63+
64+ useEffect ( ( ) => {
65+ fetchUsers ( ) ;
66+ } , [ ] ) ;
67+
4868 return (
4969 < div
5070 style = { {
51- backgroundColor : "#f7faff " ,
71+ background : "linear-gradient(180deg, #f5f9ff 0%, #ffffff 100%) " ,
5272 minHeight : "100vh" ,
5373 display : "flex" ,
5474 flexDirection : "column" ,
5575 alignItems : "center" ,
56- padding : "40px 20px" ,
76+ padding : "50px 20px" ,
5777 fontFamily : "'Inter', sans-serif" ,
5878 } }
5979 >
60- { /* Header */ }
61- < div style = { { textAlign : "center" , marginBottom : "30px" } } >
62- < h1 style = { { color : "#004aad" , fontSize : "2rem" , fontWeight : 700 } } >
80+ { /* HEADER */ }
81+ < div style = { { textAlign : "center" , marginBottom : "40px" } } >
82+ < h1
83+ style = { {
84+ fontSize : "2.3rem" ,
85+ color : "#004aad" ,
86+ fontWeight : "700" ,
87+ marginBottom : "10px" ,
88+ } }
89+ >
6390 👨💼 Admin Dashboard
6491 </ h1 >
65- < p style = { { color : "#5a6a85 " , fontSize : "1rem" } } >
66- Manage users and assign departments efficiently .
92+ < p style = { { color : "#5f6c85 " , fontSize : "1rem" } } >
93+ Manage users, departments, and system access .
6794 </ p >
6895 </ div >
6996
70- { /* Card */ }
97+ { /* FORM CARD */ }
7198 < div
7299 style = { {
73- background : "white " ,
74- padding : "40px 30px " ,
75- borderRadius : "16px " ,
100+ background : "#fff " ,
101+ padding : "40px" ,
102+ borderRadius : "20px " ,
76103 width : "100%" ,
77- maxWidth : "550px " ,
78- boxShadow : "0 4px 20px rgba(0,0,0,0.08 )" ,
79- transition : "0.3s ease-in-out " ,
104+ maxWidth : "600px " ,
105+ boxShadow : "0 4px 20px rgba(0,0,0,0.1 )" ,
106+ marginBottom : "40px " ,
80107 } }
81108 >
82109 < h2
83110 style = { {
84111 color : "#004aad" ,
112+ fontWeight : "600" ,
85113 marginBottom : "25px" ,
86- fontSize : "1.3rem" ,
87114 borderBottom : "2px solid #004aad" ,
88115 display : "inline-block" ,
89116 paddingBottom : "5px" ,
@@ -93,73 +120,52 @@ export default function AdminDashboard() {
93120 </ h2 >
94121
95122 < form onSubmit = { handleSubmit } >
96- < div style = { { marginBottom : "15px" } } >
97- < input
98- type = "text"
99- name = "name"
100- placeholder = "Full Name"
101- value = { formData . name }
102- onChange = { handleChange }
103- required
104- style = { inputStyle }
105- />
106- </ div >
107-
108- < div style = { { marginBottom : "15px" } } >
109- < input
110- type = "email"
111- name = "email"
112- placeholder = "Email"
113- value = { formData . email }
114- onChange = { handleChange }
115- required
116- style = { inputStyle }
117- />
118- </ div >
119-
120- < div style = { { marginBottom : "15px" } } >
121- < input
122- type = "password"
123- name = "password"
124- placeholder = "Password"
125- value = { formData . password }
126- onChange = { handleChange }
127- required
128- style = { inputStyle }
129- />
130- </ div >
131-
132- < div style = { { marginBottom : "15px" } } >
133- < input
134- type = "text"
135- name = "department"
136- placeholder = "Department"
137- value = { formData . department }
138- onChange = { handleChange }
139- style = { inputStyle }
140- />
141- </ div >
142-
143- < div style = { { marginBottom : "15px" } } >
144- < input
145- type = "email"
146- name = "manager_email"
147- placeholder = "Manager Email"
148- value = { formData . manager_email }
149- onChange = { handleChange }
150- style = { inputStyle }
151- />
152- </ div >
123+ { [ "name" , "email" , "password" , "department" , "manager_email" ] . map (
124+ ( field , idx ) => (
125+ < div key = { idx } style = { { marginBottom : "15px" } } >
126+ < input
127+ type = { field === "password" ? "password" : "text" }
128+ name = { field }
129+ placeholder = {
130+ field === "manager_email"
131+ ? "Manager Email"
132+ : field . charAt ( 0 ) . toUpperCase ( ) + field . slice ( 1 )
133+ }
134+ value = { formData [ field ] }
135+ onChange = { handleChange }
136+ required = { field !== "manager_email" }
137+ style = { {
138+ width : "100%" ,
139+ padding : "12px 15px" ,
140+ borderRadius : "10px" ,
141+ border : "1px solid #d0d7e2" ,
142+ backgroundColor : "#f8faff" ,
143+ fontSize : "1rem" ,
144+ outline : "none" ,
145+ transition : "0.2s" ,
146+ } }
147+ onFocus = { ( e ) =>
148+ ( e . target . style . border = "1px solid #004aad" )
149+ }
150+ onBlur = { ( e ) => ( e . target . style . border = "1px solid #d0d7e2" ) }
151+ />
152+ </ div >
153+ )
154+ ) }
153155
154156 < div style = { { marginBottom : "20px" } } >
155157 < select
156158 name = "role"
157159 value = { formData . role }
158160 onChange = { handleChange }
159161 style = { {
160- ...inputStyle ,
162+ width : "100%" ,
163+ padding : "12px 15px" ,
164+ borderRadius : "10px" ,
165+ border : "1px solid #d0d7e2" ,
166+ backgroundColor : "#f8faff" ,
167+ fontSize : "1rem" ,
161168 cursor : "pointer" ,
162- backgroundColor : "#fff" ,
163169 } }
164170 >
165171 < option value = "auditee" > Auditee</ option >
@@ -174,26 +180,29 @@ export default function AdminDashboard() {
174180 width : "100%" ,
175181 backgroundColor : "#004aad" ,
176182 color : "white" ,
177- padding : "12px" ,
178- fontSize : "1rem" ,
183+ padding : "14px" ,
179184 borderRadius : "10px" ,
180185 border : "none" ,
186+ fontSize : "1rem" ,
187+ fontWeight : "600" ,
181188 cursor : "pointer" ,
182- fontWeight : 600 ,
183- transition : "background 0.3s" ,
189+ transition : "0.3s" ,
184190 } }
185- onMouseOver = { ( e ) => ( e . target . style . backgroundColor = "#003b85" ) }
186- onMouseOut = { ( e ) => ( e . target . style . backgroundColor = "#004aad" ) }
191+ onMouseOver = { ( e ) =>
192+ ( e . target . style . backgroundColor = "#003b85" )
193+ }
194+ onMouseOut = { ( e ) =>
195+ ( e . target . style . backgroundColor = "#004aad" )
196+ }
187197 >
188198 Create User
189199 </ button >
190200 </ form >
191201
192- { /* Message Display */ }
193202 { message && (
194203 < p
195204 style = { {
196- marginTop : "20px " ,
205+ marginTop : "15px " ,
197206 textAlign : "center" ,
198207 color : message . startsWith ( "✅" )
199208 ? "green"
@@ -208,20 +217,86 @@ export default function AdminDashboard() {
208217 ) }
209218 </ div >
210219
211- { /* Footer */ }
220+ { /* USER LIST */ }
221+ < div
222+ style = { {
223+ width : "100%" ,
224+ maxWidth : "800px" ,
225+ background : "#fff" ,
226+ padding : "25px 30px" ,
227+ borderRadius : "16px" ,
228+ boxShadow : "0 3px 12px rgba(0,0,0,0.08)" ,
229+ } }
230+ >
231+ < h3
232+ style = { {
233+ color : "#004aad" ,
234+ marginBottom : "15px" ,
235+ borderBottom : "2px solid #004aad" ,
236+ display : "inline-block" ,
237+ paddingBottom : "4px" ,
238+ } }
239+ >
240+ Registered Users
241+ </ h3 >
242+ { users . length === 0 ? (
243+ < p style = { { color : "#7d8ba1" , textAlign : "center" } } >
244+ No users found.
245+ </ p >
246+ ) : (
247+ < table
248+ style = { {
249+ width : "100%" ,
250+ borderCollapse : "collapse" ,
251+ textAlign : "left" ,
252+ } }
253+ >
254+ < thead >
255+ < tr style = { { background : "#f5f9ff" } } >
256+ < th style = { thStyle } > Name</ th >
257+ < th style = { thStyle } > Email</ th >
258+ < th style = { thStyle } > Department</ th >
259+ < th style = { thStyle } > Role</ th >
260+ </ tr >
261+ </ thead >
262+ < tbody >
263+ { users . map ( ( u , i ) => (
264+ < tr
265+ key = { i }
266+ style = { {
267+ borderBottom : "1px solid #e5e9f2" ,
268+ backgroundColor : i % 2 === 0 ? "#fafbff" : "white" ,
269+ } }
270+ >
271+ < td style = { tdStyle } > { u . name } </ td >
272+ < td style = { tdStyle } > { u . email } </ td >
273+ < td style = { tdStyle } > { u . department || "-" } </ td >
274+ < td style = { tdStyle } > { u . role } </ td >
275+ </ tr >
276+ ) ) }
277+ </ tbody >
278+ </ table >
279+ ) }
280+ </ div >
281+
282+ { /* FOOTER */ }
212283 < p style = { { marginTop : "40px" , color : "#7c8ca5" , fontSize : "0.9rem" } } >
213- © { new Date ( ) . getFullYear ( ) } Edme Insurance Brokers Ltd | Finance Audit Tracker
284+ © { new Date ( ) . getFullYear ( ) } Edme Insurance Brokers Ltd | Finance Audit
285+ Tracker
214286 </ p >
215287 </ div >
216288 ) ;
217289}
218290
219- const inputStyle = {
220- width : "100%" ,
221- padding : "10px 14px" ,
222- borderRadius : "10px" ,
223- border : "1px solid #ccc" ,
224- outline : "none" ,
225- fontSize : "1rem" ,
226- transition : "border 0.3s ease" ,
291+ const thStyle = {
292+ padding : "10px 15px" ,
293+ color : "#003b80" ,
294+ fontWeight : "600" ,
295+ borderBottom : "2px solid #004aad" ,
296+ } ;
297+
298+ const tdStyle = {
299+ padding : "10px 15px" ,
300+ color : "#333" ,
301+ fontSize : "0.95rem" ,
227302} ;
0 commit comments