diff --git a/redaktions-app/src/components/ChangeRole.tsx b/redaktions-app/src/components/ChangeRole.tsx index d4b05b3..1469148 100644 --- a/redaktions-app/src/components/ChangeRole.tsx +++ b/redaktions-app/src/components/ChangeRole.tsx @@ -2,31 +2,30 @@ import React from "react"; import { IconButton, MenuItem } from "@material-ui/core"; import Menu from "@material-ui/core/Menu"; import EditIcon from "@material-ui/icons/Edit"; -import { UppercaseUserRole, UPPERCASE_USER_ROLES } from "../jwt/jwt"; +import { UPPERCASE_USER_ROLES, UppercaseUserRole } from "../jwt/jwt"; import { useMutation } from "@apollo/client"; -import { useHistory } from "react-router-dom"; import { + CHANGE_ROLE, ChangeRoleResponse, ChangeRoleVariables, - CHANGE_ROLE, } from "../backend/mutations/userRole"; +import { useSnackbar } from "notistack"; +import { GET_PERSONS_SORTED_BY_ROLE } from "../backend/queries/person"; interface ChangeRoleProps { currentRole: UppercaseUserRole; currentUserRowId: number; } - export default function ChangeRole(props: ChangeRoleProps): React.ReactElement { const [anchorEl, setAnchorEl] = React.useState(null); const open = Boolean(anchorEl); - const history = useHistory(); + const { enqueueSnackbar } = useSnackbar(); const otherRoles = UPPERCASE_USER_ROLES.filter( (role) => role != props.currentRole ); const handleMenu = (event: React.MouseEvent) => { setAnchorEl(event.currentTarget); }; - const handleClose = () => { setAnchorEl(null); }; @@ -34,21 +33,22 @@ export default function ChangeRole(props: ChangeRoleProps): React.ReactElement { CHANGE_ROLE, { onCompleted() { - console.log("Role changed"); - history.go(0); handleClose(); }, onError(e) { console.error(e); handleClose(); + enqueueSnackbar("Ein Fehler ist aufgetreten, versuche es erneut.", { + variant: "error", + }); }, + refetchQueries: [{ query: GET_PERSONS_SORTED_BY_ROLE }], } ); - const displayRole = (role: UppercaseUserRole) => { switch (role) { case "CANDYMAT_CANDIDATE": - return "zu * machen"; + return "zu Kandidat:in machen"; case "CANDYMAT_EDITOR": return "zu RedakteurIn machen"; case "CANDYMAT_PERSON":