From 578d38f187b65f3b817d22bfe441997fbe38e547 Mon Sep 17 00:00:00 2001 From: Steve White Date: Thu, 17 Oct 2024 09:04:28 -0500 Subject: [PATCH] More UI fixes to Admin.js --- src/components/Admin.js | 166 ++++++++++++++++++++++++++++------------ 1 file changed, 115 insertions(+), 51 deletions(-) diff --git a/src/components/Admin.js b/src/components/Admin.js index 4c464e4..3a2e68e 100644 --- a/src/components/Admin.js +++ b/src/components/Admin.js @@ -4,6 +4,21 @@ import axios from 'axios'; import { Link, useNavigate } from 'react-router-dom'; import { PRIMARY_COLOR, SECONDARY_COLOR } from '../App'; import './Admin.css'; // Import the CSS file +import { + Typography, + Table, + TableBody, + TableCell, + TableContainer, + TableHead, + TableRow, + Paper, + Button, + Alert, + Container, + Box, + TextField + } from '@mui/material'; export default function Admin() { @@ -26,6 +41,19 @@ export default function Admin() { }); }, []); + const fetchUsers = async () => { + try { + const response = await axios.get(`${process.env.REACT_APP_API_URL}/admin/user`, { + headers: { Authorization: `Bearer ${localStorage.getItem('token')}` } + }); + setUsers(response.data); + } catch (error) { + console.error('Error fetching users:', error); + // Optionally, set an error message + // setErrorMessage('Failed to fetch users. Please try again.'); + } + }; + const handleCreateUser = async (e) => { e.preventDefault(); try { @@ -49,6 +77,9 @@ export default function Admin() { headers: { Authorization: `Bearer ${localStorage.getItem('token')}` } }); setUsers(users.filter(user => user.id !== id)); + //setUsers(prevUsers => prevUsers.filter(user => user.id !== id)); + fetchUsers(); + } catch (error) { console.error(error); } @@ -103,54 +134,87 @@ export default function Admin() { }; return ( -
-

Admin

- - - - - - - - - {users.map(user => ( - - - - - ))} - -
UsernameActions
{user.username} - -
-
- setUsername(e.target.value)} placeholder="Username" /> - setPassword(e.target.value)} placeholder="Password" /> - -
-

Database

- - - - - - - - - - - - - - - - - -
Action
Backup - -
Restore - - -
-
- )}; \ No newline at end of file + + + Admin + + + + + Add New User + + setUsername(e.target.value)} + sx={{ mr: 2 }} + /> + setPassword(e.target.value)} + sx={{ mr: 2 }} + /> + + + + + + + + Username + Actions + + + + {users.map(user => ( + + {user.username} + + + + + ))} + +
+
+ + + + + + +
+ ); +} \ No newline at end of file