Переведены все запросы на клиенты
This commit is contained in:
@@ -1,7 +1,5 @@
|
|||||||
import Paper from "@mui/material/Paper";
|
import Paper from "@mui/material/Paper";
|
||||||
import React, {useEffect, useState} from "react";
|
import React, {useEffect, useState} from "react";
|
||||||
import {api} from "../../lib/clients/api";
|
|
||||||
import {requests} from "../../requests";
|
|
||||||
import {useAlert} from "../../hooks/useAlert";
|
import {useAlert} from "../../hooks/useAlert";
|
||||||
import {Card} from "@mui/material";
|
import {Card} from "@mui/material";
|
||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
@@ -10,76 +8,23 @@ import IconButton from "@mui/material/IconButton";
|
|||||||
import Box from "@mui/material/Box";
|
import Box from "@mui/material/Box";
|
||||||
import DeleteIcon from '@mui/icons-material/Delete';
|
import DeleteIcon from '@mui/icons-material/Delete';
|
||||||
import ElectricalServicesIcon from '@mui/icons-material/ElectricalServices';
|
import ElectricalServicesIcon from '@mui/icons-material/ElectricalServices';
|
||||||
import {getComparator} from "../../components/core/getComparator";
|
|
||||||
import Toolbar from "@mui/material/Toolbar";
|
import Toolbar from "@mui/material/Toolbar";
|
||||||
import AddCircleIcon from '@mui/icons-material/AddCircle';
|
import AddCircleIcon from '@mui/icons-material/AddCircle';
|
||||||
import {BarCreateModal} from "../../components/BarCreateModal";
|
import {BarCreateModal} from "../../components/BarCreateModal";
|
||||||
import PowerIcon from '@mui/icons-material/Power';
|
import PowerIcon from '@mui/icons-material/Power';
|
||||||
|
import {barClient} from "../../lib/clients/BarClient";
|
||||||
|
|
||||||
export function BarChangePage() {
|
export function BarChangePage() {
|
||||||
const [bars, setBars] = useState([])
|
const [bars, setBars] = useState([])
|
||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
const {createError, createSuccess, createWarning} = useAlert();
|
const {createError, createSuccess, createWarning} = useAlert();
|
||||||
|
|
||||||
useEffect(() => {
|
const createHandler = (name) => barClient.createBar(name, bars, createSuccess, createError, setBars, setOpen)
|
||||||
api().get(requests.bar.all)
|
|
||||||
.then((r) => {
|
|
||||||
setBars(r.data.sort(getComparator("name")))
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
createError("Ошибка получения списков")
|
|
||||||
})
|
|
||||||
// eslint-disable-next-line
|
|
||||||
}, []);
|
|
||||||
const changeHandler = (bar) => {
|
|
||||||
createWarning("Дождитесь окончания операции")
|
|
||||||
api().post(`${requests.bar.change}/${bar.id}`)
|
|
||||||
.then(() => createSuccess("Список изменен"))
|
|
||||||
.catch(() => createError("Ошибка изменения активного списка"))
|
|
||||||
|
|
||||||
const newState = bars.map((b) => {
|
useEffect(() => barClient.getBarList(setBars, createError), []);
|
||||||
if (b.active) {
|
|
||||||
return {
|
|
||||||
...b, active: false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (b.id === bar.id) {
|
|
||||||
return {
|
|
||||||
...b, active: true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return b;
|
|
||||||
})
|
|
||||||
setBars(newState);
|
|
||||||
}
|
|
||||||
const deleteHandler = (bar) => {
|
|
||||||
if (bar.active) {
|
|
||||||
createError("Нельзя удалить активный бар!")
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
api().delete(requests.bar.crud + bar.id)
|
|
||||||
.then(() => createSuccess("Список удален"))
|
|
||||||
.catch(() => createError("Ошибка удаления. Обновите страницу"))
|
|
||||||
|
|
||||||
setBars(bars.filter((b) => b.id !== bar.id));
|
|
||||||
}
|
|
||||||
const createHandler = (name) => {
|
|
||||||
api().post(requests.bar.crud + name)
|
|
||||||
.then((r) => {
|
|
||||||
createSuccess("Cписок создан");
|
|
||||||
let state = bars;
|
|
||||||
state.push(r.data);
|
|
||||||
setBars(state)
|
|
||||||
setOpen(false)
|
|
||||||
}).catch(() => createError("Ошибка создания списка"))
|
|
||||||
}
|
|
||||||
|
|
||||||
function closeHandler() {
|
|
||||||
setOpen(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (<>
|
return (<>
|
||||||
<BarCreateModal open={open} close={closeHandler} create={createHandler}/>
|
<BarCreateModal open={open} setOpen={setOpen} create={createHandler}/>
|
||||||
<Paper sx={{p: 1}}>
|
<Paper sx={{p: 1}}>
|
||||||
<Toolbar>
|
<Toolbar>
|
||||||
<Typography variant='h6'>Списки ингредиентов (бары)</Typography>
|
<Typography variant='h6'>Списки ингредиентов (бары)</Typography>
|
||||||
@@ -95,10 +40,11 @@ export function BarChangePage() {
|
|||||||
<PowerIcon/>
|
<PowerIcon/>
|
||||||
</IconButton>}
|
</IconButton>}
|
||||||
{!b.active && <Box>
|
{!b.active && <Box>
|
||||||
<IconButton onClick={() => deleteHandler(b)}>
|
<IconButton onClick={() => barClient.deleteBar(b, bars, createError, createSuccess, setBars)}>
|
||||||
<DeleteIcon/>
|
<DeleteIcon/>
|
||||||
</IconButton>
|
</IconButton>
|
||||||
<IconButton onClick={() => changeHandler(b)}>
|
<IconButton
|
||||||
|
onClick={() => barClient.changeBar(b.id, bars, createWarning, createSuccess, createError, setBars)}>
|
||||||
<ElectricalServicesIcon/>
|
<ElectricalServicesIcon/>
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Box>}
|
</Box>}
|
||||||
|
|||||||
@@ -1,28 +1,14 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import {useSearchParams} from "react-router-dom";
|
import {useSearchParams} from "react-router-dom";
|
||||||
import {Loading} from "../../../../components/core/Loading";
|
import {Loading} from "../../../../components/core/Loading";
|
||||||
import {api} from "../../../../lib/clients/api";
|
|
||||||
import {requests} from "../../../../requests";
|
|
||||||
import {useAuth} from "../../../../hooks/useAuth";
|
import {useAuth} from "../../../../hooks/useAuth";
|
||||||
|
import {authClient} from "../../../../lib/clients/AuthClient";
|
||||||
|
|
||||||
export function TelegramCode() {
|
export function TelegramCode() {
|
||||||
const [searchParams] = useSearchParams();
|
const [searchParams] = useSearchParams();
|
||||||
const {checkSession} = useAuth();
|
const {checkSession} = useAuth();
|
||||||
|
|
||||||
let code = searchParams.get("code");
|
authClient.loginByCode(searchParams.get("code"), checkSession)
|
||||||
const request = {
|
|
||||||
byLogin: false,
|
|
||||||
code: code
|
|
||||||
}
|
|
||||||
api().post(requests.auth.login, request)
|
|
||||||
.then(async (response) => {
|
|
||||||
if (response.data.error) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
localStorage.setItem("token", response.data.token);
|
|
||||||
await checkSession?.();
|
|
||||||
window.location.reload();
|
|
||||||
})
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Loading loading={true}/>
|
<Loading loading={true}/>
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
import Typography from "@mui/material/Typography";
|
import Typography from "@mui/material/Typography";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import {useEffect, useMemo} from "react";
|
import {useEffect, useMemo} from "react";
|
||||||
import {api} from "../../../lib/clients/api";
|
|
||||||
import {requests} from "../../../requests";
|
|
||||||
import {useAlert} from "../../../hooks/useAlert";
|
import {useAlert} from "../../../hooks/useAlert";
|
||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
import Box from "@mui/material/Box";
|
import Box from "@mui/material/Box";
|
||||||
import {CocktailItemCalc} from "./CocktailItemCalc";
|
import {CocktailItemCalc} from "./CocktailItemCalc";
|
||||||
import {IngredientCalcCard} from "./IngredientCalcCard";
|
import {IngredientCalcCard} from "./IngredientCalcCard";
|
||||||
|
import {cocktailClient} from "../../../lib/clients/CocktailClient";
|
||||||
|
|
||||||
export function CalcPage() {
|
export function CalcPage() {
|
||||||
const {createError} = useAlert();
|
const {createError} = useAlert();
|
||||||
@@ -23,28 +22,7 @@ export function CalcPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (load) {
|
cocktailClient.getCocktailsForCalcPage(load, setLoad, setCocktails, setCocktailMap, createError)
|
||||||
return;
|
|
||||||
}
|
|
||||||
api().get(requests.cocktails.calc)
|
|
||||||
.then((r) => {
|
|
||||||
const data = r.data;
|
|
||||||
if (data.length === 0) {
|
|
||||||
setLoad(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setCocktails(data);
|
|
||||||
let map = [];
|
|
||||||
data.map((d) => {
|
|
||||||
map[d.id] = 1
|
|
||||||
})
|
|
||||||
setCocktailMap(map);
|
|
||||||
setLoad(true);
|
|
||||||
})
|
|
||||||
.catch((r) => {
|
|
||||||
setLoad(true);
|
|
||||||
createError("Ошибка загрузки данных от сервера Status:" + r.code)
|
|
||||||
})
|
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
}, [load]);
|
}, [load]);
|
||||||
|
|
||||||
|
|||||||
@@ -5,19 +5,16 @@ import {useCallback, useEffect, useState} from "react";
|
|||||||
import {Cocktail} from "../../../components/cocktails/Cocktail";
|
import {Cocktail} from "../../../components/cocktails/Cocktail";
|
||||||
import {Fab, Skeleton} from "@mui/material";
|
import {Fab, Skeleton} from "@mui/material";
|
||||||
import Box from "@mui/material/Box";
|
import Box from "@mui/material/Box";
|
||||||
import {requests} from "../../../requests";
|
|
||||||
import {NoResult} from "../../../components/cocktails/NoResult";
|
import {NoResult} from "../../../components/cocktails/NoResult";
|
||||||
import {FilterBlock} from "../../../components/cocktails/FilterBlock";
|
import {FilterBlock} from "../../../components/cocktails/FilterBlock";
|
||||||
import {api} from "../../../lib/clients/api";
|
|
||||||
import {CocktailInfoModal} from "../../../components/cocktails/CocktailInfoModal";
|
import {CocktailInfoModal} from "../../../components/cocktails/CocktailInfoModal";
|
||||||
import {useUser} from "../../../hooks/useUser";
|
import {useUser} from "../../../hooks/useUser";
|
||||||
import {blue} from "@mui/material/colors";
|
import {blue} from "@mui/material/colors";
|
||||||
import UpIcon from "@mui/icons-material/KeyboardArrowUp";
|
import UpIcon from "@mui/icons-material/KeyboardArrowUp";
|
||||||
import {sortList} from "../../../components/cocktails/sortingList";
|
|
||||||
import {useSelect} from "../../../hooks/useSelect";
|
import {useSelect} from "../../../hooks/useSelect";
|
||||||
import Paper from "@mui/material/Paper";
|
import Paper from "@mui/material/Paper";
|
||||||
import CheckMarks from "../../../components/cocktails/CheckMarks";
|
import CheckMarks from "../../../components/cocktails/CheckMarks";
|
||||||
import {getComparator} from "../../../components/core/getComparator";
|
import {cocktailClient} from "../../../lib/clients/CocktailClient";
|
||||||
|
|
||||||
const emptyFilter = {
|
const emptyFilter = {
|
||||||
search: "",
|
search: "",
|
||||||
@@ -36,7 +33,6 @@ const emptyFilter = {
|
|||||||
const CocktailsPageContent = () => {
|
const CocktailsPageContent = () => {
|
||||||
const {user} = useUser();
|
const {user} = useUser();
|
||||||
const {createError, createSuccess} = useAlert();
|
const {createError, createSuccess} = useAlert();
|
||||||
const [allowIngredients, setAllowIngredients] = useState([])
|
|
||||||
const [rows, setRows] = useState([]);
|
const [rows, setRows] = useState([]);
|
||||||
const [filter, setFilter] = useState(emptyFilter)
|
const [filter, setFilter] = useState(emptyFilter)
|
||||||
const [chips, setChips] = useState([])
|
const [chips, setChips] = useState([])
|
||||||
@@ -52,36 +48,10 @@ const CocktailsPageContent = () => {
|
|||||||
if (load || (!isNew && isEnd)) {
|
if (load || (!isNew && isEnd)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
setLoad(true);
|
cocktailClient.getMenu(setRows, setIsNew, setPage, setLoad, setIsEnd, isNew, rows, page, size, filter, createError);
|
||||||
const request = {
|
|
||||||
...filter,
|
|
||||||
sort: sortList.find((s) => s.name === filter.sorting).id,
|
|
||||||
page: page + 1,
|
|
||||||
size: size,
|
|
||||||
notHaveCount: Array.isArray(filter.iCount) ? null : filter.iCount
|
|
||||||
}
|
|
||||||
api().post(requests.cocktails.menu, request)
|
|
||||||
.then((r) => {
|
|
||||||
if (r.data.length === 0) {
|
|
||||||
if (isNew) {
|
|
||||||
setRows([]);
|
|
||||||
}
|
|
||||||
setIsEnd(true);
|
|
||||||
setLoad(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const cocktails = isNew ? r.data : rows.concat(r.data);
|
|
||||||
setRows(cocktails);
|
|
||||||
setIsNew(false);
|
|
||||||
setPage(page + 1);
|
|
||||||
setLoad(false);
|
|
||||||
})
|
|
||||||
.catch((r) => {
|
|
||||||
setLoad(false);
|
|
||||||
createError("Ошибка загрузки данных от сервера Status:" + r.code)
|
|
||||||
})
|
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
}, [load, isEnd, page]);
|
}, [load, isEnd, page]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleScroll = () => {
|
const handleScroll = () => {
|
||||||
const {scrollTop, scrollHeight, clientHeight} = document.documentElement;
|
const {scrollTop, scrollHeight, clientHeight} = document.documentElement;
|
||||||
@@ -93,34 +63,7 @@ const CocktailsPageContent = () => {
|
|||||||
return () => window.removeEventListener('scroll', handleScroll);
|
return () => window.removeEventListener('scroll', handleScroll);
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
}, [loading]);
|
}, [loading]);
|
||||||
useEffect(() => {
|
useEffect(() => loading(), [filter])
|
||||||
api().get(requests.ingredient.simple)
|
|
||||||
.then((r) => {
|
|
||||||
const arr = r.data.filter((i) => i.isHave)
|
|
||||||
.map((i) => i.name)
|
|
||||||
setAllowIngredients(arr)
|
|
||||||
})
|
|
||||||
.catch(() => createError("Ошибка получения ингредиентов"))
|
|
||||||
// eslint-disable-next-line
|
|
||||||
}, [])
|
|
||||||
useEffect(() => {
|
|
||||||
loading();
|
|
||||||
// eslint-disable-next-line
|
|
||||||
}, [filter])
|
|
||||||
useEffect(() => {
|
|
||||||
if (!filter.all) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const ingredients = new Set();
|
|
||||||
rows.map((c) => c.components)
|
|
||||||
.map((c) => c.split(", "))
|
|
||||||
.map((c) => c.filter((i) => !allowIngredients.includes(i)))
|
|
||||||
.filter((nhc) => nhc.length === 1)
|
|
||||||
.map((fc) => fc[0])
|
|
||||||
.forEach((i) => ingredients.add(i))
|
|
||||||
setChips(Array.from(ingredients).sort(getComparator()));
|
|
||||||
// eslint-disable-next-line
|
|
||||||
}, [rows, allowIngredients])
|
|
||||||
|
|
||||||
const renderSkeleton = () => {
|
const renderSkeleton = () => {
|
||||||
return Array.from({length: 3}, () => null)
|
return Array.from({length: 3}, () => null)
|
||||||
@@ -142,11 +85,7 @@ const CocktailsPageContent = () => {
|
|||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
})
|
})
|
||||||
api().post(`${requests.cocktails.rating}${row.id}&rating=${value}`)
|
cocktailClient.changeRating(row.id, newState, value, setRows, createSuccess, createError)
|
||||||
.then(() => {
|
|
||||||
setRows(newState);
|
|
||||||
createSuccess("Спасибо за оценку!")
|
|
||||||
}).catch(() => createError("Ошибка сохранения"))
|
|
||||||
|
|
||||||
}
|
}
|
||||||
const handleFilterChange = (filterName, value) => {
|
const handleFilterChange = (filterName, value) => {
|
||||||
@@ -172,14 +111,7 @@ const CocktailsPageContent = () => {
|
|||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
});
|
});
|
||||||
let url = `${requests.cocktails.favourite}${row.id}`;
|
cocktailClient.changeFavourite(value, row.id, newState, setRows, createSuccess, createError)
|
||||||
let request = value ? api().put(url) : api().delete(url);
|
|
||||||
|
|
||||||
request
|
|
||||||
.then(() => {
|
|
||||||
setRows(newState);
|
|
||||||
createSuccess("Спасибо за оценку!")
|
|
||||||
}).catch(() => createError("Ошибка сохранения"))
|
|
||||||
}
|
}
|
||||||
const handleFilterClear = () => {
|
const handleFilterClear = () => {
|
||||||
setFilter(emptyFilter);
|
setFilter(emptyFilter);
|
||||||
@@ -187,17 +119,9 @@ const CocktailsPageContent = () => {
|
|||||||
setIsEnd(false);
|
setIsEnd(false);
|
||||||
setPage(-1);
|
setPage(-1);
|
||||||
}
|
}
|
||||||
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) => {
|
|
||||||
api().delete(requests.cocktails.cocktail + row.id)
|
|
||||||
.then(() => {
|
|
||||||
setRows(rows.filter((r) => r.id !== row.id))
|
|
||||||
createSuccess("Коктейль удален")
|
|
||||||
})
|
|
||||||
.catch(() => createError("Ошибка удаления коктейля"))
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
|
|||||||
@@ -6,18 +6,18 @@ import {useEffect, useState} from "react";
|
|||||||
import Paper from "@mui/material/Paper";
|
import Paper from "@mui/material/Paper";
|
||||||
import {Autocomplete} from "@mui/material";
|
import {Autocomplete} from "@mui/material";
|
||||||
import TextField from "@mui/material/TextField";
|
import TextField from "@mui/material/TextField";
|
||||||
import {api} from "../../../lib/clients/api";
|
|
||||||
import {requests} from "../../../requests";
|
|
||||||
import {useAlert} from "../../../hooks/useAlert";
|
import {useAlert} from "../../../hooks/useAlert";
|
||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
import Button from "@mui/material/Button";
|
import Button from "@mui/material/Button";
|
||||||
import {EditCocktailReceipt} from "../../../components/cocktails/EditCocktailReceipt";
|
import {EditCocktailReceipt} from "../../../components/cocktails/EditCocktailReceipt";
|
||||||
import {SelectEdit} from "../../../components/cocktails/SelectEdit";
|
import {SelectEdit} from "../../../components/cocktails/SelectEdit";
|
||||||
import {getComparator} from "../../../components/core/getComparator";
|
|
||||||
import {useSearchParams} from "react-router-dom";
|
import {useSearchParams} from "react-router-dom";
|
||||||
import {Loading} from "../../../components/core/Loading";
|
import {Loading} from "../../../components/core/Loading";
|
||||||
import CloudUploadIcon from '@mui/icons-material/CloudUpload';
|
import CloudUploadIcon from '@mui/icons-material/CloudUpload';
|
||||||
import {styled} from "@mui/material/styles";
|
import {styled} from "@mui/material/styles";
|
||||||
|
import {cocktailClient} from "../../../lib/clients/CocktailClient";
|
||||||
|
import {categoryClient} from "../../../lib/clients/CategoryClient";
|
||||||
|
import {glassClient} from "../../../lib/clients/GlassClient";
|
||||||
|
|
||||||
const emptyCocktail = {
|
const emptyCocktail = {
|
||||||
id: null,
|
id: null,
|
||||||
@@ -75,55 +75,15 @@ export function EditCocktailPage() {
|
|||||||
const [category, setCategory] = useState([]);
|
const [category, setCategory] = useState([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
api().get(requests.cocktails.simple)
|
cocktailClient.getSimpleList(setCocktails, setSelected, setLoading, createError, searchParams.get("id"))
|
||||||
.then((r) => {
|
categoryClient.getCategoryList(setCategory, createError);
|
||||||
const arr = r.data.sort(getComparator("asc", "name"));
|
glassClient.getGlassList(setGlass, createError)
|
||||||
setCocktails(arr)
|
|
||||||
|
|
||||||
const currentId = searchParams.get("id");
|
|
||||||
if (!currentId) {
|
|
||||||
setLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const currentCocktail = arr.find((r) => r.id === (currentId * 1));
|
|
||||||
if (!currentCocktail) {
|
|
||||||
setLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setSelected(currentCocktail.id);
|
|
||||||
setLoading(false);
|
|
||||||
})
|
|
||||||
.catch(() => createError("Ошибка получения данных"))
|
|
||||||
|
|
||||||
api().get(requests.category.basic)
|
|
||||||
.then((r) => {
|
|
||||||
setCategory(r.data.sort(getComparator())
|
|
||||||
.map((item, i) => {
|
|
||||||
return {id: i, name: item}
|
|
||||||
}))
|
|
||||||
})
|
|
||||||
.catch(() => createError("Ошибка получения категорий"))
|
|
||||||
|
|
||||||
api().get(requests.glass.list)
|
|
||||||
.then((r) => setGlass(r.data.sort(getComparator())
|
|
||||||
.map((item, i) => {
|
|
||||||
return {id: i, name: item}
|
|
||||||
})))
|
|
||||||
.catch(() => createError("Ошибка получения посуды"))
|
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
}, []);
|
}, []);
|
||||||
useEffect(() => {
|
|
||||||
if (!selected) {
|
useEffect(() => cocktailClient.getOneCocktail(selected, setCocktail, getError, emptyCocktail), [selected])
|
||||||
setCocktail(emptyCocktail);
|
const saveHandler = () => cocktailClient.saveChangeCocktail(cocktail, createError, createSuccess)
|
||||||
return;
|
const deleteHandle = () => cocktailClient.deleteCocktailFromEdit(setCocktails, setCocktail, createError, cocktails, cocktail, emptyCocktail)
|
||||||
}
|
|
||||||
api().get(requests.cocktails.cocktail + selected)
|
|
||||||
.then((r) => {
|
|
||||||
setCocktail(r.data)
|
|
||||||
})
|
|
||||||
.catch(() => getError());
|
|
||||||
// eslint-disable-next-line
|
|
||||||
}, [selected])
|
|
||||||
|
|
||||||
const changeCocktailValue = (name, value) => {
|
const changeCocktailValue = (name, value) => {
|
||||||
if (name === "tags") {
|
if (name === "tags") {
|
||||||
@@ -134,25 +94,7 @@ export function EditCocktailPage() {
|
|||||||
[name]: value
|
[name]: value
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
const saveHandler = () => {
|
|
||||||
api().patch(requests.cocktails.basic, cocktail)
|
|
||||||
.then((r) => {
|
|
||||||
if (!r.data.error) {
|
|
||||||
createSuccess("Сохранено")
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
createError("Ошибка на сервере: " + r.data.error)
|
|
||||||
})
|
|
||||||
.catch(() => createError("Неизвестная ошибка"))
|
|
||||||
}
|
|
||||||
const deleteHandle = () => {
|
|
||||||
api().delete(requests.cocktails.cocktail + cocktail.id)
|
|
||||||
.then(() => {
|
|
||||||
setCocktails(cocktails.filter((r) => r.id !== cocktail.id))
|
|
||||||
setCocktail(emptyCocktail);
|
|
||||||
})
|
|
||||||
.catch(() => createError("Ошибка удаления коктейля"))
|
|
||||||
}
|
|
||||||
return (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
{/*Загрузка*/}
|
{/*Загрузка*/}
|
||||||
@@ -208,14 +150,7 @@ export function EditCocktailPage() {
|
|||||||
<VisuallyHiddenInput
|
<VisuallyHiddenInput
|
||||||
type="file"
|
type="file"
|
||||||
accept=".jpg,.jpeg,.png"
|
accept=".jpg,.jpeg,.png"
|
||||||
onChange={(event) => {
|
onChange={(event) => cocktailClient.savePhoto(event, changeCocktailValue, getError)}
|
||||||
const file = event.target.files[0];
|
|
||||||
let formData = new FormData();
|
|
||||||
formData.append('file', file);
|
|
||||||
api().post(requests.cocktails.photo, formData)
|
|
||||||
.then((r) => changeCocktailValue("image", r.data))
|
|
||||||
.catch(() => getError())
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ import * as React from "react";
|
|||||||
import {useEffect, useState} from "react";
|
import {useEffect, useState} from "react";
|
||||||
import Paper from "@mui/material/Paper";
|
import Paper from "@mui/material/Paper";
|
||||||
import {Autocomplete, FormControl, FormControlLabel, InputLabel} from "@mui/material";
|
import {Autocomplete, FormControl, FormControlLabel, InputLabel} from "@mui/material";
|
||||||
import {api} from "../../../lib/clients/api";
|
|
||||||
import {requests} from "../../../requests";
|
|
||||||
import {useAlert} from "../../../hooks/useAlert";
|
import {useAlert} from "../../../hooks/useAlert";
|
||||||
import {useSearchParams} from "react-router-dom";
|
import {useSearchParams} from "react-router-dom";
|
||||||
import TextField from "@mui/material/TextField";
|
import TextField from "@mui/material/TextField";
|
||||||
@@ -15,7 +13,7 @@ import Stack from "@mui/material/Stack";
|
|||||||
import Button from "@mui/material/Button";
|
import Button from "@mui/material/Button";
|
||||||
import Select from "@mui/material/Select";
|
import Select from "@mui/material/Select";
|
||||||
import MenuItem from "@mui/material/MenuItem";
|
import MenuItem from "@mui/material/MenuItem";
|
||||||
import {getComparator} from "../../../components/core/getComparator";
|
import {ingredientClient} from "../../../lib/clients/IngredientClient";
|
||||||
|
|
||||||
const emptyIngredient = {
|
const emptyIngredient = {
|
||||||
id: null,
|
id: null,
|
||||||
@@ -36,25 +34,8 @@ export function EditIngredientPage() {
|
|||||||
const [ingredient, setIngredient] = useState(emptyIngredient)
|
const [ingredient, setIngredient] = useState(emptyIngredient)
|
||||||
const {createError, createSuccess} = useAlert();
|
const {createError, createSuccess} = useAlert();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
api().get(requests.ingredient.all)
|
ingredientClient.allList(searchParams.get("id"), setIngredients, setIngredient, createError)
|
||||||
.then((r) => {
|
ingredientClient.getType(setTypes)
|
||||||
const arr = r.data.sort(getComparator("asc", "name"));
|
|
||||||
setIngredients(arr)
|
|
||||||
|
|
||||||
const currentId = searchParams.get("id");
|
|
||||||
if (!currentId) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const currentIngredient = arr.find((r) => r.id === (currentId * 1));
|
|
||||||
if (!currentIngredient) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setIngredient(currentIngredient);
|
|
||||||
})
|
|
||||||
.catch(() => createError("Ошибка получения данных"))
|
|
||||||
|
|
||||||
api().get(requests.ingredient.type)
|
|
||||||
.then((r) => setTypes(r.data.sort(getComparator("asc", "name"))))
|
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -64,11 +45,6 @@ export function EditIngredientPage() {
|
|||||||
[name]: value
|
[name]: value
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
const saveIngredientHandler = () => {
|
|
||||||
api().patch(requests.ingredient.crud, ingredient)
|
|
||||||
.then(() => createSuccess("Ингредиент сохранен"))
|
|
||||||
.catch(() => createError("Ошибка сохранения"))
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
@@ -158,7 +134,8 @@ export function EditIngredientPage() {
|
|||||||
</Stack>
|
</Stack>
|
||||||
</Paper>
|
</Paper>
|
||||||
<Box display={'flex'} justifyContent={'flex-end'}>
|
<Box display={'flex'} justifyContent={'flex-end'}>
|
||||||
<Button variant='contained' onClick={() => saveIngredientHandler()}>Сохранить</Button>
|
<Button variant='contained'
|
||||||
|
onClick={() => ingredientClient.saveIngredient(ingredient, createSuccess, createError)}>Сохранить</Button>
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -8,10 +8,8 @@ import SearchIcon from "@mui/icons-material/Search";
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import {useEffect, useMemo, useState} from "react";
|
import {useEffect, useMemo, useState} from "react";
|
||||||
import {Loading} from "../../../components/core/Loading";
|
import {Loading} from "../../../components/core/Loading";
|
||||||
import {requests} from "../../../requests";
|
|
||||||
import {useAlert} from "../../../hooks/useAlert";
|
import {useAlert} from "../../../hooks/useAlert";
|
||||||
import {IngredientInfoModal} from "../../../components/Ingredients/IngredientInfoModal";
|
import {IngredientInfoModal} from "../../../components/Ingredients/IngredientInfoModal";
|
||||||
import {api} from "../../../lib/clients/api";
|
|
||||||
import Tab from "@mui/material/Tab";
|
import Tab from "@mui/material/Tab";
|
||||||
import {a11yProps} from "../../../components/core/tabProps";
|
import {a11yProps} from "../../../components/core/tabProps";
|
||||||
import {CustomTabPanel} from "../../../components/core/TabPanel";
|
import {CustomTabPanel} from "../../../components/core/TabPanel";
|
||||||
@@ -19,6 +17,7 @@ import {IngredientList} from "../../../components/Ingredients/IngredientList";
|
|||||||
import {blue} from "@mui/material/colors";
|
import {blue} from "@mui/material/colors";
|
||||||
import UpIcon from "@mui/icons-material/KeyboardArrowUp";
|
import UpIcon from "@mui/icons-material/KeyboardArrowUp";
|
||||||
import {useSelect} from "../../../hooks/useSelect";
|
import {useSelect} from "../../../hooks/useSelect";
|
||||||
|
import {ingredientClient} from "../../../lib/clients/IngredientClient";
|
||||||
|
|
||||||
export function IngredientsPage() {
|
export function IngredientsPage() {
|
||||||
const [value, setValue] = React.useState(0);
|
const [value, setValue] = React.useState(0);
|
||||||
@@ -30,15 +29,7 @@ export function IngredientsPage() {
|
|||||||
const {createError, createSuccess} = useAlert();
|
const {createError, createSuccess} = useAlert();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
api().get(requests.ingredient.all)
|
ingredientClient.getAllIngredients(setIngredients, setLoading, createError)
|
||||||
.then((r) => {
|
|
||||||
setIngredients(r.data)
|
|
||||||
setLoading(false);
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
createError("Ошибка получения списка ингредиентов");
|
|
||||||
setLoading(false);
|
|
||||||
})
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -63,26 +54,12 @@ export function IngredientsPage() {
|
|||||||
return ingredient;
|
return ingredient;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
const url = `${requests.ingredient.crud}?id=${row.id}`;
|
ingredientClient.changeIngredientIsHave(row.id, value, newState, setIngredients, createError)
|
||||||
const request = value ? api().put(url) : api().delete(url);
|
|
||||||
request
|
|
||||||
.then(() => {
|
|
||||||
setIngredients(newState);
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
createError("Ошибка изменения ингредиента");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
const handleOpenModal = (i) => {
|
|
||||||
selectIngredient(i)
|
|
||||||
}
|
}
|
||||||
const handleDelete = (id) => {
|
const handleDelete = (id) => {
|
||||||
const newState = ingredients.filter((ingredient) => ingredient.id !== id);
|
const newState = ingredients.filter((ingredient) => ingredient.id !== id);
|
||||||
setIngredients(newState)
|
setIngredients(newState)
|
||||||
|
ingredientClient.deleteIngredientIsHave(id, createSuccess, createError)
|
||||||
api().delete(`${requests.ingredient.crud}/${id}`)
|
|
||||||
.then((r) => createSuccess("Ингредиент удален"))
|
|
||||||
.catch(() => createError("Ошибка удаления ингредиента. Перезагрузите страницу"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -118,11 +95,11 @@ export function IngredientsPage() {
|
|||||||
<Box>
|
<Box>
|
||||||
<CustomTabPanel value={value} index={0}>
|
<CustomTabPanel value={value} index={0}>
|
||||||
<IngredientList rows={ingredientsInBar} value={false} changeHandler={changeHandler}
|
<IngredientList rows={ingredientsInBar} value={false} changeHandler={changeHandler}
|
||||||
infoHandler={handleOpenModal}/>
|
infoHandler={selectIngredient}/>
|
||||||
</CustomTabPanel>
|
</CustomTabPanel>
|
||||||
<CustomTabPanel value={value} index={1}>
|
<CustomTabPanel value={value} index={1}>
|
||||||
<IngredientList rows={ingredientsToAdd} value={true} changeHandler={changeHandler}
|
<IngredientList rows={ingredientsToAdd} value={true} changeHandler={changeHandler}
|
||||||
infoHandler={handleOpenModal}/>
|
infoHandler={selectIngredient}/>
|
||||||
</CustomTabPanel>
|
</CustomTabPanel>
|
||||||
</Box>
|
</Box>
|
||||||
<Fab sx={{
|
<Fab sx={{
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
import Dialog from "@mui/material/Dialog";
|
import Dialog from "@mui/material/Dialog";
|
||||||
import DialogTitle from "@mui/material/DialogTitle";
|
import DialogTitle from "@mui/material/DialogTitle";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
|
import {useState} from "react";
|
||||||
import Typography from "@mui/material/Typography";
|
import Typography from "@mui/material/Typography";
|
||||||
import DialogContent from "@mui/material/DialogContent";
|
import DialogContent from "@mui/material/DialogContent";
|
||||||
import DialogActions from "@mui/material/DialogActions";
|
import DialogActions from "@mui/material/DialogActions";
|
||||||
import Button from "@mui/material/Button";
|
import Button from "@mui/material/Button";
|
||||||
import {useState} from "react";
|
|
||||||
import TextField from "@mui/material/TextField";
|
import TextField from "@mui/material/TextField";
|
||||||
|
|
||||||
export function BarCreateModal({open, close, create}) {
|
export function BarCreateModal({open, setOpen, create}) {
|
||||||
const [value, setValue] = useState("");
|
const [value, setValue] = useState("");
|
||||||
return (
|
return (
|
||||||
<Dialog fullWidth={true}
|
<Dialog fullWidth={true}
|
||||||
open={open} onClose={close}
|
open={open} onClose={() => setOpen(false)}
|
||||||
sx={{
|
sx={{
|
||||||
'& .MuiDialog-paper': {
|
'& .MuiDialog-paper': {
|
||||||
margin: '8px',
|
margin: '8px',
|
||||||
|
|||||||
@@ -4,17 +4,16 @@ import DialogContent from "@mui/material/DialogContent";
|
|||||||
import DialogActions from "@mui/material/DialogActions";
|
import DialogActions from "@mui/material/DialogActions";
|
||||||
import Button from "@mui/material/Button";
|
import Button from "@mui/material/Button";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
|
import {useEffect, useState} from "react";
|
||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
import Typography from "@mui/material/Typography";
|
import Typography from "@mui/material/Typography";
|
||||||
import List from "@mui/material/List";
|
import List from "@mui/material/List";
|
||||||
import {useEffect, useState} from "react";
|
|
||||||
import {api} from "../../lib/clients/api";
|
|
||||||
import {requests} from "../../requests";
|
|
||||||
import {useAlert} from "../../hooks/useAlert";
|
import {useAlert} from "../../hooks/useAlert";
|
||||||
import ListItem from "@mui/material/ListItem";
|
import ListItem from "@mui/material/ListItem";
|
||||||
import {useSelect} from "../../hooks/useSelect";
|
import {useSelect} from "../../hooks/useSelect";
|
||||||
import {IngredientAlert} from "./IngredientAlert";
|
import {IngredientAlert} from "./IngredientAlert";
|
||||||
import {useUser} from "../../hooks/useUser";
|
import {useUser} from "../../hooks/useUser";
|
||||||
|
import {cocktailClient} from "../../lib/clients/CocktailClient";
|
||||||
|
|
||||||
export function IngredientInfoModal({ingredient, handleDelete}) {
|
export function IngredientInfoModal({ingredient, handleDelete}) {
|
||||||
const {user} = useUser();
|
const {user} = useUser();
|
||||||
@@ -28,11 +27,7 @@ export function IngredientInfoModal({ingredient, handleDelete}) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if(!ingredient) {
|
cocktailClient.getCocktailByIngredient(ingredient, setCocktails)
|
||||||
return
|
|
||||||
}
|
|
||||||
api().get(requests.cocktails.byIngredient + ingredient.id)
|
|
||||||
.then((r) => setCocktails(r.data))
|
|
||||||
.catch(() => createError())
|
.catch(() => createError())
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
}, [ingredient]);
|
}, [ingredient]);
|
||||||
@@ -59,7 +54,7 @@ export function IngredientInfoModal({ingredient, handleDelete}) {
|
|||||||
</Stack>
|
</Stack>
|
||||||
{cocktails.length > 0 && (
|
{cocktails.length > 0 && (
|
||||||
<>
|
<>
|
||||||
<Typography sx={{ mt:2}}>Коктейли:</Typography>
|
<Typography sx={{mt: 2}}>Коктейли:</Typography>
|
||||||
<List>
|
<List>
|
||||||
{cocktails.map((c) => {
|
{cocktails.map((c) => {
|
||||||
return (
|
return (
|
||||||
@@ -69,7 +64,7 @@ export function IngredientInfoModal({ingredient, handleDelete}) {
|
|||||||
}}>
|
}}>
|
||||||
<Stack direction={'row'}>
|
<Stack direction={'row'}>
|
||||||
<img src={c.image} alt={c.name} loading={"eager"} width={"50"}/>
|
<img src={c.image} alt={c.name} loading={"eager"} width={"50"}/>
|
||||||
<Typography sx={{mx:1}}>{c.name}</Typography>
|
<Typography sx={{mx: 1}}>{c.name}</Typography>
|
||||||
{c.rating.rating > 0 && <Typography> {`${c.rating.rating}/5`}</Typography>}
|
{c.rating.rating > 0 && <Typography> {`${c.rating.rating}/5`}</Typography>}
|
||||||
</Stack>
|
</Stack>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
@@ -83,7 +78,8 @@ export function IngredientInfoModal({ingredient, handleDelete}) {
|
|||||||
{user.role !== 'USER' && <Button onClick={() => setOpen(true)}>Удалить</Button>}
|
{user.role !== 'USER' && <Button onClick={() => setOpen(true)}>Удалить</Button>}
|
||||||
<Button onClick={closeIngredient}>Закрыть</Button>
|
<Button onClick={closeIngredient}>Закрыть</Button>
|
||||||
</DialogActions>
|
</DialogActions>
|
||||||
<IngredientAlert handleDelete={handleDelete} handleClose={handleClose} open={open} id={ingredient.id} handleCloseParent={closeIngredient}/>
|
<IngredientAlert handleDelete={handleDelete} handleClose={handleClose} open={open} id={ingredient.id}
|
||||||
|
handleCloseParent={closeIngredient}/>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -10,9 +10,8 @@ import Button from "@mui/material/Button";
|
|||||||
import CircularProgress from "@mui/material/CircularProgress";
|
import CircularProgress from "@mui/material/CircularProgress";
|
||||||
import Box from "@mui/material/Box";
|
import Box from "@mui/material/Box";
|
||||||
import {red} from "@mui/material/colors";
|
import {red} from "@mui/material/colors";
|
||||||
import {requests} from "../../requests";
|
|
||||||
import {useAuth} from "../../hooks/useAuth";
|
import {useAuth} from "../../hooks/useAuth";
|
||||||
import {api} from "../../lib/clients/api";
|
import {authClient} from "../../lib/clients/AuthClient";
|
||||||
|
|
||||||
const emptyRequest = {
|
const emptyRequest = {
|
||||||
byLogin: true,
|
byLogin: true,
|
||||||
@@ -38,21 +37,9 @@ export function SignInForm() {
|
|||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
const handleButtonClick = async () => {
|
const handleButtonClick = async () => {
|
||||||
setLoading(true);
|
await authClient.login(request, setLoading, setError, checkSession)
|
||||||
const response = await api().post(requests.auth.login, request);
|
|
||||||
|
|
||||||
if (response.data.error) {
|
|
||||||
setError(response.data.error);
|
|
||||||
setLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
localStorage.setItem("token", response.data.token);
|
|
||||||
|
|
||||||
await checkSession?.();
|
|
||||||
|
|
||||||
window.location.reload();
|
|
||||||
}
|
|
||||||
const renderByCode = () => {
|
const renderByCode = () => {
|
||||||
return (
|
return (
|
||||||
<Stack direction='row' mt={1}>
|
<Stack direction='row' mt={1}>
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
import {Card} from "@mui/material";
|
|
||||||
import Stack from "@mui/material/Stack";
|
|
||||||
import Box from "@mui/material/Box";
|
|
||||||
import React from "react";
|
|
||||||
import Typography from "@mui/material/Typography";
|
|
||||||
import Button from "@mui/material/Button";
|
|
||||||
|
|
||||||
const role = (myRole) => {
|
|
||||||
switch (myRole) {
|
|
||||||
case "ADMIN":
|
|
||||||
return "Администратор";
|
|
||||||
case "ADMIN_NOT_BARMEN":
|
|
||||||
return "Управляющий";
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function BarItem({row, changeHandler, all, enterExist}) {
|
|
||||||
return (
|
|
||||||
<Card sx={{mb: 1, height: '100px', display: 'relative', p: 1}}>
|
|
||||||
<Stack direction='row' justifyContent='start' alignItems='start'>
|
|
||||||
<Box sx={{width: '75%', pr: 2}}>
|
|
||||||
<Typography variant='h6'>{row.name}</Typography>
|
|
||||||
<Typography>{role(row.myRole)}</Typography>
|
|
||||||
</Box>
|
|
||||||
<Stack sx={{width: '25%'}} spacing={1} justifyContent='flex-end' display='flex'>
|
|
||||||
<Typography color={row.open ? 'green' : 'red'}>{row.open ? "Бар открыт" : "Бар закрыт"}</Typography>
|
|
||||||
<Button variant='contained'
|
|
||||||
color={row.enter ? 'error' : 'success'}
|
|
||||||
onClick={() => changeHandler(row, !row.enter)}
|
|
||||||
disabled={!row.enter && enterExist}
|
|
||||||
>
|
|
||||||
{all ? "Добавить" : row.enter ? "Выйти" : "Войти"}
|
|
||||||
</Button>
|
|
||||||
</Stack>
|
|
||||||
</Stack>
|
|
||||||
</Card>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
import Box from "@mui/material/Box";
|
|
||||||
import {useEffect, useMemo, useState} from "react";
|
|
||||||
import {api} from "../../lib/clients/api";
|
|
||||||
import {requests} from "../../requests";
|
|
||||||
import {useAlert} from "../../hooks/useAlert";
|
|
||||||
import {BarItem} from "./BarItem";
|
|
||||||
import {Loading} from "../core/Loading";
|
|
||||||
import * as React from "react";
|
|
||||||
import {useUser} from "../../hooks/useUser";
|
|
||||||
|
|
||||||
export function BarList({all}) {
|
|
||||||
const {getError, createError} = useAlert();
|
|
||||||
const {refresh} = useUser();
|
|
||||||
const [bars, setBars] = useState([]);
|
|
||||||
const [loading, setLoading] = useState(true);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setLoading(true);
|
|
||||||
api().get(`${requests.bar.all}?my=${!all}`)
|
|
||||||
.then((r) => {
|
|
||||||
setBars(r.data)
|
|
||||||
setLoading(false);
|
|
||||||
})
|
|
||||||
.catch(() => getError())
|
|
||||||
// eslint-disable-next-line
|
|
||||||
}, []);
|
|
||||||
const enterExist = useMemo(() => bars.find((b) => b.enter), [bars])
|
|
||||||
const changeHandler = (row, value) => {
|
|
||||||
let request;
|
|
||||||
let newState;
|
|
||||||
if (!all) {
|
|
||||||
if (value && enterExist) {
|
|
||||||
//todo: добавить переключение
|
|
||||||
createError("Нельзя войти более чем в один бар одновременно")
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
request = api().patch(`${requests.bar.enter}${row.id}&value=${value}`);
|
|
||||||
newState = bars.map((b) => {
|
|
||||||
if (b.id !== row.id) {
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
...b,
|
|
||||||
enter: value
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
request = api().post(requests.bar.addToMyList, row);
|
|
||||||
newState = bars.filter((b) => b.id !== row.id);
|
|
||||||
}
|
|
||||||
request.then(() => {
|
|
||||||
setBars(newState)
|
|
||||||
refresh();
|
|
||||||
}).catch(() => getError())
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<Box mt={2}>
|
|
||||||
{
|
|
||||||
bars.map((row) => {
|
|
||||||
return (
|
|
||||||
<BarItem key={row.id} row={row} changeHandler={changeHandler}
|
|
||||||
all={all} enterExist={enterExist}/>
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
{/*Загрузчик*/}
|
|
||||||
<Loading loading={loading}/>
|
|
||||||
</Box>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -15,13 +15,13 @@ import IconButton from "@mui/material/IconButton";
|
|||||||
import ShoppingCartIcon from '@mui/icons-material/ShoppingCart';
|
import ShoppingCartIcon from '@mui/icons-material/ShoppingCart';
|
||||||
import DeleteIcon from '@mui/icons-material/Delete';
|
import DeleteIcon from '@mui/icons-material/Delete';
|
||||||
import {IngredientInfoModal} from "../Ingredients/IngredientInfoModal";
|
import {IngredientInfoModal} from "../Ingredients/IngredientInfoModal";
|
||||||
import {api} from "../../lib/clients/api";
|
|
||||||
import {requests} from "../../requests";
|
|
||||||
import {useAlert} from "../../hooks/useAlert";
|
import {useAlert} from "../../hooks/useAlert";
|
||||||
import {paths} from "../../path";
|
import {paths} from "../../path";
|
||||||
import {Loading} from "../core/Loading";
|
import {Loading} from "../core/Loading";
|
||||||
import {useUser} from "../../hooks/useUser";
|
import {useUser} from "../../hooks/useUser";
|
||||||
import {useSelect} from "../../hooks/useSelect";
|
import {useSelect} from "../../hooks/useSelect";
|
||||||
|
import {cocktailClient} from "../../lib/clients/CocktailClient";
|
||||||
|
import {ingredientClient} from "../../lib/clients/IngredientClient";
|
||||||
|
|
||||||
export function CocktailInfoModal({row}) {
|
export function CocktailInfoModal({row}) {
|
||||||
const {user} = useUser();
|
const {user} = useUser();
|
||||||
@@ -29,56 +29,8 @@ export function CocktailInfoModal({row}) {
|
|||||||
const [cocktail, setCocktail] = useState(null)
|
const [cocktail, setCocktail] = useState(null)
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const {closeCocktail, selectIngredient, getIngredient, getOpenCocktail} = useSelect();
|
const {closeCocktail, selectIngredient, getIngredient, getOpenCocktail} = useSelect();
|
||||||
const openIngredientModalHandler = (id) => {
|
|
||||||
api().get(`${requests.bar.ingredient}?id=${id}`)
|
|
||||||
.then((r) => {
|
|
||||||
selectIngredient(r.data)
|
|
||||||
})
|
|
||||||
.catch(() => createError("Ошибка получения информации об ингредиенте"))
|
|
||||||
}
|
|
||||||
const selectIngredientHandler = (ingredient) => {
|
|
||||||
const url = `${requests.ingredient.crud}?id=${ingredient.id}`;
|
|
||||||
const request = ingredient.isHave ? api().delete(url) : api().put(url);
|
|
||||||
const value = !ingredient.isHave;
|
|
||||||
request.then(() => {
|
|
||||||
const newReceipts = cocktail.receipt.map((r) => {
|
|
||||||
if (r.ingredient.id !== ingredient.id) {
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
...r,
|
|
||||||
ingredient: {
|
|
||||||
...ingredient,
|
|
||||||
isHave: value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
setCocktail({
|
|
||||||
...cocktail,
|
|
||||||
receipt: newReceipts
|
|
||||||
})
|
|
||||||
createSuccess("Сохранено")
|
|
||||||
}).catch(() => createError("Ошибка сохранения"))
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => cocktailClient.getCocktailForModal(row, setLoading, setCocktail, closeCocktail, getError), [row]);
|
||||||
setLoading(true)
|
|
||||||
if (!row) {
|
|
||||||
setLoading(false)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
api().get(requests.cocktails.modal + row)
|
|
||||||
.then((r) => {
|
|
||||||
setCocktail(r.data)
|
|
||||||
setLoading(false)
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
getError();
|
|
||||||
setLoading(false)
|
|
||||||
closeCocktail();
|
|
||||||
})
|
|
||||||
// eslint-disable-next-line
|
|
||||||
}, [row]);
|
|
||||||
|
|
||||||
if (!row || !cocktail) {
|
if (!row || !cocktail) {
|
||||||
return null;
|
return null;
|
||||||
@@ -134,7 +86,7 @@ export function CocktailInfoModal({row}) {
|
|||||||
<Stack direction='row'>
|
<Stack direction='row'>
|
||||||
{(user.role && user.role !== "USER") && (
|
{(user.role && user.role !== "USER") && (
|
||||||
<IconButton size="small" sx={{pb: "2px"}}
|
<IconButton size="small" sx={{pb: "2px"}}
|
||||||
onClick={() => selectIngredientHandler(r.ingredient)}>
|
onClick={() => ingredientClient.changeIngredientInBar(r.ingredient, cocktail, setCocktail, createSuccess, createError)}>
|
||||||
{r.ingredient.isHave
|
{r.ingredient.isHave
|
||||||
? (<DeleteIcon fontSize="small"/>)
|
? (<DeleteIcon fontSize="small"/>)
|
||||||
: (<ShoppingCartIcon fontSize="small"/>)
|
: (<ShoppingCartIcon fontSize="small"/>)
|
||||||
@@ -142,7 +94,7 @@ export function CocktailInfoModal({row}) {
|
|||||||
</IconButton>
|
</IconButton>
|
||||||
)}
|
)}
|
||||||
<Typography
|
<Typography
|
||||||
onClick={() => openIngredientModalHandler(r.ingredient.id)}>{r.ingredient.name}</Typography>
|
onClick={() => ingredientClient.findOne(r.ingredient.id, selectIngredient, createError)}>{r.ingredient.name}</Typography>
|
||||||
</Stack>
|
</Stack>
|
||||||
<Typography color={hasError && 'red'}>{measure}</Typography>
|
<Typography color={hasError && 'red'}>{measure}</Typography>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|||||||
@@ -6,13 +6,11 @@ import AddIcon from "@mui/icons-material/Add";
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import {useEffect, useState} from "react";
|
import {useEffect, useState} from "react";
|
||||||
import {useAlert} from "../../hooks/useAlert";
|
import {useAlert} from "../../hooks/useAlert";
|
||||||
import {api} from "../../lib/clients/api";
|
|
||||||
import {requests} from "../../requests";
|
|
||||||
import {getComparator} from "../core/getComparator";
|
|
||||||
import {Card} from "@mui/material";
|
import {Card} from "@mui/material";
|
||||||
import {SelectEdit} from "./SelectEdit";
|
import {SelectEdit} from "./SelectEdit";
|
||||||
import TextField from "@mui/material/TextField";
|
import TextField from "@mui/material/TextField";
|
||||||
import DeleteForeverIcon from '@mui/icons-material/DeleteForever';
|
import DeleteForeverIcon from '@mui/icons-material/DeleteForever';
|
||||||
|
import {ingredientClient} from "../../lib/clients/IngredientClient";
|
||||||
|
|
||||||
export function EditCocktailReceipt({receipt, handler}) {
|
export function EditCocktailReceipt({receipt, handler}) {
|
||||||
const {createError} = useAlert()
|
const {createError} = useAlert()
|
||||||
@@ -20,13 +18,8 @@ export function EditCocktailReceipt({receipt, handler}) {
|
|||||||
const [units, setUnits] = useState([])
|
const [units, setUnits] = useState([])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
api().get(requests.ingredient.all)
|
ingredientClient.findAll(setIngredients, createError)
|
||||||
.then((r) => setIngredients(r.data.sort(getComparator("asc", "name"))))
|
ingredientClient.findUnit(setUnits, createError)
|
||||||
.catch(() => createError("Ошибка получения списка ингредиентов"))
|
|
||||||
|
|
||||||
api().get(requests.unit)
|
|
||||||
.then((r) => setUnits(r.data.sort(getComparator("asc", "name"))))
|
|
||||||
.catch(() => createError("Ошибка получения единиц измерения"))
|
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -153,7 +146,8 @@ export function EditCocktailReceipt({receipt, handler}) {
|
|||||||
value={r.count}
|
value={r.count}
|
||||||
onChange={(e) => countHandler(i, e.target.value)}
|
onChange={(e) => countHandler(i, e.target.value)}
|
||||||
/>
|
/>
|
||||||
<SelectEdit width={'calc(65% - 28px)'} array={units} value={!r.unit ? null : r.unit.name}
|
<SelectEdit width={'calc(65% - 28px)'} array={units}
|
||||||
|
value={!r.unit ? null : r.unit.name}
|
||||||
handler={unitHandler} label={"Ед."}
|
handler={unitHandler} label={"Ед."}
|
||||||
margin={1} attributeName={i}
|
margin={1} attributeName={i}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ import CheckMarks from "./CheckMarks";
|
|||||||
import Button from "@mui/material/Button";
|
import Button from "@mui/material/Button";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import {useEffect, useState} from "react";
|
import {useEffect, useState} from "react";
|
||||||
import {requests} from "../../requests";
|
|
||||||
import {useAlert} from "../../hooks/useAlert";
|
import {useAlert} from "../../hooks/useAlert";
|
||||||
import {api} from "../../lib/clients/api";
|
import {categoryClient} from "../../lib/clients/CategoryClient";
|
||||||
|
import {glassClient} from "../../lib/clients/GlassClient";
|
||||||
|
|
||||||
export function FilterBlock({filter, handleFilterChange, handleClearFilter, barmen}) {
|
export function FilterBlock({filter, handleFilterChange, handleClearFilter, barmen}) {
|
||||||
const {createError} = useAlert();
|
const {createError} = useAlert();
|
||||||
@@ -23,13 +23,8 @@ export function FilterBlock({filter, handleFilterChange, handleClearFilter, barm
|
|||||||
const sort = ['Название по возрастанию', 'Название по убыванию'];
|
const sort = ['Название по возрастанию', 'Название по убыванию'];
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
api().get(requests.category.basic)
|
categoryClient.getCategoryList(setCategory, createError)
|
||||||
.then((r) => setCategory(r.data))
|
glassClient.getGlassList(setGlass, createError)
|
||||||
.catch(() => createError("Ошибка получения категорий"))
|
|
||||||
|
|
||||||
api().get(requests.glass.list)
|
|
||||||
.then((r) => setGlass(r.data))
|
|
||||||
.catch(() => createError("Ошибка получения посуды"))
|
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,45 @@
|
|||||||
|
import {api} from "./api";
|
||||||
|
import {requests} from "../../requests";
|
||||||
|
|
||||||
class AuthClient {
|
class AuthClient {
|
||||||
|
|
||||||
async signOut() {
|
async signOut() {
|
||||||
localStorage.removeItem("token");
|
localStorage.removeItem("token");
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async login(request, setLoading, setError, checkSession) {
|
||||||
|
setLoading(true);
|
||||||
|
const response = await api().post(requests.auth.login, request);
|
||||||
|
|
||||||
|
if (response.data.error) {
|
||||||
|
setError(response.data.error);
|
||||||
|
setLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
localStorage.setItem("token", response.data.token);
|
||||||
|
|
||||||
|
await checkSession?.();
|
||||||
|
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
loginByCode(code, checkSession) {
|
||||||
|
const request = {
|
||||||
|
byLogin: false,
|
||||||
|
code: code
|
||||||
|
}
|
||||||
|
api().post(requests.auth.login, request)
|
||||||
|
.then(async (response) => {
|
||||||
|
if (response.data.error) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
localStorage.setItem("token", response.data.token);
|
||||||
|
await checkSession?.();
|
||||||
|
window.location.reload();
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const authClient = new AuthClient();
|
export const authClient = new AuthClient();
|
||||||
|
|||||||
63
front/src/lib/clients/BarClient.js
Normal file
63
front/src/lib/clients/BarClient.js
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
import {api} from "./api";
|
||||||
|
import {requests} from "../../requests";
|
||||||
|
import {getComparator} from "../../components/core/getComparator";
|
||||||
|
|
||||||
|
class BarClient {
|
||||||
|
|
||||||
|
getBarList(setBars, createError) {
|
||||||
|
api().get(requests.bar.all)
|
||||||
|
.then((r) => {
|
||||||
|
setBars(r.data.sort(getComparator("name")))
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
createError("Ошибка получения списков")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
changeBar(id, bars, createWarning, createSuccess, createError, setBars) {
|
||||||
|
createWarning("Дождитесь окончания операции")
|
||||||
|
api().post(`${requests.bar.change}/${id}`)
|
||||||
|
.then(() => createSuccess("Список изменен"))
|
||||||
|
.catch(() => createError("Ошибка изменения активного списка"))
|
||||||
|
|
||||||
|
const newState = bars.map((b) => {
|
||||||
|
if (b.active) {
|
||||||
|
return {
|
||||||
|
...b, active: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (b.id === id) {
|
||||||
|
return {
|
||||||
|
...b, active: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return b;
|
||||||
|
})
|
||||||
|
setBars(newState);
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteBar(bar, bars, createError, createSuccess, setBars) {
|
||||||
|
if (bar.active) {
|
||||||
|
createError("Нельзя удалить активный бар!")
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
api().delete(requests.bar.crud + bar.id)
|
||||||
|
.then(() => createSuccess("Список удален"))
|
||||||
|
.catch(() => createError("Ошибка удаления. Обновите страницу"))
|
||||||
|
|
||||||
|
setBars(bars.filter((b) => b.id !== bar.id));
|
||||||
|
}
|
||||||
|
|
||||||
|
createBar(name, bars, createSuccess, createError, setBars, setOpen) {
|
||||||
|
api().post(requests.bar.crud + name)
|
||||||
|
.then((r) => {
|
||||||
|
createSuccess("Cписок создан");
|
||||||
|
let state = bars;
|
||||||
|
state.push(r.data);
|
||||||
|
setBars(state)
|
||||||
|
setOpen(false)
|
||||||
|
}).catch(() => createError("Ошибка создания списка"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const barClient = new BarClient();
|
||||||
19
front/src/lib/clients/CategoryClient.js
Normal file
19
front/src/lib/clients/CategoryClient.js
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import {api} from "./api";
|
||||||
|
import {requests} from "../../requests";
|
||||||
|
import {getComparator} from "../../components/core/getComparator";
|
||||||
|
|
||||||
|
class CategoryClient {
|
||||||
|
|
||||||
|
getCategoryList(setCategory, createError) {
|
||||||
|
api().get(requests.category.basic)
|
||||||
|
.then((r) => {
|
||||||
|
setCategory(r.data.sort(getComparator())
|
||||||
|
.map((item, i) => {
|
||||||
|
return {id: i, name: item}
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
.catch(() => createError("Ошибка получения категорий"))
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const categoryClient = new CategoryClient();
|
||||||
201
front/src/lib/clients/CocktailClient.js
Normal file
201
front/src/lib/clients/CocktailClient.js
Normal file
@@ -0,0 +1,201 @@
|
|||||||
|
import {api} from "./api";
|
||||||
|
import {requests} from "../../requests";
|
||||||
|
import {sortList} from "../../components/cocktails/sortingList";
|
||||||
|
import {getComparator} from "../../components/core/getComparator";
|
||||||
|
|
||||||
|
class CocktailClient {
|
||||||
|
emptyCocktailForEditPage = {
|
||||||
|
id: null,
|
||||||
|
name: "",
|
||||||
|
alcoholic: "",
|
||||||
|
category: "",
|
||||||
|
components: "",
|
||||||
|
glass: "",
|
||||||
|
image: "",
|
||||||
|
instructions: "",
|
||||||
|
isAllowed: false,
|
||||||
|
rating: {
|
||||||
|
rating: 0,
|
||||||
|
favourite: false
|
||||||
|
},
|
||||||
|
receipt: [],
|
||||||
|
tags: "",
|
||||||
|
video: ""
|
||||||
|
}
|
||||||
|
|
||||||
|
getMenu(setRows, setIsNew, setPage, setLoad, setIsEnd, isNew, rows, page, size, filter, createError) {
|
||||||
|
setLoad(true);
|
||||||
|
|
||||||
|
const request = {
|
||||||
|
...filter,
|
||||||
|
sort: sortList.find((s) => s.name === filter.sorting).id,
|
||||||
|
page: page + 1,
|
||||||
|
size: size,
|
||||||
|
notHaveCount: Array.isArray(filter.iCount) ? null : filter.iCount
|
||||||
|
}
|
||||||
|
|
||||||
|
api().post(requests.cocktails.menu, request)
|
||||||
|
.then((r) => {
|
||||||
|
if (r.data.length === 0) {
|
||||||
|
if (isNew) {
|
||||||
|
setRows([]);
|
||||||
|
}
|
||||||
|
setIsEnd(true);
|
||||||
|
setLoad(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const cocktails = isNew ? r.data : rows.concat(r.data);
|
||||||
|
setRows(cocktails);
|
||||||
|
setIsNew(false);
|
||||||
|
setPage(page + 1);
|
||||||
|
setLoad(false);
|
||||||
|
})
|
||||||
|
.catch((r) => {
|
||||||
|
setLoad(false);
|
||||||
|
createError("Ошибка загрузки данных от сервера Status:" + r.code)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async getCocktailByIngredient(ingredient, setCocktails) {
|
||||||
|
if(!ingredient) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
api().get(requests.cocktails.byIngredient + ingredient.id)
|
||||||
|
.then((r) => setCocktails(r.data))
|
||||||
|
}
|
||||||
|
|
||||||
|
getCocktailsForCalcPage(load,setLoad, setCocktails, setCocktailMap, createError) {
|
||||||
|
if (load) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
api().get(requests.cocktails.calc)
|
||||||
|
.then((r) => {
|
||||||
|
const data = r.data;
|
||||||
|
if (data.length === 0) {
|
||||||
|
setLoad(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setCocktails(data);
|
||||||
|
let map = [];
|
||||||
|
map = data.map((d) => map[d.id] = 1)
|
||||||
|
setCocktailMap(map);
|
||||||
|
setLoad(true);
|
||||||
|
})
|
||||||
|
.catch((r) => {
|
||||||
|
setLoad(true);
|
||||||
|
createError("Ошибка загрузки данных от сервера Status:" + r.code)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
savePhoto(event, changeCocktailValue, getError) {
|
||||||
|
const file = event.target.files[0];
|
||||||
|
let formData = new FormData();
|
||||||
|
formData.append('file', file);
|
||||||
|
api().post(requests.cocktails.photo, formData)
|
||||||
|
.then((r) => changeCocktailValue("image", r.data))
|
||||||
|
.catch(() => getError())
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteCocktailFromEdit(setCocktails, setCocktail, createError, cocktails, cocktail, emptyCocktail) {
|
||||||
|
api().delete(requests.cocktails.cocktail + cocktail.id)
|
||||||
|
.then(() => {
|
||||||
|
setCocktails(cocktails.filter((r) => r.id !== cocktail.id))
|
||||||
|
setCocktail(emptyCocktail);
|
||||||
|
})
|
||||||
|
.catch(() => createError("Ошибка удаления коктейля"))
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteCocktail(id, rows, setRows, createSuccess, createError) {
|
||||||
|
api().delete(requests.cocktails.cocktail + id)
|
||||||
|
.then(() => {
|
||||||
|
setRows(rows.filter((r) => r.id !== id))
|
||||||
|
createSuccess("Коктейль удален")
|
||||||
|
})
|
||||||
|
.catch(() => createError("Ошибка удаления коктейля"))
|
||||||
|
}
|
||||||
|
|
||||||
|
saveChangeCocktail (cocktail, createError, createSuccess) {
|
||||||
|
api().patch(requests.cocktails.basic, cocktail)
|
||||||
|
.then((r) => {
|
||||||
|
if (!r.data.error) {
|
||||||
|
createSuccess("Сохранено")
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
createError("Ошибка на сервере: " + r.data.error)
|
||||||
|
})
|
||||||
|
.catch(() => createError("Неизвестная ошибка"))
|
||||||
|
}
|
||||||
|
|
||||||
|
getOneCocktail (selected, setCocktail, getError, emptyCocktail) {
|
||||||
|
if (!selected) {
|
||||||
|
setCocktail(emptyCocktail);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
api().get(requests.cocktails.cocktail + selected)
|
||||||
|
.then((r) => {
|
||||||
|
setCocktail(r.data)
|
||||||
|
})
|
||||||
|
.catch(() => getError());
|
||||||
|
}
|
||||||
|
|
||||||
|
getSimpleList(setCocktails, setSelected, setLoading, createError, currentId) {
|
||||||
|
api().get(requests.cocktails.simple)
|
||||||
|
.then((r) => {
|
||||||
|
const arr = r.data.sort(getComparator("asc", "name"));
|
||||||
|
setCocktails(arr)
|
||||||
|
|
||||||
|
if (!currentId) {
|
||||||
|
setLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const currentCocktail = arr.find((r) => r.id === (currentId * 1));
|
||||||
|
if (!currentCocktail) {
|
||||||
|
setLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setSelected(currentCocktail.id);
|
||||||
|
setLoading(false);
|
||||||
|
})
|
||||||
|
.catch(() => createError("Ошибка получения данных"))
|
||||||
|
}
|
||||||
|
|
||||||
|
getCocktailForModal (row, setLoading, setCocktail, closeCocktail, getError) {
|
||||||
|
setLoading(true)
|
||||||
|
if (!row) {
|
||||||
|
setLoading(false)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
api().get(requests.cocktails.modal + row)
|
||||||
|
.then((r) => {
|
||||||
|
setCocktail(r.data)
|
||||||
|
setLoading(false)
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
getError();
|
||||||
|
setLoading(false)
|
||||||
|
closeCocktail();
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
changeFavourite(value, id, newState, setRows, createSuccess, createError) {
|
||||||
|
const url = `${requests.cocktails.favourite}${id}`;
|
||||||
|
const request = value ? api().put(url) : api().delete(url);
|
||||||
|
|
||||||
|
request
|
||||||
|
.then(() => {
|
||||||
|
setRows(newState);
|
||||||
|
createSuccess("Спасибо за оценку!")
|
||||||
|
}).catch(() => createError("Ошибка сохранения"))
|
||||||
|
}
|
||||||
|
|
||||||
|
changeRating(id, newState, value, setRows, createSuccess, createError) {
|
||||||
|
api().post(`${requests.cocktails.rating}${id}&rating=${value}`)
|
||||||
|
.then(() => {
|
||||||
|
setRows(newState);
|
||||||
|
createSuccess("Спасибо за оценку!")
|
||||||
|
}).catch(() => createError("Ошибка сохранения"))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export const cocktailClient = new CocktailClient();
|
||||||
17
front/src/lib/clients/GlassClient.js
Normal file
17
front/src/lib/clients/GlassClient.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import {api} from "./api";
|
||||||
|
import {requests} from "../../requests";
|
||||||
|
import {getComparator} from "../../components/core/getComparator";
|
||||||
|
|
||||||
|
class GlassClient {
|
||||||
|
|
||||||
|
getGlassList(setGlass, createError) {
|
||||||
|
api().get(requests.glass.list)
|
||||||
|
.then((r) => setGlass(r.data.sort(getComparator())
|
||||||
|
.map((item, i) => {
|
||||||
|
return {id: i, name: item}
|
||||||
|
})))
|
||||||
|
.catch(() => createError("Ошибка получения посуды"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const glassClient = new GlassClient();
|
||||||
112
front/src/lib/clients/IngredientClient.js
Normal file
112
front/src/lib/clients/IngredientClient.js
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
import {api} from "./api";
|
||||||
|
import {requests} from "../../requests";
|
||||||
|
import {getComparator} from "../../components/core/getComparator";
|
||||||
|
|
||||||
|
class IngredientClient {
|
||||||
|
|
||||||
|
allList(currentId, setIngredients, setIngredient, createError) {
|
||||||
|
api().get(requests.ingredient.all)
|
||||||
|
.then((r) => {
|
||||||
|
const arr = r.data.sort(getComparator("asc", "name"));
|
||||||
|
setIngredients(arr)
|
||||||
|
|
||||||
|
if (!currentId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const currentIngredient = arr.find((r) => r.id === (currentId * 1));
|
||||||
|
if (!currentIngredient) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setIngredient(currentIngredient);
|
||||||
|
})
|
||||||
|
.catch(() => createError("Ошибка получения данных"))
|
||||||
|
}
|
||||||
|
|
||||||
|
getType(setTypes) {
|
||||||
|
api().get(requests.ingredient.type)
|
||||||
|
.then((r) => setTypes(r.data.sort(getComparator("asc", "name"))))
|
||||||
|
}
|
||||||
|
|
||||||
|
findAll(setIngredients, createError) {
|
||||||
|
api().get(requests.ingredient.all)
|
||||||
|
.then((r) => setIngredients(r.data.sort(getComparator("asc", "name"))))
|
||||||
|
.catch(() => createError("Ошибка получения списка ингредиентов"))
|
||||||
|
}
|
||||||
|
|
||||||
|
getAllIngredients(setIngredients, setLoading, createError) {
|
||||||
|
api().get(requests.ingredient.all)
|
||||||
|
.then((r) => {
|
||||||
|
setIngredients(r.data)
|
||||||
|
setLoading(false);
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
createError("Ошибка получения списка ингредиентов");
|
||||||
|
setLoading(false);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
changeIngredientIsHave(id, value, state, setIngredients, createError) {
|
||||||
|
const url = `${requests.ingredient.crud}?id=${id}`;
|
||||||
|
const request = value ? api().put(url) : api().delete(url);
|
||||||
|
request
|
||||||
|
.then(() => {
|
||||||
|
setIngredients(state);
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
createError("Ошибка изменения ингредиента");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteIngredientIsHave(id, createSuccess, createError) {
|
||||||
|
api().delete(`${requests.ingredient.crud}/${id}`)
|
||||||
|
.then(() => createSuccess("Ингредиент удален"))
|
||||||
|
.catch(() => createError("Ошибка удаления ингредиента. Перезагрузите страницу"))
|
||||||
|
}
|
||||||
|
|
||||||
|
saveIngredient(ingredient, createSuccess, createError) {
|
||||||
|
api().patch(requests.ingredient.crud, ingredient)
|
||||||
|
.then(() => createSuccess("Ингредиент сохранен"))
|
||||||
|
.catch(() => createError("Ошибка сохранения"))
|
||||||
|
}
|
||||||
|
|
||||||
|
findOne(id, selectIngredient, createError) {
|
||||||
|
api().get(`${requests.bar.ingredient}?id=${id}`)
|
||||||
|
.then((r) => {
|
||||||
|
selectIngredient(r.data)
|
||||||
|
})
|
||||||
|
.catch(() => createError("Ошибка получения информации об ингредиенте"))
|
||||||
|
}
|
||||||
|
|
||||||
|
changeIngredientInBar(ingredient, cocktail, setCocktail, createSuccess, createError) {
|
||||||
|
const url = `${requests.ingredient.crud}?id=${ingredient.id}`;
|
||||||
|
const request = ingredient.isHave ? api().delete(url) : api().put(url);
|
||||||
|
const value = !ingredient.isHave;
|
||||||
|
request.then(() => {
|
||||||
|
const newReceipts = cocktail.receipt.map((r) => {
|
||||||
|
if (r.ingredient.id !== ingredient.id) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
...r,
|
||||||
|
ingredient: {
|
||||||
|
...ingredient,
|
||||||
|
isHave: value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
setCocktail({
|
||||||
|
...cocktail,
|
||||||
|
receipt: newReceipts
|
||||||
|
})
|
||||||
|
createSuccess("Сохранено")
|
||||||
|
}).catch(() => createError("Ошибка сохранения"))
|
||||||
|
}
|
||||||
|
|
||||||
|
findUnit(setUnits, createError) {
|
||||||
|
api().get(requests.unit)
|
||||||
|
.then((r) => setUnits(r.data.sort(getComparator("asc", "name"))))
|
||||||
|
.catch(() => createError("Ошибка получения единиц измерения"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ingredientClient = new IngredientClient()
|
||||||
@@ -37,7 +37,6 @@ export const requests = {
|
|||||||
modal: routes.cocktail + "/modal?id=",
|
modal: routes.cocktail + "/modal?id=",
|
||||||
favourite: routes.cocktail + "/favourite?id=",
|
favourite: routes.cocktail + "/favourite?id=",
|
||||||
rating: routes.cocktail + "/rating?id=",
|
rating: routes.cocktail + "/rating?id=",
|
||||||
receipts: routes.cocktail + "/receipts?id=",
|
|
||||||
},
|
},
|
||||||
glass: {
|
glass: {
|
||||||
list: routes.glass,
|
list: routes.glass,
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
package ru.kayashov.bar.controller;
|
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
import ru.kayashov.bar.controller.dto.cocktail.ReceiptResponseDto;
|
|
||||||
import ru.kayashov.bar.service.ReceiptService;
|
|
||||||
|
|
||||||
import javax.annotation.security.PermitAll;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@CrossOrigin(origins = {"*"})
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/api/receipt")
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class ReceiptController {
|
|
||||||
|
|
||||||
private final ReceiptService receiptService;
|
|
||||||
|
|
||||||
@PermitAll
|
|
||||||
@GetMapping
|
|
||||||
public List<ReceiptResponseDto> getReceipt(@RequestParam("id") Long id) {
|
|
||||||
return receiptService.getReceiptList(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user