Added categories / add category
This commit is contained in:
@@ -1,18 +1,28 @@
|
|||||||
import React from "react";
|
import React, { useState } from "react";
|
||||||
|
import { useSelector, useDispatch } from "react-redux";
|
||||||
import Divider from "@material-ui/core/Divider";
|
import Divider from "@material-ui/core/Divider";
|
||||||
import Accordion from "@material-ui/core/Accordion";
|
import Accordion from "@material-ui/core/Accordion";
|
||||||
import AccordionSummary from "@material-ui/core/AccordionSummary";
|
import AccordionSummary from "@material-ui/core/AccordionSummary";
|
||||||
import ExpandMoreIcon from "@material-ui/icons/ExpandMore";
|
import ExpandMoreIcon from "@material-ui/icons/ExpandMore";
|
||||||
import ButtonSecondary from "../Input/ButtonSecondary";
|
import ButtonSecondary from "../Input/ButtonSecondary";
|
||||||
import TextField from "@material-ui/core/TextField";
|
import TextField from "@material-ui/core/TextField";
|
||||||
|
import IconButton from "@material-ui/core/IconButton";
|
||||||
|
import DeleteIcon from "@material-ui/icons/Delete";
|
||||||
import List from "@material-ui/core/List";
|
import List from "@material-ui/core/List";
|
||||||
import ListItem from "@material-ui/core/ListItem";
|
import ListItem from "@material-ui/core/ListItem";
|
||||||
|
import AddIcon from "@material-ui/icons/Add";
|
||||||
import { makeStyles } from "@material-ui/core/styles";
|
import { makeStyles } from "@material-ui/core/styles";
|
||||||
|
import validator from "validator";
|
||||||
|
import LunchMenu from "./LunchMenu";
|
||||||
|
import axios from "axios";
|
||||||
|
import { notification, refreshUserData } from "../../actions";
|
||||||
|
import { showBackdrop, hideBackdrop } from "../../actions/toggles.js";
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const useStyles = makeStyles((theme) => ({
|
||||||
root: {
|
root: {
|
||||||
backgroundColor: "#262626",
|
backgroundColor: "#262626",
|
||||||
color: "#bbbbbb",
|
color: "#bbbbbb",
|
||||||
|
width: "100%",
|
||||||
},
|
},
|
||||||
expandIcon: {
|
expandIcon: {
|
||||||
color: "#bbbbbb",
|
color: "#bbbbbb",
|
||||||
@@ -34,23 +44,49 @@ const useStyles = makeStyles((theme) => ({
|
|||||||
|
|
||||||
export default function EditRestaurantMenu(props) {
|
export default function EditRestaurantMenu(props) {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const {
|
const { categories, lunchMenu } = props.restaurant;
|
||||||
imgUrl,
|
const [newCategory, setNewCategory] = useState("");
|
||||||
dishes,
|
const token = useSelector((state) => state.data.userData.jwt);
|
||||||
categories,
|
const dispatch = useDispatch();
|
||||||
lunchMenu,
|
|
||||||
name,
|
const addCategory = () => {
|
||||||
city,
|
if (validator.isLength(newCategory, { min: 1, max: 20 })) {
|
||||||
adress,
|
dispatch(showBackdrop());
|
||||||
placesId,
|
const data = {
|
||||||
location,
|
restaurantId: props.restaurant._id,
|
||||||
workingHours,
|
category: newCategory,
|
||||||
description,
|
action: "add",
|
||||||
tags,
|
};
|
||||||
links,
|
axios({
|
||||||
phone,
|
url: "http://localhost:4000/restaurant/category",
|
||||||
hidden,
|
method: "POST",
|
||||||
} = props.restaurant;
|
data: data,
|
||||||
|
headers: {
|
||||||
|
"x-auth-token": token,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.then((res) => {
|
||||||
|
dispatch(hideBackdrop());
|
||||||
|
dispatch(notification("Dodano kategorię.", "success"));
|
||||||
|
dispatch(refreshUserData(token));
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
dispatch(hideBackdrop());
|
||||||
|
dispatch(notification("Nie udało się dodać kategorii :(", "error"));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const filterDishes = (dishes, category) => {
|
||||||
|
var result = [];
|
||||||
|
dishes.map((dish) => {
|
||||||
|
if (dish.category === category) {
|
||||||
|
result.push(dish);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
const CategoriesList = categories.map((category) => {
|
const CategoriesList = categories.map((category) => {
|
||||||
return (
|
return (
|
||||||
@@ -59,6 +95,16 @@ export default function EditRestaurantMenu(props) {
|
|||||||
expandIcon={<ExpandMoreIcon className={classes.expandIcon} />}
|
expandIcon={<ExpandMoreIcon className={classes.expandIcon} />}
|
||||||
>
|
>
|
||||||
<h4>{category}</h4>
|
<h4>{category}</h4>
|
||||||
|
<div className="editRestaurant-categorySpan">
|
||||||
|
<h5>Dania: 0</h5>
|
||||||
|
<IconButton
|
||||||
|
color="primary"
|
||||||
|
aria-label="upload picture"
|
||||||
|
component="span"
|
||||||
|
>
|
||||||
|
<DeleteIcon />
|
||||||
|
</IconButton>
|
||||||
|
</div>
|
||||||
</AccordionSummary>
|
</AccordionSummary>
|
||||||
</Accordion>
|
</Accordion>
|
||||||
);
|
);
|
||||||
@@ -73,21 +119,26 @@ export default function EditRestaurantMenu(props) {
|
|||||||
{CategoriesList}
|
{CategoriesList}
|
||||||
<Accordion className={classes.root}>
|
<Accordion className={classes.root}>
|
||||||
<AccordionSummary
|
<AccordionSummary
|
||||||
expandIcon={<ExpandMoreIcon className={classes.expandIcon} />}
|
expandIcon={<AddIcon className={classes.expandIcon} />}
|
||||||
>
|
>
|
||||||
<h4>Dodaj kategorię</h4>
|
<h4>Dodaj kategorię</h4>
|
||||||
</AccordionSummary>
|
</AccordionSummary>
|
||||||
<TextField
|
<div className="editRestaurant-addCategory">
|
||||||
className={classes.textInputFullWidth}
|
<TextField
|
||||||
label="Nazwa kategorii"
|
className={classes.textInputFullWidth}
|
||||||
variant="outlined"
|
value={newCategory}
|
||||||
></TextField>
|
onChange={(event) => setNewCategory(event.target.value)}
|
||||||
<ButtonSecondary text="Dodaj" />
|
label="Nazwa kategorii"
|
||||||
|
variant="outlined"
|
||||||
|
></TextField>
|
||||||
|
<ButtonSecondary onClick={addCategory} text="Dodaj" />
|
||||||
|
</div>
|
||||||
</Accordion>
|
</Accordion>
|
||||||
<div className="editRestaurant-sectiontitle">
|
<div className="editRestaurant-sectiontitle">
|
||||||
<h4>Lunch menu</h4>
|
<h4>Lunch menu</h4>
|
||||||
<Divider />
|
<Divider />
|
||||||
</div>
|
</div>
|
||||||
|
<LunchMenu lunchMenu={lunchMenu} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
31
src/components/EditRestaurant/LunchMenu.js
Normal file
31
src/components/EditRestaurant/LunchMenu.js
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import React from "react";
|
||||||
|
import IconButton from "@material-ui/core/IconButton";
|
||||||
|
import DeleteIcon from "@material-ui/icons/Delete";
|
||||||
|
import List from "@material-ui/core/List";
|
||||||
|
import ListItem from "@material-ui/core/ListItem";
|
||||||
|
|
||||||
|
export default function LunchMenu(props) {
|
||||||
|
const { lunchMenu } = props;
|
||||||
|
const LunchDishes = () => {
|
||||||
|
if (lunchMenu.length > 0) {
|
||||||
|
lunchMenu.map((dish) => {
|
||||||
|
return (
|
||||||
|
<ListItem key={dish}>
|
||||||
|
Dish name
|
||||||
|
<IconButton
|
||||||
|
color="primary"
|
||||||
|
aria-label="upload picture"
|
||||||
|
component="span"
|
||||||
|
>
|
||||||
|
<DeleteIcon />
|
||||||
|
</IconButton>
|
||||||
|
</ListItem>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return <ListItem>Lunch menu puste</ListItem>;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return <List>{LunchDishes}</List>;
|
||||||
|
}
|
||||||
@@ -73,3 +73,21 @@
|
|||||||
margin: auto 6px auto 6px;
|
margin: auto 6px auto 6px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.editRestaurant-addCategory {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
padding-left: 8px;
|
||||||
|
padding-right: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.editRestaurant-categorySpan {
|
||||||
|
flex-grow: 10;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: flex-end;
|
||||||
|
h5 {
|
||||||
|
font-weight: 300;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -62,6 +62,7 @@
|
|||||||
|
|
||||||
.image-upload-container-wide {
|
.image-upload-container-wide {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: flex-end;
|
align-items: flex-end;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user