72 lines
2.1 KiB
TypeScript
72 lines
2.1 KiB
TypeScript
import { Paper, Typography } from "@material-ui/core";
|
|
import React from "react";
|
|
import { makeStyles } from "@material-ui/core/styles";
|
|
import { useQuery } from "@apollo/client";
|
|
import AddCard from "./AddCard";
|
|
import AccordionWithEdit from "./AccordionWithEdit";
|
|
import {
|
|
BasicCategoryResponse,
|
|
GET_ALL_CATEGORIES,
|
|
GetAllCategoriesResponse,
|
|
} from "../backend/queries/category";
|
|
import DialogChangeCategory, {
|
|
dialogChangeCategoryId,
|
|
dialogChangeCategoryOpen,
|
|
} from "./DialogChangeCategory";
|
|
import DialogDeleteCategory, {
|
|
dialogDeleteCategoryId,
|
|
dialogDeleteCategoryOpen,
|
|
dialogDeleteCategoryTitle,
|
|
} from "./DialogDeleteCategory";
|
|
|
|
const useStyles = makeStyles((theme) => ({
|
|
root: {
|
|
width: "100%",
|
|
padding: theme.spacing(1),
|
|
marginBottom: theme.spacing(3),
|
|
},
|
|
}));
|
|
|
|
export default function CategoryList(): React.ReactElement {
|
|
const categories = useQuery<GetAllCategoriesResponse, null>(
|
|
GET_ALL_CATEGORIES
|
|
).data?.allCategories.nodes;
|
|
const classes = useStyles();
|
|
|
|
const handleAddClick = () => {
|
|
dialogChangeCategoryId("");
|
|
dialogChangeCategoryOpen(true);
|
|
};
|
|
|
|
const handleEditButtonClick = (category: BasicCategoryResponse) => {
|
|
dialogChangeCategoryId(category.id);
|
|
dialogChangeCategoryOpen(true);
|
|
};
|
|
|
|
const handleDeleteButtonClick = (category: BasicCategoryResponse) => {
|
|
dialogDeleteCategoryTitle(category.title);
|
|
dialogDeleteCategoryId(category.id);
|
|
dialogDeleteCategoryOpen(true);
|
|
};
|
|
|
|
return (
|
|
<Paper className={classes.root}>
|
|
<Typography component={"h2"} variant="h6" color="primary" gutterBottom>
|
|
Kategorien
|
|
</Typography>
|
|
{categories?.map((category) => (
|
|
<AccordionWithEdit
|
|
key={category.id}
|
|
title={category.title}
|
|
description={category.description}
|
|
onEditButtonClick={() => handleEditButtonClick(category)}
|
|
onDeleteButtonClick={() => handleDeleteButtonClick(category)}
|
|
/>
|
|
))}
|
|
<AddCard handleClick={handleAddClick} />
|
|
<DialogChangeCategory />
|
|
<DialogDeleteCategory />
|
|
</Paper>
|
|
);
|
|
}
|