добавлен функционал копирования баров
This commit is contained in:
@@ -12,23 +12,34 @@ 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 ContentCopyIcon from '@mui/icons-material/ContentCopy';
|
||||||
import {barClient} from "../../lib/clients/BarClient";
|
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 [oldId, setOldId] = useState(null);
|
||||||
|
const {createError, createSuccess, createWarning, notImplement} = useAlert();
|
||||||
|
|
||||||
const createHandler = (name) => barClient.createBar(name, bars, createSuccess, createError, setBars, setOpen)
|
const createHandler = (id, name) => {
|
||||||
|
if (id) {
|
||||||
|
barClient.copyBar(id, name, setBars, bars, createError, createSuccess, setOpen)
|
||||||
|
} else {
|
||||||
|
barClient.createBar(name, bars, createSuccess, createError, setBars, setOpen)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => barClient.getBarList(setBars, createError), []);
|
useEffect(() => barClient.getBarList(setBars, createError), []);
|
||||||
|
|
||||||
return (<>
|
return (<>
|
||||||
<BarCreateModal open={open} setOpen={setOpen} create={createHandler}/>
|
<BarCreateModal open={open} setOpen={setOpen} create={createHandler} id={oldId}/>
|
||||||
<Paper sx={{p: 1}}>
|
<Paper sx={{p: 1}}>
|
||||||
<Toolbar>
|
<Toolbar>
|
||||||
<Typography variant='h6'>Списки ингредиентов (бары)</Typography>
|
<Typography variant='h6'>Списки ингредиентов (бары)</Typography>
|
||||||
<IconButton edge="end" onClick={() => setOpen(true)}>
|
<IconButton edge="end" onClick={() => {
|
||||||
|
setOldId(null);
|
||||||
|
setOpen(true);
|
||||||
|
}}>
|
||||||
<AddCircleIcon/>
|
<AddCircleIcon/>
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Toolbar>
|
</Toolbar>
|
||||||
@@ -36,18 +47,27 @@ export function BarChangePage() {
|
|||||||
return <Card key={b.id} sx={{m: 2, p: 2}}>
|
return <Card key={b.id} sx={{m: 2, p: 2}}>
|
||||||
<Stack direction='row' justifyContent={'space-between'}>
|
<Stack direction='row' justifyContent={'space-between'}>
|
||||||
<Typography>{b.name}</Typography>
|
<Typography>{b.name}</Typography>
|
||||||
|
<Box>
|
||||||
|
<IconButton onClick={() => {
|
||||||
|
setOldId(b.id)
|
||||||
|
setOpen(true);
|
||||||
|
}}>
|
||||||
|
<ContentCopyIcon/>
|
||||||
|
</IconButton>
|
||||||
{b.active && <IconButton disabled>
|
{b.active && <IconButton disabled>
|
||||||
<PowerIcon/>
|
<PowerIcon/>
|
||||||
</IconButton>}
|
</IconButton>}
|
||||||
{!b.active && <Box>
|
{!b.active && <>
|
||||||
<IconButton onClick={() => barClient.deleteBar(b, bars, createError, createSuccess, setBars)}>
|
<IconButton
|
||||||
|
onClick={() => barClient.deleteBar(b, bars, createError, createSuccess, setBars)}>
|
||||||
<DeleteIcon/>
|
<DeleteIcon/>
|
||||||
</IconButton>
|
</IconButton>
|
||||||
<IconButton
|
<IconButton
|
||||||
onClick={() => barClient.changeBar(b.id, bars, createWarning, createSuccess, createError, setBars)}>
|
onClick={() => barClient.changeBar(b.id, bars, createWarning, createSuccess, createError, setBars)}>
|
||||||
<ElectricalServicesIcon/>
|
<ElectricalServicesIcon/>
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Box>}
|
</>}
|
||||||
|
</Box>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Card>
|
</Card>
|
||||||
})}
|
})}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import DialogActions from "@mui/material/DialogActions";
|
|||||||
import Button from "@mui/material/Button";
|
import Button from "@mui/material/Button";
|
||||||
import TextField from "@mui/material/TextField";
|
import TextField from "@mui/material/TextField";
|
||||||
|
|
||||||
export function BarCreateModal({open, setOpen, create}) {
|
export function BarCreateModal({open, setOpen, create, id}) {
|
||||||
const [value, setValue] = useState("");
|
const [value, setValue] = useState("");
|
||||||
return (
|
return (
|
||||||
<Dialog fullWidth={true}
|
<Dialog fullWidth={true}
|
||||||
@@ -26,13 +26,17 @@ export function BarCreateModal({open, setOpen, create}) {
|
|||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
<TextField sx={{width: '75%'}}
|
<TextField sx={{width: '75%'}}
|
||||||
label={"Название списка"} variant='outlined'
|
label={<Typography pt={'4px'}>
|
||||||
|
Название списка</Typography>} variant='outlined'
|
||||||
value={!value ? "" : value}
|
value={!value ? "" : value}
|
||||||
onChange={(e) => setValue(e.target.value)}
|
onChange={(e) => setValue(e.target.value)}
|
||||||
/>
|
/>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
<Button onClick={() => create(value)}>Создать</Button>
|
<Button onClick={() => {
|
||||||
|
create(id, value);
|
||||||
|
setValue("");
|
||||||
|
}}>Создать</Button>
|
||||||
</DialogActions>
|
</DialogActions>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -58,6 +58,17 @@ class BarClient {
|
|||||||
setOpen(false)
|
setOpen(false)
|
||||||
}).catch(() => createError("Ошибка создания списка"))
|
}).catch(() => createError("Ошибка создания списка"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
copyBar(oldId, newName, setBars, bars, createError, createSuccess, setOpen) {
|
||||||
|
api().post(requests.bar.crud + "copy/" + oldId + "/" + newName)
|
||||||
|
.then((r) => {
|
||||||
|
const state = bars;
|
||||||
|
state.push(r.data)
|
||||||
|
setBars(state);
|
||||||
|
createSuccess("Бар скопирован")
|
||||||
|
setOpen(false)
|
||||||
|
}).catch(() => createError("Ошибка при копировании бара"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const barClient = new BarClient();
|
export const barClient = new BarClient();
|
||||||
Reference in New Issue
Block a user