fixes
This commit is contained in:
@@ -184,3 +184,16 @@ export const tryRegister = (data) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const setTempData = (data) => {
|
||||||
|
return {
|
||||||
|
type: "SET_TEMP_DATA",
|
||||||
|
payload: data,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const clearTempData = () => {
|
||||||
|
return {
|
||||||
|
type: "CLEAR_TEMP_DATA",
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|||||||
@@ -87,14 +87,17 @@ export default function NewRestaurant() {
|
|||||||
name: "",
|
name: "",
|
||||||
city: "",
|
city: "",
|
||||||
adress: "",
|
adress: "",
|
||||||
hoursFrom: "",
|
hoursFrom: "07:00",
|
||||||
hoursTo: "",
|
hoursTo: "23:00",
|
||||||
description: "",
|
description: "",
|
||||||
tags: [],
|
tags: [],
|
||||||
phone: "",
|
phone: "",
|
||||||
facebook: "",
|
facebook: "",
|
||||||
twitter: "",
|
twitter: "",
|
||||||
www: "",
|
www: "",
|
||||||
|
nameError: false,
|
||||||
|
cityError: false,
|
||||||
|
adressError: false,
|
||||||
};
|
};
|
||||||
const steps = ["Informacje", "Zdjęcie", "Lokalizacja"];
|
const steps = ["Informacje", "Zdjęcie", "Lokalizacja"];
|
||||||
const [state, setState] = useState(initialState);
|
const [state, setState] = useState(initialState);
|
||||||
@@ -115,9 +118,10 @@ export default function NewRestaurant() {
|
|||||||
// HANDLERS
|
// HANDLERS
|
||||||
|
|
||||||
const handleNextButton = () => {
|
const handleNextButton = () => {
|
||||||
if (activeStep < 2) {
|
if (activeStep === 0) {
|
||||||
setActiveStep(activeStep + 1);
|
if (validateForm()) {
|
||||||
console.log(activeStep);
|
setActiveStep(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -126,6 +130,24 @@ export default function NewRestaurant() {
|
|||||||
console.log(activeStep);
|
console.log(activeStep);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const validateForm = () => {
|
||||||
|
const validation = {
|
||||||
|
nameValid: validator.isLength(state.name, { min: 1, max: 40 }),
|
||||||
|
cityValid: validator.isLength(state.city, { min: 1, max: 40 }),
|
||||||
|
adressValid: validator.isLength(state.name, { min: 1, max: 40 }),
|
||||||
|
};
|
||||||
|
setState({
|
||||||
|
...state,
|
||||||
|
nameError: !validation.nameValid,
|
||||||
|
cityError: !validation.cityValid,
|
||||||
|
adressError: !validation.adressValid,
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
validation.nameValid && validation.cityValid && validation.adressValid
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
// COMPONENTS
|
// COMPONENTS
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -160,9 +182,13 @@ export default function NewRestaurant() {
|
|||||||
className={styles.textInputFullWidth}
|
className={styles.textInputFullWidth}
|
||||||
fullWidth
|
fullWidth
|
||||||
required
|
required
|
||||||
|
error={state.nameError}
|
||||||
|
value={state.name}
|
||||||
label="Nazwa lokalu"
|
label="Nazwa lokalu"
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
onChange={(event) => (state.name = event.target.value)}
|
onChange={(event) =>
|
||||||
|
setState({ ...state, name: event.target.value })
|
||||||
|
}
|
||||||
InputProps={{
|
InputProps={{
|
||||||
startAdornment: (
|
startAdornment: (
|
||||||
<InputAdornment position="start">
|
<InputAdornment position="start">
|
||||||
@@ -177,8 +203,12 @@ export default function NewRestaurant() {
|
|||||||
className={styles.textInput}
|
className={styles.textInput}
|
||||||
required
|
required
|
||||||
label="Miasto"
|
label="Miasto"
|
||||||
|
error={state.cityError}
|
||||||
|
value={state.city}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
onChange={(event) => (state.city = event.target.value)}
|
onChange={(event) =>
|
||||||
|
setState({ ...state, city: event.target.value })
|
||||||
|
}
|
||||||
InputProps={{
|
InputProps={{
|
||||||
startAdornment: (
|
startAdornment: (
|
||||||
<InputAdornment position="start">
|
<InputAdornment position="start">
|
||||||
@@ -192,7 +222,11 @@ export default function NewRestaurant() {
|
|||||||
required
|
required
|
||||||
label="Adres"
|
label="Adres"
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
onChange={(event) => (state.adress = event.target.value)}
|
error={state.adressError}
|
||||||
|
value={state.adress}
|
||||||
|
onChange={(event) =>
|
||||||
|
setState({ ...state, adress: event.target.value })
|
||||||
|
}
|
||||||
InputProps={{
|
InputProps={{
|
||||||
startAdornment: (
|
startAdornment: (
|
||||||
<InputAdornment position="start">
|
<InputAdornment position="start">
|
||||||
@@ -204,9 +238,11 @@ export default function NewRestaurant() {
|
|||||||
<TextField
|
<TextField
|
||||||
label="Otwarcie"
|
label="Otwarcie"
|
||||||
type="time"
|
type="time"
|
||||||
defaultValue="07:00"
|
onChange={(event) =>
|
||||||
onChange={(event) => (state.hoursFrom = event.target.value)}
|
setState({ ...state, hoursFrom: event.target.value })
|
||||||
|
}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
|
value={state.hoursFrom}
|
||||||
className={styles.timePicker}
|
className={styles.timePicker}
|
||||||
InputLabelProps={{
|
InputLabelProps={{
|
||||||
shrink: true,
|
shrink: true,
|
||||||
@@ -218,9 +254,11 @@ export default function NewRestaurant() {
|
|||||||
<TextField
|
<TextField
|
||||||
label="Zamknięcie"
|
label="Zamknięcie"
|
||||||
type="time"
|
type="time"
|
||||||
defaultValue="22:00"
|
onChange={(event) =>
|
||||||
onChange={(event) => (state.hoursTo = event.target.value)}
|
setState({ ...state, hoursTo: event.target.value })
|
||||||
|
}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
|
value={state.hoursTo}
|
||||||
className={styles.timePicker}
|
className={styles.timePicker}
|
||||||
InputLabelProps={{
|
InputLabelProps={{
|
||||||
shrink: true,
|
shrink: true,
|
||||||
@@ -234,8 +272,9 @@ export default function NewRestaurant() {
|
|||||||
className={styles.textInputFullWidth}
|
className={styles.textInputFullWidth}
|
||||||
fullWidth
|
fullWidth
|
||||||
label="Opis"
|
label="Opis"
|
||||||
|
value={state.description}
|
||||||
onChange={(event) =>
|
onChange={(event) =>
|
||||||
(state.description = event.target.value)
|
setState({ ...state, description: event.target.value })
|
||||||
}
|
}
|
||||||
multiline
|
multiline
|
||||||
rows={3}
|
rows={3}
|
||||||
@@ -244,6 +283,7 @@ export default function NewRestaurant() {
|
|||||||
<Autocomplete
|
<Autocomplete
|
||||||
multiple
|
multiple
|
||||||
options={availableTags}
|
options={availableTags}
|
||||||
|
value={state.tags}
|
||||||
onChange={(event, values) =>
|
onChange={(event, values) =>
|
||||||
setState({ ...state, tags: values })
|
setState({ ...state, tags: values })
|
||||||
}
|
}
|
||||||
@@ -263,7 +303,10 @@ export default function NewRestaurant() {
|
|||||||
label="Telefon"
|
label="Telefon"
|
||||||
type="tel"
|
type="tel"
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
onChange={(event) => (state.phone = event.target.value)}
|
value={state.phone}
|
||||||
|
onChange={(event) =>
|
||||||
|
setState({ ...state, phone: event.target.value })
|
||||||
|
}
|
||||||
InputProps={{
|
InputProps={{
|
||||||
startAdornment: (
|
startAdornment: (
|
||||||
<InputAdornment position="start">
|
<InputAdornment position="start">
|
||||||
@@ -276,7 +319,10 @@ export default function NewRestaurant() {
|
|||||||
className={styles.textInput}
|
className={styles.textInput}
|
||||||
label="Facebook"
|
label="Facebook"
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
onChange={(event) => (state.facebook = event.target.value)}
|
value={state.facebook}
|
||||||
|
onChange={(event) =>
|
||||||
|
setState({ ...state, facebook: event.target.value })
|
||||||
|
}
|
||||||
InputProps={{
|
InputProps={{
|
||||||
startAdornment: (
|
startAdornment: (
|
||||||
<InputAdornment position="start">
|
<InputAdornment position="start">
|
||||||
@@ -289,7 +335,10 @@ export default function NewRestaurant() {
|
|||||||
className={styles.textInput}
|
className={styles.textInput}
|
||||||
label="Twitter"
|
label="Twitter"
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
onChange={(event) => (state.twitter = event.target.value)}
|
value={state.twitter}
|
||||||
|
onChange={(event) =>
|
||||||
|
setState({ ...state, twitter: event.target.value })
|
||||||
|
}
|
||||||
InputProps={{
|
InputProps={{
|
||||||
startAdornment: (
|
startAdornment: (
|
||||||
<InputAdornment position="start">
|
<InputAdornment position="start">
|
||||||
@@ -302,7 +351,10 @@ export default function NewRestaurant() {
|
|||||||
className={styles.textInput}
|
className={styles.textInput}
|
||||||
label="www"
|
label="www"
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
onChange={(event) => (state.www = event.target.value)}
|
value={state.www}
|
||||||
|
onChange={(event) =>
|
||||||
|
setState({ ...state, www: event.target.value })
|
||||||
|
}
|
||||||
InputProps={{
|
InputProps={{
|
||||||
startAdornment: (
|
startAdornment: (
|
||||||
<InputAdornment position="start">
|
<InputAdornment position="start">
|
||||||
@@ -316,6 +368,7 @@ export default function NewRestaurant() {
|
|||||||
)}
|
)}
|
||||||
{activeStep === 1 && (
|
{activeStep === 1 && (
|
||||||
<Paper>
|
<Paper>
|
||||||
|
<h4>Dodaj zdjęcie lokalu.</h4>
|
||||||
<ImageUpload />
|
<ImageUpload />
|
||||||
</Paper>
|
</Paper>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -1,31 +1,43 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
|
import axios from "axios";
|
||||||
|
|
||||||
export default function ImageUpload() {
|
export default function ImageUpload() {
|
||||||
const [file, setFile] = useState(null);
|
|
||||||
const [imagePreviewURL, setPreviewURL] = useState("");
|
const [imagePreviewURL, setPreviewURL] = useState("");
|
||||||
|
|
||||||
const handleInputChange = (event) => {
|
const handleInputChange = (event) => {
|
||||||
setFile(event.target.files[0]);
|
let data = new FormData();
|
||||||
let reader = new FileReader();
|
data.append("menuiImage", new Blob([event.target.files[0]]));
|
||||||
|
|
||||||
|
axios({
|
||||||
|
url: "http://localhost:4000/img",
|
||||||
|
method: "POST",
|
||||||
|
data: data,
|
||||||
|
headers: {
|
||||||
|
Accept: "application/json",
|
||||||
|
"Content-Type": "multipart/form-data",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
console.log(response);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.log(error);
|
||||||
|
});
|
||||||
|
|
||||||
|
let reader = new FileReader();
|
||||||
reader.onloadend = () => {
|
reader.onloadend = () => {
|
||||||
setPreviewURL(reader.result);
|
setPreviewURL(reader.result);
|
||||||
};
|
};
|
||||||
|
|
||||||
reader.readAsDataURL(event.target.files[0]);
|
reader.readAsDataURL(event.target.files[0]);
|
||||||
};
|
};
|
||||||
|
|
||||||
let imagePreview = <div className="image-preview">Proszę wybrać obraz.</div>;
|
let imagePreview = <div className="image-preview">Proszę wybrać obraz.</div>;
|
||||||
if (imagePreviewURL) {
|
if (imagePreviewURL) {
|
||||||
imagePreview = (
|
imagePreview = (
|
||||||
<div className="image-preview">
|
<div
|
||||||
<img
|
className="image-preview"
|
||||||
className="preview"
|
style={{ backgroundImage: `url(${imagePreviewURL})` }}
|
||||||
src={imagePreviewURL}
|
></div>
|
||||||
width="200"
|
|
||||||
alt="Obraz"
|
|
||||||
></img>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +51,7 @@ export default function ImageUpload() {
|
|||||||
className="input-image"
|
className="input-image"
|
||||||
onChange={handleInputChange}
|
onChange={handleInputChange}
|
||||||
></input>
|
></input>
|
||||||
<label for="file">Wybierz plik...</label>
|
<label htmlFor="file">Wybierz plik...</label>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ const initialState = {
|
|||||||
registerResult: "",
|
registerResult: "",
|
||||||
loginResult: "",
|
loginResult: "",
|
||||||
},
|
},
|
||||||
|
tempData: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
const data = (state = initialState, action) => {
|
const data = (state = initialState, action) => {
|
||||||
@@ -105,6 +106,10 @@ const data = (state = initialState, action) => {
|
|||||||
...state,
|
...state,
|
||||||
dialogs: { ...state.dialogs, newRestaurant: true },
|
dialogs: { ...state.dialogs, newRestaurant: true },
|
||||||
});
|
});
|
||||||
|
case "SET_TEMP_DATA":
|
||||||
|
return (state = { ...state, tempData: action.payload });
|
||||||
|
case "CLEAR_TEMP_DATA":
|
||||||
|
return (state = { ...state, tempData: {} });
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,10 +26,8 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
font-size: 0.8rem;
|
font-size: 0.8rem;
|
||||||
}
|
background-size: contain;
|
||||||
|
background-position: center;
|
||||||
.preview {
|
|
||||||
border-radius: 15px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.input-image {
|
.input-image {
|
||||||
|
|||||||
Reference in New Issue
Block a user