From c94b109dd8e80a2dfaa4b0826eca9239288cebd2 Mon Sep 17 00:00:00 2001 From: Daniil Palagin Date: Wed, 4 Sep 2024 16:17:38 +0200 Subject: [PATCH] [#202] Implement roles in internal authorization and save it to the repository --- package-lock.json | 1 + package.json | 1 + src/RoleSelector.jsx | 61 +++++++++++++++++++++++++++++++ src/components/user/User.jsx | 37 ++++++++++--------- src/constants/DefaultConstants.js | 1 + src/i18n/cs.js | 1 + src/i18n/en.js | 1 + src/utils/SecurityUtils.js | 9 +++-- 8 files changed, 92 insertions(+), 20 deletions(-) create mode 100644 src/RoleSelector.jsx diff --git a/package-lock.json b/package-lock.json index 8e267f59..7ca7bf6b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -33,6 +33,7 @@ "react-promise-tracker": "^2.1.1", "react-redux": "^7.2.4", "react-router-dom": "^5.2.0", + "react-select": "^5.8.0", "redux": "^4.1.0", "redux-devtools-extension": "^2.13.9", "redux-thunk": "^2.3.0", diff --git a/package.json b/package.json index 9424b22b..993165b5 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "react-promise-tracker": "^2.1.1", "react-redux": "^7.2.4", "react-router-dom": "^5.2.0", + "react-select": "^5.8.0", "redux": "^4.1.0", "redux-devtools-extension": "^2.13.9", "redux-thunk": "^2.3.0", diff --git a/src/RoleSelector.jsx b/src/RoleSelector.jsx new file mode 100644 index 00000000..f15ba69a --- /dev/null +++ b/src/RoleSelector.jsx @@ -0,0 +1,61 @@ +import React, { useState, useEffect } from "react"; +import Select from "react-select"; +import PropTypes from "prop-types"; +import { ROLE } from "./constants/DefaultConstants.js"; +import Row from "react-bootstrap/Row"; +import { Col, FormGroup, FormLabel } from "react-bootstrap"; + +const roleOptions = Object.keys(ROLE).map((key) => ({ + value: ROLE[key], + label: ROLE[key], +})); + +const RoleSelector = ({ selected = [], handler, readOnly = true, label = "Roles" }) => { + const formatSelected = (selected) => { + return selected.map((value) => ({ + value: value, + label: value, + })); + }; + + const [selectedRoles, setSelectedRoles] = useState(formatSelected(selected)); + + useEffect(() => { + setSelectedRoles(formatSelected(selected)); + }, [selected]); + + const handleChange = (selectedOptions) => { + setSelectedRoles(selectedOptions); + const selectedValues = selectedOptions.map((option) => option.value); + handler(selectedValues); + }; + + return ( + + + {label} + + +