добавлена кнопка для скрытия коктейля из списка коктейлей
This commit is contained in:
@@ -124,6 +124,13 @@ const CocktailsPageContent = () => {
|
|||||||
|
|
||||||
const handleSelectCocktail = (row) => selectCocktail(row.id)
|
const handleSelectCocktail = (row) => selectCocktail(row.id)
|
||||||
const deleteHandle = (row) => cocktailClient.deleteCocktail(row.id, rows, setRows, createSuccess, createError)
|
const deleteHandle = (row) => cocktailClient.deleteCocktail(row.id, rows, setRows, createSuccess, createError)
|
||||||
|
const hideHandler = (id) => {
|
||||||
|
cocktailClient.hiddenCocktail(id)
|
||||||
|
.then(() => {
|
||||||
|
createSuccess("Коктейль скрыт успешно");
|
||||||
|
setRows(rows.filter((r) => r.id !== id))
|
||||||
|
}).catch(() => createError("Ошибка при попытке скрыть коктейль"))
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
@@ -158,6 +165,7 @@ const CocktailsPageContent = () => {
|
|||||||
handleChangeRating={handleChangeRating}
|
handleChangeRating={handleChangeRating}
|
||||||
handleSelect={handleSelectCocktail}
|
handleSelect={handleSelectCocktail}
|
||||||
deleteHandler={deleteHandle}
|
deleteHandler={deleteHandle}
|
||||||
|
hideHandler={hideHandler}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {CocktailDescription} from "./CocktailDescription";
|
|||||||
import EditIcon from '@mui/icons-material/Edit';
|
import EditIcon from '@mui/icons-material/Edit';
|
||||||
import DeleteIcon from '@mui/icons-material/Delete';
|
import DeleteIcon from '@mui/icons-material/Delete';
|
||||||
import LocalBarIcon from '@mui/icons-material/LocalBar';
|
import LocalBarIcon from '@mui/icons-material/LocalBar';
|
||||||
|
import VisibilityOffIcon from '@mui/icons-material/VisibilityOff';
|
||||||
import {paths} from "../../path";
|
import {paths} from "../../path";
|
||||||
import {useAlert} from "../../hooks/useAlert";
|
import {useAlert} from "../../hooks/useAlert";
|
||||||
import {useUser} from "../../hooks/useUser";
|
import {useUser} from "../../hooks/useUser";
|
||||||
@@ -35,7 +36,7 @@ function renderRating(handleChangeRating, row) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Cocktail({row, handleFavourite, handleChangeRating, handleSelect, deleteHandler}) {
|
export function Cocktail({row, handleFavourite, handleChangeRating, handleSelect, deleteHandler, hideHandler}) {
|
||||||
const {createError, createSuccess} = useAlert();
|
const {createError, createSuccess} = useAlert();
|
||||||
const {user} = useUser();
|
const {user} = useUser();
|
||||||
return (
|
return (
|
||||||
@@ -73,6 +74,9 @@ export function Cocktail({row, handleFavourite, handleChangeRating, handleSelect
|
|||||||
<IconButton size='small' href={`${paths.bar.cocktailEdit}?id=${row.id}`}>
|
<IconButton size='small' href={`${paths.bar.cocktailEdit}?id=${row.id}`}>
|
||||||
<EditIcon fontSize='small'/>
|
<EditIcon fontSize='small'/>
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
<IconButton size='small' onClick={() => hideHandler(row.id)}>
|
||||||
|
<VisibilityOffIcon fontSize='small'/>
|
||||||
|
</IconButton>
|
||||||
<IconButton size='small' onClick={() => deleteHandler(row)}>
|
<IconButton size='small' onClick={() => deleteHandler(row)}>
|
||||||
<DeleteIcon fontSize='small'/>
|
<DeleteIcon fontSize='small'/>
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
|||||||
@@ -119,6 +119,10 @@ class CocktailClient {
|
|||||||
.catch(() => createError("Ошибка удаления коктейля"))
|
.catch(() => createError("Ошибка удаления коктейля"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async hiddenCocktail(id) {
|
||||||
|
return api().post(requests.cocktails.hide + id);
|
||||||
|
}
|
||||||
|
|
||||||
saveChangeCocktail (cocktail, createError, createSuccess) {
|
saveChangeCocktail (cocktail, createError, createSuccess) {
|
||||||
api().patch(requests.cocktails.basic, cocktail)
|
api().patch(requests.cocktails.basic, cocktail)
|
||||||
.then((r) => {
|
.then((r) => {
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ export const requests = {
|
|||||||
favourite: routes.cocktail + "/favourite?id=",
|
favourite: routes.cocktail + "/favourite?id=",
|
||||||
rating: routes.cocktail + "/rating?id=",
|
rating: routes.cocktail + "/rating?id=",
|
||||||
drink: routes.cocktail + "/drink",
|
drink: routes.cocktail + "/drink",
|
||||||
|
hide: routes.cocktail + "/hidden/",
|
||||||
},
|
},
|
||||||
glass: {
|
glass: {
|
||||||
list: routes.glass,
|
list: routes.glass,
|
||||||
|
|||||||
Reference in New Issue
Block a user