Add Restaurant almost done
This commit is contained in:
@@ -17,6 +17,8 @@ import InputAdornment from "@material-ui/core/InputAdornment";
|
||||
import ImageUpload from "../Input/ImageUpload";
|
||||
import validator from "validator";
|
||||
import { useHistory } from "react-router-dom";
|
||||
import InputGoogleMaps from "../Input/InputGoogleMaps";
|
||||
import InfoDialog from "../Output/InfoDialog";
|
||||
// ICONS
|
||||
import FastfoodIcon from "@material-ui/icons/Fastfood";
|
||||
import LocationCityIcon from "@material-ui/icons/LocationCity";
|
||||
@@ -89,6 +91,9 @@ export default function NewRestaurant() {
|
||||
name: "",
|
||||
city: "",
|
||||
adress: "",
|
||||
coordinates: [52.354293, 19.42377],
|
||||
placesId: "",
|
||||
imgURL: "",
|
||||
hoursFrom: "07:00",
|
||||
hoursTo: "23:00",
|
||||
description: "",
|
||||
@@ -102,6 +107,8 @@ export default function NewRestaurant() {
|
||||
adressError: false,
|
||||
descriptionError: false,
|
||||
charLeft: 400,
|
||||
open: true,
|
||||
response: "",
|
||||
};
|
||||
const steps = ["Informacje", "Zdjęcie", "Lokalizacja"];
|
||||
const [state, setState] = useState(initialState);
|
||||
@@ -120,14 +127,58 @@ export default function NewRestaurant() {
|
||||
|
||||
// HANDLERS
|
||||
|
||||
const handleNextButton = () => {
|
||||
if (activeStep === 0) {
|
||||
if (validateForm()) {
|
||||
setActiveStep(1);
|
||||
}
|
||||
const sendForm = () => {
|
||||
// format tags
|
||||
const formattedTags;
|
||||
const data = {
|
||||
name: state.name,
|
||||
city: state.city,
|
||||
adress: state.adress,
|
||||
coordinates: state.coordinates,
|
||||
placesId: state.placesId,
|
||||
imgURL: state.imgURL,
|
||||
workingHours: `${state.hoursFrom} - ${state.hoursTo}`,
|
||||
description: state.description,
|
||||
tags: formattedTags,
|
||||
links: {},
|
||||
phone: request.phone,
|
||||
hidden: request.hidden,
|
||||
}
|
||||
};
|
||||
|
||||
const setCoordinatesAndPlacesID = (coordinates, placesID) => {
|
||||
if (!placesID) {
|
||||
setState({ ...state, coordinates: coordinates });
|
||||
} else {
|
||||
setState({ ...state, coordinates: coordinates, placesId: placesID });
|
||||
}
|
||||
};
|
||||
|
||||
const handleNextButton = () => {
|
||||
switch (activeStep) {
|
||||
case 0:
|
||||
if (validateForm()) {
|
||||
setActiveStep(1);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (!validator.isEmpty(state.imgURL)) {
|
||||
setActiveStep(2);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
setState({ ...state, open: false });
|
||||
sendForm();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
const handleImageUploaded = (link) => {
|
||||
setState({ ...state, imgURL: link });
|
||||
};
|
||||
|
||||
const handleDescriptionChange = (event) => {
|
||||
let stringLength = event.target.value.length;
|
||||
let charleft = 400 - stringLength;
|
||||
@@ -168,9 +219,16 @@ export default function NewRestaurant() {
|
||||
|
||||
return (
|
||||
<div>
|
||||
{!state.open && (
|
||||
<InfoDialog
|
||||
title={"Dodawanie lokalu"}
|
||||
text={"Dodawanie lokalu, prosimy o chwilę cierpliwości..."}
|
||||
loading={true}
|
||||
/>
|
||||
)}
|
||||
<Dialog
|
||||
className={styles.root}
|
||||
open={true}
|
||||
open={state.open}
|
||||
aria-labelledby="newRestaurant-title"
|
||||
>
|
||||
<DialogTitle id="newRestaurant-title">Dodaj Lokal</DialogTitle>
|
||||
@@ -390,7 +448,20 @@ export default function NewRestaurant() {
|
||||
{activeStep === 1 && (
|
||||
<Paper>
|
||||
<h4>Dodaj zdjęcie lokalu.</h4>
|
||||
<ImageUpload />
|
||||
<ImageUpload
|
||||
img={state.imgURL}
|
||||
onUpload={(link) => handleImageUploaded(link)}
|
||||
/>
|
||||
</Paper>
|
||||
)}
|
||||
{activeStep === 2 && (
|
||||
<Paper>
|
||||
<InputGoogleMaps
|
||||
setCoordinates={(coordinates, placesID) =>
|
||||
setCoordinatesAndPlacesID(coordinates, placesID)
|
||||
}
|
||||
coordinates={state.coordinates}
|
||||
/>
|
||||
</Paper>
|
||||
)}
|
||||
{activeStep !== 0 && (
|
||||
|
||||
Reference in New Issue
Block a user