|
@@ -1,5 +1,5 @@
|
|
import React, { useState } from 'react';
|
|
import React, { useState } from 'react';
|
|
-import { deleteCategory, useGetCategoriesQuery, useGetCategoryCountQuery } from '../../store/api';
|
|
|
|
|
|
+import { useDeleteCategoryMutation, useGetCategoriesQuery, useGetCategoryCountQuery } from '../../store/api';
|
|
import Loader from '../../components/Loader';
|
|
import Loader from '../../components/Loader';
|
|
import {
|
|
import {
|
|
Button, IconButton, Paper, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Tooltip, Dialog,
|
|
Button, IconButton, Paper, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Tooltip, Dialog,
|
|
@@ -8,7 +8,6 @@ import {
|
|
import { DeleteOutlineOutlined, Edit, KeyboardArrowDown, KeyboardArrowUp } from '@mui/icons-material';
|
|
import { DeleteOutlineOutlined, Edit, KeyboardArrowDown, KeyboardArrowUp } from '@mui/icons-material';
|
|
import { Link } from 'react-router-dom';
|
|
import { Link } from 'react-router-dom';
|
|
import LinkButton from '../../components/LinkButton';
|
|
import LinkButton from '../../components/LinkButton';
|
|
-import { useDispatch } from 'react-redux';
|
|
|
|
import { Box } from '@mui/system';
|
|
import { Box } from '@mui/system';
|
|
import { Image } from '../../components/Image/Image';
|
|
import { Image } from '../../components/Image/Image';
|
|
|
|
|
|
@@ -19,7 +18,7 @@ function CategoriesPage() {
|
|
const [rowsPerPage, setRowsPerPage] = useState(5);
|
|
const [rowsPerPage, setRowsPerPage] = useState(5);
|
|
const [open, setOpen] = useState(false);
|
|
const [open, setOpen] = useState(false);
|
|
const [selectedId, setSelectedId] = useState('');
|
|
const [selectedId, setSelectedId] = useState('');
|
|
- const dispatch = useDispatch();
|
|
|
|
|
|
+ const [deleteCategory, result] = useDeleteCategoryMutation();
|
|
|
|
|
|
const handleChangePage = (event, newPage) => {
|
|
const handleChangePage = (event, newPage) => {
|
|
setPage(newPage);
|
|
setPage(newPage);
|
|
@@ -40,10 +39,11 @@ function CategoriesPage() {
|
|
setOpen(false);
|
|
setOpen(false);
|
|
};
|
|
};
|
|
|
|
|
|
- const onDelitionSubmit = () => {
|
|
|
|
|
|
+ const onDeletionSubmit = () => {
|
|
const category = data?.CategoryFind?.find(category => category._id === selectedId);
|
|
const category = data?.CategoryFind?.find(category => category._id === selectedId);
|
|
- dispatch(deleteCategory(category));
|
|
|
|
- setOpen(false);
|
|
|
|
|
|
+ deleteCategory(category).then(response => {
|
|
|
|
+ setOpen(false);
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
|
|
const Row = ({ _id, name, goods, category }) => {
|
|
const Row = ({ _id, name, goods, category }) => {
|
|
@@ -76,9 +76,10 @@ function CategoriesPage() {
|
|
<Table size="small">
|
|
<Table size="small">
|
|
<TableHead>
|
|
<TableHead>
|
|
<TableRow>
|
|
<TableRow>
|
|
- <TableCell></TableCell>
|
|
|
|
- <TableCell >Good</TableCell>
|
|
|
|
- <TableCell >Price</TableCell>
|
|
|
|
|
|
+ <TableCell></TableCell>
|
|
|
|
+ <TableCell >Good</TableCell>
|
|
|
|
+ <TableCell >Price</TableCell>
|
|
|
|
+ <TableCell align='right'></TableCell>
|
|
</TableRow>
|
|
</TableRow>
|
|
</TableHead>
|
|
</TableHead>
|
|
<TableBody>
|
|
<TableBody>
|
|
@@ -91,6 +92,9 @@ function CategoriesPage() {
|
|
</TableCell>
|
|
</TableCell>
|
|
<TableCell >{good?.name}</TableCell>
|
|
<TableCell >{good?.name}</TableCell>
|
|
<TableCell >{good?.price}</TableCell>
|
|
<TableCell >{good?.price}</TableCell>
|
|
|
|
+ <TableCell align='right'>
|
|
|
|
+ <IconButton component={Link} to={`/admin/good/${good._id}`}><Edit /></IconButton>
|
|
|
|
+ </TableCell>
|
|
</TableRow>)}
|
|
</TableRow>)}
|
|
</TableBody>
|
|
</TableBody>
|
|
</Table>
|
|
</Table>
|
|
@@ -148,7 +152,7 @@ function CategoriesPage() {
|
|
<DialogContentText>Do you confirm category deletion?</DialogContentText>
|
|
<DialogContentText>Do you confirm category deletion?</DialogContentText>
|
|
</DialogContent>
|
|
</DialogContent>
|
|
<DialogActions>
|
|
<DialogActions>
|
|
- <Button onClick={() => onDelitionSubmit()}>Yes</Button>
|
|
|
|
|
|
+ <Button onClick={() => onDeletionSubmit()}>Yes</Button>
|
|
<Button onClick={closeModalWindow}>No</Button>
|
|
<Button onClick={closeModalWindow}>No</Button>
|
|
</DialogActions>
|
|
</DialogActions>
|
|
</Dialog>
|
|
</Dialog>
|