diff --git a/dashboard/src/states/Dashboard/pages/AccessKeys/AccessKeys.jsx b/dashboard/src/states/Dashboard/pages/AccessKeys/AccessKeys.jsx new file mode 100644 index 0000000..a4c7550 --- /dev/null +++ b/dashboard/src/states/Dashboard/pages/AccessKeys/AccessKeys.jsx @@ -0,0 +1,117 @@ +import {useContext, useEffect, useState} from "react"; +import {deleteRequest, getRequest} from "@/common/utils/RequestUtil.js"; +import {ProjectContext} from "@/states/Dashboard/contexts/Project"; +import {Alert, Button, CircularProgress, IconButton, Link, Snackbar, Stack, Typography} from "@mui/material"; +import {Delete, Key} from "@mui/icons-material"; +import KeyCreationDialog from "./components/KeyCreationDialog"; + +export const AccessKeys = () => { + const {currentProject} = useContext(ProjectContext); + + const [loading, setLoading] = useState(true); + const [dialogOpen, setDialogOpen] = useState(false); + const [keys, setKeys] = useState([]); + const [createdKey, setCreatedKey] = useState(null); + + const fetchKeys = async () => { + try { + const data = await getRequest(`/key/${currentProject.id}/list`); + + if (!data) return; + + setKeys(data); + setLoading(false); + } catch (e) { + console.error(e); + } + } + + const deleteKey = async (key) => { + try { + await deleteRequest(`/key/${currentProject.id}/${key}`); + await fetchKeys(); + } catch (e) { + console.error(e); + } + } + + const getKeyRole = (role) => { + switch (role) { + case 0: + return "Can view project data like licenses, groups, ..."; + case 1: + return "Can view, edit and delete project data like licenses, groups, ..."; + case 2: + return "Can manage project data and access keys"; + } + + return "Unknown"; + } + + const copyAndClose = () => { + navigator.clipboard.writeText(createdKey); + setCreatedKey(null); + } + + useEffect(() => { + fetchKeys(); + + const timer = setInterval(fetchKeys, 5000); + + return () => clearInterval(timer); + }, []); + + return ( + + setDialogOpen(false)} + fetchKeys={fetchKeys} setCreatedKey={setCreatedKey}/> + + + {loading && <>Access keys} + {!loading && <>{keys.length} Access keys} + + + + + + Copy & Close} + >Access key created + + + + {keys.map((key, index) => ( + + + + + {key.name} + + {getKeyRole(key.role)} + + + + deleteKey(key.id)}> + + + ))} + + {loading && + + } + + {!loading && keys.length === 0 && + + No access keys created. setDialogOpen(true)} color="primary" + sx={{cursor: "pointer"}}>Create one + + } + + + ); +} \ No newline at end of file diff --git a/dashboard/src/states/Dashboard/pages/AccessKeys/index.js b/dashboard/src/states/Dashboard/pages/AccessKeys/index.js new file mode 100644 index 0000000..65c4327 --- /dev/null +++ b/dashboard/src/states/Dashboard/pages/AccessKeys/index.js @@ -0,0 +1 @@ +export {AccessKeys as default} from "./AccessKeys.jsx"; \ No newline at end of file