From 052b50cd28e61c08af7bc919d87fc49021ffd455 Mon Sep 17 00:00:00 2001 From: Purvesh Date: Thu, 28 Dec 2023 10:07:37 +1300 Subject: [PATCH] admin user table --- react-admin/src/App.js | 2 + .../src/layouts/partials/AppSidebar.jsx | 11 ++ .../src/pages/admin-user/AdminUserTable.jsx | 102 ++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 react-admin/src/pages/admin-user/AdminUserTable.jsx diff --git a/react-admin/src/App.js b/react-admin/src/App.js index e8457916..cc1661e0 100644 --- a/react-admin/src/App.js +++ b/react-admin/src/App.js @@ -7,6 +7,7 @@ import AppLayout from "./layouts/AppLayout"; import PageTable from "./pages/page/PageTable"; import PageCreate from "./pages/page/PageCreate"; import PageEdit from "./pages/page/PageEdit"; +import AdminUserTable from "./pages/admin-user/AdminUserTable"; function App() { return ( @@ -22,6 +23,7 @@ function App() { } /> } /> } /> + } /> diff --git a/react-admin/src/layouts/partials/AppSidebar.jsx b/react-admin/src/layouts/partials/AppSidebar.jsx index 0431b314..ae255a82 100644 --- a/react-admin/src/layouts/partials/AppSidebar.jsx +++ b/react-admin/src/layouts/partials/AppSidebar.jsx @@ -77,6 +77,17 @@ function AppSidebar() { + +
+ +
+
+ Admin User +
+
+ +
diff --git a/react-admin/src/pages/admin-user/AdminUserTable.jsx b/react-admin/src/pages/admin-user/AdminUserTable.jsx new file mode 100644 index 00000000..c8efdbdb --- /dev/null +++ b/react-admin/src/pages/admin-user/AdminUserTable.jsx @@ -0,0 +1,102 @@ +import {useEffect, useState} from "react"; +import {Link, redirect, useNavigate} from "react-router-dom"; +import {isEmpty} from "lodash"; + +function AdminUserTable() { + const [adminUsers, setAdminUsers] = useState([]); + const navigate = useNavigate() + + const getFormattedDate = ((date) => { + var date = new Date(date); + + return `${date.getFullYear()}-${date.getMonth()}-${date.getDate()}`; + }) + + useEffect(() => { + const mounted = (async () => { + const response = await fetch('http://localhost:8080/api/admin-user', { + method: 'get', + headers: { + 'Content-Type': 'application/json', + 'Authorization': 'Bearer ' + localStorage.getItem("AUTH_TOKEN"), + } + }) + console.log(response.ok) + if (!response.ok) { + return + } + return await response.json() + }) + + mounted().then((res) => { + if (isEmpty(res)) { + localStorage.removeItem("AUTH_TOKEN") + return navigate("/admin/login") + } + setAdminUsers(res.data) + }) + + }, []) + + return ( +
+
+
+
+ Admin Users +
+ + Create + +
+ + +
+ + + + + + + + + + + + + + + {adminUsers.map((adminUser) => { + return ( + + + + + + + + + + + ) + })} + +
IDFullNameEmailCreated atUpdated atCreated byUpdated byAction
{adminUser.id}{adminUser.full_name}{adminUser.email} + {getFormattedDate(adminUser.created_at)} + + {getFormattedDate(adminUser.updated_at)} + {adminUser.created_by}{adminUser.updated_by} + + Edit + + +
+
+
+
+ ) +} + +export default AdminUserTable \ No newline at end of file