The main server, and probably only repository in this org.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
2.9 KiB

  1. import React, {useState} from "react";
  2. import useAuth from "../../Hooks/auth";
  3. import {
  4. Button,
  5. Col,
  6. Form,
  7. FormGroup,
  8. Input,
  9. InputGroup,
  10. InputGroupAddon,
  11. Label,
  12. Modal,
  13. ModalBody,
  14. ModalFooter,
  15. ModalHeader,
  16. Row
  17. } from "reactstrap";
  18. import PermissionsModal from "./PermissionsModal";
  19. import {saveGroupMetadata} from "../../Helpers/groups";
  20. function GroupPropertiesModal({id, nValue, permissions, onClose}) {
  21. const {users} = useAuth();
  22. const [name, setName] = useState(nValue);
  23. const [permUserId, setPermUserId] = useState(null);
  24. const [permModal, setPermModal] = useState(false);
  25. function permissionFor(userId) {
  26. const perm = permissions.find(p => p.userId === userId);
  27. return typeof perm !== "undefined"
  28. ? perm
  29. : null;
  30. }
  31. return (
  32. <Modal isOpen={true}>
  33. <ModalHeader>Endre gruppe</ModalHeader>
  34. <ModalBody style={{margin: "0 auto"}}>
  35. <Form>
  36. <FormGroup row>
  37. <Label sm={3} for="text-name">
  38. Navn:
  39. </Label>
  40. <Col sm={9}>
  41. <Input type="text"
  42. id="text-name"
  43. name="power"
  44. value={name}
  45. onChange={e => setName(e.target.value)}/>
  46. </Col>
  47. </FormGroup>
  48. <FormGroup row>
  49. <Label sm={3}>
  50. Tilgang:
  51. </Label>
  52. <Col sm={9}>
  53. {users.map(user => {
  54. const permission = permissionFor(user.id);
  55. const btnColor = permission !== null ? "secondary" : "success";
  56. const btnLabel = permission !== null ? "Endre" : "Opprett";
  57. return (
  58. <Row>
  59. <InputGroup className="mb-2">
  60. <Input className="permission" disabled value={user.name}/>
  61. <InputGroupAddon addonType="prepend">
  62. <Button color={btnColor} onClick={() => {
  63. setPermUserId(user.id);
  64. setPermModal(true);
  65. }}>{btnLabel}</Button>
  66. </InputGroupAddon>
  67. </InputGroup>
  68. </Row>
  69. )
  70. })}
  71. </Col>
  72. </FormGroup>
  73. </Form>
  74. </ModalBody>
  75. <ModalFooter>
  76. <Button color="primary"
  77. onClick={() => {
  78. saveGroupMetadata(id, name);
  79. onClose();
  80. }}
  81. >
  82. Lagre
  83. </Button>
  84. {" "}
  85. <Button color="secondary" onClick={onClose}>Avbryt</Button>
  86. </ModalFooter>
  87. {permModal && (
  88. <PermissionsModal permissions={permissionFor(permUserId)}
  89. groupId={id}
  90. userId={permUserId}
  91. onClose={() => setPermModal(false)}
  92. />
  93. )}
  94. </Modal>
  95. );
  96. }
  97. export default GroupPropertiesModal;