добавлена кнопка для скрытия коктейля из списка коктейлей

This commit is contained in:
Kayashov.SM
2025-12-27 20:55:40 +04:00
parent de96c83ddf
commit e282681679
4 changed files with 18 additions and 1 deletions

View File

@@ -124,6 +124,13 @@ const CocktailsPageContent = () => {
const handleSelectCocktail = (row) => selectCocktail(row.id)
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 (
<Box>
@@ -158,6 +165,7 @@ const CocktailsPageContent = () => {
handleChangeRating={handleChangeRating}
handleSelect={handleSelectCocktail}
deleteHandler={deleteHandle}
hideHandler={hideHandler}
/>
)
})}

View File

@@ -10,6 +10,7 @@ import {CocktailDescription} from "./CocktailDescription";
import EditIcon from '@mui/icons-material/Edit';
import DeleteIcon from '@mui/icons-material/Delete';
import LocalBarIcon from '@mui/icons-material/LocalBar';
import VisibilityOffIcon from '@mui/icons-material/VisibilityOff';
import {paths} from "../../path";
import {useAlert} from "../../hooks/useAlert";
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 {user} = useUser();
return (
@@ -73,6 +74,9 @@ export function Cocktail({row, handleFavourite, handleChangeRating, handleSelect
<IconButton size='small' href={`${paths.bar.cocktailEdit}?id=${row.id}`}>
<EditIcon fontSize='small'/>
</IconButton>
<IconButton size='small' onClick={() => hideHandler(row.id)}>
<VisibilityOffIcon fontSize='small'/>
</IconButton>
<IconButton size='small' onClick={() => deleteHandler(row)}>
<DeleteIcon fontSize='small'/>
</IconButton>

View File

@@ -119,6 +119,10 @@ class CocktailClient {
.catch(() => createError("Ошибка удаления коктейля"))
}
async hiddenCocktail(id) {
return api().post(requests.cocktails.hide + id);
}
saveChangeCocktail (cocktail, createError, createSuccess) {
api().patch(requests.cocktails.basic, cocktail)
.then((r) => {

View File

@@ -38,6 +38,7 @@ export const requests = {
favourite: routes.cocktail + "/favourite?id=",
rating: routes.cocktail + "/rating?id=",
drink: routes.cocktail + "/drink",
hide: routes.cocktail + "/hidden/",
},
glass: {
list: routes.glass,