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.

84 lines
2.9 KiB

  1. import React, {useState} from "react";
  2. import {Button, CustomInput, FormGroup, Modal, ModalBody, ModalFooter, ModalHeader} from "reactstrap";
  3. import {savePermissions} from "../../Helpers/groups";
  4. function PermissionsModal({groupId, userId, permissions, onClose}) {
  5. function getPermission(type) {
  6. if (permissions === null || typeof permissions[type] === "undefined") {
  7. return false;
  8. }
  9. return permissions[type];
  10. }
  11. const [read, setRead] = useState(getPermission("read"));
  12. const [write, setWrite] = useState(getPermission("write"));
  13. const [create, setCreate] = useState(getPermission("create"));
  14. const [remove, setRemove] = useState(getPermission("delete"));
  15. const manage = getPermission("manage");
  16. return (
  17. <Modal isOpen={true}>
  18. <ModalHeader>Endre gruppe</ModalHeader>
  19. <ModalBody style={{margin: "0 auto"}}>
  20. <FormGroup className="perm-switch">
  21. <CustomInput type="switch"
  22. id="switch-read"
  23. name="read"
  24. label="Les"
  25. checked={read}
  26. onChange={e => setRead(e.target.checked)}/>
  27. </FormGroup>
  28. <FormGroup className="perm-switch">
  29. <CustomInput type="switch"
  30. id="switch-write"
  31. name="write"
  32. label="Skriv"
  33. checked={write}
  34. onChange={e => setWrite(e.target.checked)}/>
  35. </FormGroup>
  36. <FormGroup className="perm-switch">
  37. <CustomInput type="switch"
  38. id="switch-create"
  39. name="create"
  40. label="Opprett"
  41. checked={create}
  42. onChange={e => setCreate(e.target.checked)}/>
  43. </FormGroup>
  44. <FormGroup className="perm-switch">
  45. <CustomInput type="switch"
  46. id="switch-remove"
  47. name="remove"
  48. label="Slett"
  49. checked={remove}
  50. onChange={e => setRemove(e.target.checked)}/>
  51. </FormGroup>
  52. <FormGroup className="perm-switch">
  53. <CustomInput type="switch"
  54. id="switch-manage"
  55. name="manage"
  56. label="Forvalte"
  57. checked={manage}
  58. disabled/>
  59. </FormGroup>
  60. </ModalBody>
  61. <ModalFooter>
  62. <Button color="primary"
  63. onClick={() => {
  64. savePermissions(
  65. groupId,
  66. userId,
  67. {read, write, delete: remove, create});
  68. onClose();
  69. }}
  70. >
  71. Lagre
  72. </Button>
  73. {" "}
  74. <Button color="secondary" onClick={onClose}>Avbryt</Button>
  75. </ModalFooter>
  76. </Modal>
  77. );
  78. }
  79. export default PermissionsModal;