added functions to close menu and reload element after user role change

This commit is contained in:
Philipp Lohner 2021-05-29 18:09:31 +02:00
parent 2dc8a97af0
commit 0d6d496291
6 changed files with 19 additions and 10 deletions

6
package-lock.json generated Normal file
View File

@ -0,0 +1,6 @@
{
"name": "candymat",
"lockfileVersion": 2,
"requires": true,
"packages": {}
}

1
package.json Normal file
View File

@ -0,0 +1 @@
{}

View File

@ -28,9 +28,9 @@ const useStyles = makeStyles((theme) => ({
}));
export default function CategoryList(): React.ReactElement {
const categories =
useQuery<GetAllCategoriesResponse, null>(GET_ALL_CATEGORIES).data
?.allCategories.nodes;
const categories = useQuery<GetAllCategoriesResponse, null>(
GET_ALL_CATEGORIES
).data?.allCategories.nodes;
const classes = useStyles();
const handleAddClick = () => {

View File

@ -4,6 +4,7 @@ import Menu from "@material-ui/core/Menu";
import EditIcon from "@material-ui/icons/Edit";
import { UppercaseUserRole, UPPERCASE_USER_ROLES } from "../jwt/jwt";
import { useMutation } from "@apollo/client";
import { useHistory } from "react-router-dom";
import {
ChangeRoleResponse,
ChangeRoleVariables,
@ -18,7 +19,7 @@ interface ChangeRoleProps {
export default function ChangeRole(props: ChangeRoleProps): React.ReactElement {
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
const open = Boolean(anchorEl);
const history = useHistory();
const otherRoles = UPPERCASE_USER_ROLES.filter(
(role) => role != props.currentRole
);
@ -34,6 +35,8 @@ export default function ChangeRole(props: ChangeRoleProps): React.ReactElement {
{
onCompleted() {
console.log("Role changed");
history.go(0);
handleClose();
},
onError(e) {
console.error(e);

View File

@ -52,9 +52,9 @@ export default function DialogChangeQuestion(): React.ReactElement {
},
}
);
const categories =
useQuery<GetAllCategoriesResponse, null>(GET_ALL_CATEGORIES).data
?.allCategories.nodes;
const categories = useQuery<GetAllCategoriesResponse, null>(
GET_ALL_CATEGORIES
).data?.allCategories.nodes;
const [editQuestion, { loading: editLoading }] = useMutation<
EditQuestionResponse,

View File

@ -28,9 +28,8 @@ const useStyles = makeStyles((theme) => ({
}));
export default function QuestionList(): React.ReactElement {
const questions =
useQuery<GetAllQuestionsResponse, null>(GET_ALL_QUESTIONS).data
?.allQuestions.nodes;
const questions = useQuery<GetAllQuestionsResponse, null>(GET_ALL_QUESTIONS)
.data?.allQuestions.nodes;
const classes = useStyles();
const handleAddButtonClick = () => {