forked from blcham/record-manager-ui
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#202] Implement roles in internal authorization and save it to the r…
…epository
- Loading branch information
Showing
8 changed files
with
92 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<FormGroup as={Row}> | ||
<Col as={FormLabel} lg={2} className="font-weight-bold text-lg-right align-self-center"> | ||
{label} | ||
</Col> | ||
<Col lg={10}> | ||
<Select | ||
value={selectedRoles} | ||
onChange={handleChange} | ||
isMulti | ||
name="roles" | ||
options={roleOptions} | ||
isDisabled={readOnly} | ||
className="basic-multi-select" | ||
classNamePrefix="select" | ||
/> | ||
</Col> | ||
</FormGroup> | ||
); | ||
}; | ||
|
||
RoleSelector.propTypes = { | ||
selected: PropTypes.array, | ||
handler: PropTypes.func.isRequired, | ||
readOnly: PropTypes.bool, | ||
label: PropTypes.string, | ||
}; | ||
|
||
export default RoleSelector; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters