From e93fe35059b1bd15e15b4a36a3ad2c00b816c729 Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Mon, 22 Jul 2024 17:21:25 +0200 Subject: [PATCH] Create Groups page --- .../LicenseDialog/pages/Groups/Groups.jsx | 64 +++++++++++++++++++ .../LicenseDialog/pages/Groups/index.js | 1 + 2 files changed, 65 insertions(+) create mode 100644 dashboard/src/states/Dashboard/pages/Licenses/components/LicenseDialog/pages/Groups/Groups.jsx create mode 100644 dashboard/src/states/Dashboard/pages/Licenses/components/LicenseDialog/pages/Groups/index.js diff --git a/dashboard/src/states/Dashboard/pages/Licenses/components/LicenseDialog/pages/Groups/Groups.jsx b/dashboard/src/states/Dashboard/pages/Licenses/components/LicenseDialog/pages/Groups/Groups.jsx new file mode 100644 index 0000000..0d5b393 --- /dev/null +++ b/dashboard/src/states/Dashboard/pages/Licenses/components/LicenseDialog/pages/Groups/Groups.jsx @@ -0,0 +1,64 @@ +import { + CircularProgress, + Stack, + Switch, + Typography +} from "@mui/material"; +import {getRequest} from "@/common/utils/RequestUtil.js"; +import {useContext, useEffect, useState} from "react"; +import {ProjectContext} from "@/states/Dashboard/contexts/Project"; +import {Group} from "@mui/icons-material"; + +export const Groups = ({setGroups, groups}) => { + const {currentProject} = useContext(ProjectContext); + + const [loading, setLoading] = useState(true); + + const [onlineGroups, setOnlineGroups] = useState([]); + + const updateLocal = (group) => { + setGroups(prev => { + if (prev.includes(group)) { + return prev.filter(p => p !== group); + } else { + return [...prev, group]; + } + }); + } + + useEffect(() => { + const fetchGroups = async () => { + try { + const data = await getRequest(`/group/${currentProject.id}/list`); + + if (!data) return; + + setOnlineGroups(data); + setLoading(false); + } catch (e) { + console.error(e); + } + } + + fetchGroups(); + }, []); + + return ( + + {onlineGroups.map(({name}, index) => ( + + + + {name} + + updateLocal(name)}/> + + ))} + + {loading && + + } + + ) +} \ No newline at end of file diff --git a/dashboard/src/states/Dashboard/pages/Licenses/components/LicenseDialog/pages/Groups/index.js b/dashboard/src/states/Dashboard/pages/Licenses/components/LicenseDialog/pages/Groups/index.js new file mode 100644 index 0000000..1017ff4 --- /dev/null +++ b/dashboard/src/states/Dashboard/pages/Licenses/components/LicenseDialog/pages/Groups/index.js @@ -0,0 +1 @@ +export {Groups as default} from "./Groups.jsx"; \ No newline at end of file