.
+ ******************************************************************************/
+
+import React from 'react';
+import { useState } from 'react';
+import { Form, Col, Button} from 'react-bootstrap';
+import Dialog from '../../../common/dialogs/dialog';
+import { useGetScenariosQuery } from '../../../store/apiSlice';
+
+const AddUsergroupDialog = ({isModalOpened, onClose}) => {
+
+ const [name, setName] = useState('');
+ const [isValid, setIsValid] = useState(false);
+ const [selectedOption, setSelectedOption] = useState('addUsersToScenario');
+ const [selectedScenarioID, setSelectedScenarioID] = useState('');
+
+ const {data: {scenarios} = {}, isLoading: isLoadingScenarios} = useGetScenariosQuery();
+
+ const checkValidity = (name, scenarioID) => {
+ //group names have to be at lest 3 characters long and cannot start with spaces
+ const isNameValid = name.length >= 3 && !(/^\s/.test(name));
+ //scenario ID is chosen from the dropdown therefore we just make sure that empty option is not selected
+ const isScenarioIDValid = scenarioID !== '';
+ setIsValid(isNameValid && isScenarioIDValid);
+ }
+
+ const handleNameChange = (e) => {
+ const newName = e.target.value;
+ setName(newName);
+ checkValidity(newName, selectedScenarioID);
+ }
+
+ const handleRadioChange = (e) => {
+ setSelectedOption(e.target.value);
+ }
+
+ const handleClose = (canceled) => {
+ if(canceled) {
+ onClose(null);
+ } else {
+ onClose({name: name, scenarioID: selectedScenarioID, isDuplicateSelected: selectedOption === 'duplicateScenarioForUsers'});
+ }
+ }
+
+ const handleReset = () => {
+ setName('');
+ }
+
+ const handleSelectChange = (e) => {
+ setSelectedScenarioID(e.target.value);
+ checkValidity(name, e.target.value);
+ };
+
+ return ();
+}
+
+export default AddUsergroupDialog;
diff --git a/src/pages/usergroups/styles.js b/src/pages/usergroups/styles.js
new file mode 100644
index 0000000..826affe
--- /dev/null
+++ b/src/pages/usergroups/styles.js
@@ -0,0 +1,21 @@
+export const buttonStyle = {
+ marginLeft: '5px',
+}
+
+export const iconStyle = {
+ height: '25px',
+ width: '25px'
+}
+
+export const tableHeadingStyle = {
+ paddingTop: '30px'
+}
+
+export const dialogWarningLabel = {
+ background: '#eb4d2a',
+ color: 'white'
+}
+
+export const signalDialogCheckButton = {
+ float: 'right'
+}
diff --git a/src/pages/usergroups/tables/usergroup-scenarios-table.js b/src/pages/usergroups/tables/usergroup-scenarios-table.js
new file mode 100644
index 0000000..01e4346
--- /dev/null
+++ b/src/pages/usergroups/tables/usergroup-scenarios-table.js
@@ -0,0 +1,22 @@
+/**
+ * This file is part of VILLASweb.
+ *
+ * VILLASweb is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * VILLASweb is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with VILLASweb. If not, see .
+ ******************************************************************************/
+
+const UsergroupScenariosTable = (props) => {
+ return
+}
+
+export default UsergroupScenariosTable;
diff --git a/src/pages/usergroups/tables/usergroup-users-table.js b/src/pages/usergroups/tables/usergroup-users-table.js
new file mode 100644
index 0000000..08fae10
--- /dev/null
+++ b/src/pages/usergroups/tables/usergroup-users-table.js
@@ -0,0 +1,22 @@
+/**
+ * This file is part of VILLASweb.
+ *
+ * VILLASweb is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * VILLASweb is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with VILLASweb. If not, see .
+ ******************************************************************************/
+
+const UsergroupUsersTable = (props) => {
+ return
+}
+
+export default UsergroupUsersTable;
diff --git a/src/pages/usergroups/usergroup.js b/src/pages/usergroups/usergroup.js
new file mode 100644
index 0000000..d7f7e0a
--- /dev/null
+++ b/src/pages/usergroups/usergroup.js
@@ -0,0 +1,46 @@
+/**
+ * This file is part of VILLASweb.
+ *
+ * VILLASweb is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * VILLASweb is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with VILLASweb. If not, see .
+ ******************************************************************************/
+
+import { useParams } from "react-router-dom/cjs/react-router-dom.min";
+import { Table, DataColumn, LinkColumn } from "../../common/table";
+import { Row, Col } from "react-bootstrap";
+import UsergroupScenariosTable from "./tables/usergroup-scenarios-table";
+import UsergroupUsersTable from "./tables/usergroup-users-table";
+
+const Usergroup = (props) => {
+ // const params = useParams();
+ // const id = params.usergroup;
+ const usergroup = {name: 'Test Group'};
+
+ return (
+
+
{usergroup.name}
+
+
+
Users
+
+
+
+
Scenario Mappings
+
+
+
+
+ );
+}
+
+export default Usergroup;
diff --git a/src/pages/usergroups/usergroups.js b/src/pages/usergroups/usergroups.js
new file mode 100644
index 0000000..70d6c71
--- /dev/null
+++ b/src/pages/usergroups/usergroups.js
@@ -0,0 +1,82 @@
+/**
+ * This file is part of VILLASweb.
+ *
+ * VILLASweb is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * VILLASweb is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with VILLASweb. If not, see .
+ ******************************************************************************/
+
+import { useState } from "react";
+import { useGetUsergroupsQuery, useAddUserGroupMutation } from "../../store/apiSlice";
+import { Table, DataColumn, LinkColumn } from "../../common/table";
+import IconButton from "../../common/buttons/icon-button";
+import { buttonStyle, iconStyle } from "./styles";
+import AddUsergroupDialog from "./dialogs/addUsergroupDialog";
+
+const Usergroups = (props) => {
+ const {data: {usergroups} = {}, refetch: refetchUsergroups, isLoading} = useGetUsergroupsQuery();
+ const [addUserGroup] = useAddUserGroupMutation();
+
+ const [isAddDialogOpen, setIsAddDialogOpen] = useState(false);
+
+ const handleAddNewGroup = async (response) => {
+ if(response){
+ try {
+ //put data in correct structure
+ const usergroup = {Name: response.name, ScenarioMappings: [{Duplicate: response.isDuplicateSelected, ScenarioID: Number(response.scenarioID)}]};
+ await addUserGroup(usergroup).unwrap();
+
+ refetchUsergroups();
+ } catch (err) {
+ console.log("Error adding usergroup: ", err);
+ }
+ }
+ setIsAddDialogOpen(false);
+ }
+
+ if(isLoading) return
Loading
;
+
+ if(usergroups){
+ return (
+
+ User Groups
+
+ setIsAddDialogOpen(true)}
+ icon="plus"
+ buttonStyle={buttonStyle}
+ iconStyle={iconStyle}
+ />
+
+
+
+
+
+
+
+
+
);
+ }
+}
+
+export default Usergroups;
diff --git a/src/store/apiSlice.js b/src/store/apiSlice.js
index 3080f15..7a0703d 100644
--- a/src/store/apiSlice.js
+++ b/src/store/apiSlice.js
@@ -1,3 +1,20 @@
+/**
+ * This file is part of VILLASweb.
+ *
+ * VILLASweb is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * VILLASweb is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with VILLASweb. If not, see .
+ ******************************************************************************/
+
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
import { sessionToken } from '../localStorage';
import { widgetEndpoints } from './endpoints/widget-endpoints';
@@ -11,6 +28,7 @@ import { signalEndpoints } from './endpoints/signal-endpoints';
import { resultEndpoints } from './endpoints/result-endpoints';
import { authEndpoints } from './endpoints/auth-endpoints';
import { websocketEndpoints } from './endpoints/websocket-endpoints';
+import { usergroupEndpoints } from './endpoints/usergroup-endpoints';
export const apiSlice = createApi({
reducerPath: 'api',
@@ -36,6 +54,7 @@ export const apiSlice = createApi({
...signalEndpoints(builder),
...authEndpoints(builder),
...websocketEndpoints(builder),
+ ...usergroupEndpoints(builder),
}),
});
@@ -86,5 +105,7 @@ export const {
useUpdateSignalMutation,
useGetIcDataQuery,
useLazyDownloadImageQuery,
- useUpdateComponentConfigMutation
+ useUpdateComponentConfigMutation,
+ useGetUsergroupsQuery,
+ useAddUserGroupMutation
} = apiSlice;
diff --git a/src/store/endpoints/usergroup-endpoints.js b/src/store/endpoints/usergroup-endpoints.js
new file mode 100644
index 0000000..1531148
--- /dev/null
+++ b/src/store/endpoints/usergroup-endpoints.js
@@ -0,0 +1,31 @@
+/**
+ * This file is part of VILLASweb.
+ *
+ * VILLASweb is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * VILLASweb is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with VILLASweb. If not, see .
+ ******************************************************************************/
+
+export const usergroupEndpoints = (builder) => ({
+ getUsergroups: builder.query({
+ query: () => 'usergroups',
+ }),
+ addUserGroup: builder.mutation({
+ query: (usergroup) => ({
+ url: '/usergroups',
+ method: 'POST',
+ body: {
+ userGroup: usergroup
+ },
+ }),
+ }),
+});