From be5ef192aa57af18a996f72fe64be37f02087752 Mon Sep 17 00:00:00 2001 From: Mathias Wagner <germannewsmaker@gmail.com> Date: Sun, 10 Sep 2023 16:08:23 +0200 Subject: [PATCH] Created the Licenses.jsx --- .../Dashboard/pages/Licenses/Licenses.jsx | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/states/Dashboard/pages/Licenses/Licenses.jsx diff --git a/src/states/Dashboard/pages/Licenses/Licenses.jsx b/src/states/Dashboard/pages/Licenses/Licenses.jsx new file mode 100644 index 0000000..c1a0e2d --- /dev/null +++ b/src/states/Dashboard/pages/Licenses/Licenses.jsx @@ -0,0 +1,51 @@ +import {DataGrid} from '@mui/x-data-grid'; +import {useContext, useEffect, useState} from "react"; +import {getRequest} from "@/common/utils/RequestUtil.js"; +import {ProjectContext} from "@/states/Dashboard/contexts/Project"; +import {Button, Stack, TextField} from "@mui/material"; +import {Search} from "@mui/icons-material"; +import columns from "./columns.jsx"; + +export const Licenses = () => { + const {currentProject} = useContext(ProjectContext); + + const [isLoading, setIsLoading] = useState(true); + const [rows, setRows] = useState([]); + const [pageInfo, setPageInfo] = useState({totalRowCount: 0, totalPages: 0, pageSize: 100, page: 0}); + + const fetchLicenses = async () => { + setIsLoading(true); + try { + const data = await getRequest(`/license/${currentProject.id}/list?limit=${pageInfo.pageSize}&page=${pageInfo.page}`); + + setRows(data?.licenses.map((license) => ({id: license.key, ...license})) || []); + setPageInfo(pageInfo => ({totalRowCount: data.total, totalPages: Math.ceil(data.total / pageInfo.pageSize), + pageSize: pageInfo.pageSize, page: pageInfo.page})); + setIsLoading(false); + } catch (e) { + console.error(e); + } + } + + const onPageChange = async (page) => setPageInfo({...pageInfo, page: page}); + + useEffect(() => { + fetchLicenses(); + }, [pageInfo.page]); + + return ( + <Stack> + + <Stack justifyContent="space-between" direction="row" sx={{mb: 2}} alignItems="center"> + <TextField variant="outlined" size="small" placeholder="Schlüssel suchen" + InputProps={{startAdornment: <Search sx={{mr: 1}} />}}/> + <Button variant="contained" color="primary">Lizenz erstellen</Button> + </Stack> + + <DataGrid rows={rows} columns={columns} loading={isLoading} paginationMode="server" disableSelectionOnClick + rowCount={pageInfo.totalRowCount} paginationModel={pageInfo} autoHeight disableColumnFilter + onPaginationModelChange={(page) => onPageChange(page.page)} disableColumnMenu + sx={{display: 'grid', gridTemplateRows: 'auto 1f auto'}} /> + </Stack> + ); +} \ No newline at end of file