diff --git a/dashboard/src/states/Dashboard/pages/Permissions/Permissions.jsx b/dashboard/src/states/Dashboard/pages/Permissions/Permissions.jsx new file mode 100644 index 0000000..9c90335 --- /dev/null +++ b/dashboard/src/states/Dashboard/pages/Permissions/Permissions.jsx @@ -0,0 +1,103 @@ +import {useContext, useEffect, useState} from "react"; +import {deleteRequest, getRequest} from "@/common/utils/RequestUtil.js"; +import {ProjectContext} from "@/states/Dashboard/contexts/Project"; +import {Button, CircularProgress, IconButton, Link, Stack, Typography} from "@mui/material"; +import {Delete, Shield, ChevronRight} from "@mui/icons-material"; +import PermissionCreationDialog from "./components/PermissionCreationDialog"; + +export const Permissions = () => { + const {currentProject} = useContext(ProjectContext); + + const [loading, setLoading] = useState(true); + const [dialogOpen, setDialogOpen] = useState(false); + const [permissions, setPermissions] = useState([]); + + const fetchPermissions = async () => { + try { + const data = await getRequest(`/permission/${currentProject.id}/list`); + + if (!data) return; + + setPermissions(data); + setLoading(false); + } catch (e) { + console.error(e); + } + } + + const deletePermission = async (permission) => { + try { + await deleteRequest(`/permission/${currentProject.id}/${permission}`); + await fetchPermissions(); + } catch (e) { + console.error(e); + } + } + + useEffect(() => { + fetchPermissions(); + + const timer = setInterval(fetchPermissions, 5000); + + return () => clearInterval(timer); + }, []); + + const getNameClean = (permission) => { + const parts = permission.split('.'); + + return parts.map((part, index) => ( + + {part} + {index < parts.length - 1 && } + + )) + } + + return ( + + setDialogOpen(false)} + fetchPermissions={fetchPermissions}/> + + + {permissions.length} Permissions + + + + + {permissions.map((permission, index) => ( + + + + + + {getNameClean(permission.permission)} + + + {permission.description} + + + + deletePermission(permission.permission)}> + + + ))} + + {loading && + + } + + {!loading && permissions.length === 0 && + + No permissions created. setDialogOpen(true)} color="primary" + sx={{cursor: "pointer"}}>Create one + + } + + + ); +} \ No newline at end of file diff --git a/dashboard/src/states/Dashboard/pages/Permissions/index.js b/dashboard/src/states/Dashboard/pages/Permissions/index.js new file mode 100644 index 0000000..47bc9c0 --- /dev/null +++ b/dashboard/src/states/Dashboard/pages/Permissions/index.js @@ -0,0 +1 @@ +export {Permissions as default} from "./Permissions.jsx"; \ No newline at end of file