diff --git a/src/App.js b/src/App.js
index 535630e..1c063e9 100644
--- a/src/App.js
+++ b/src/App.js
@@ -15,6 +15,9 @@ import NewRestaurant from "./components/Dialogs/NewRestaurant";
import RegisterDialog from "./components/Dialogs/RegisterDialog";
import ForgotPassword from "./components/Dialogs/ForgotPassword";
import ResetPassword from "./components/Dialogs/ResetPassword";
+import Contact from "./components/Output/Contact";
+import Settings from "./components/Dialogs/Settings";
+import EditRestaurant from "./components/Dialogs/EditRestaurant";
const theme = createMuiTheme({
palette: {
@@ -62,11 +65,18 @@ function App(props) {
+
+
+
}
/>
- } />
+ } />
+ }
+ />
diff --git a/src/Services.js b/src/Services.js
index d9ef5b4..7de2014 100644
--- a/src/Services.js
+++ b/src/Services.js
@@ -10,3 +10,26 @@ export function extractTags(tags) {
}
return results;
}
+
+function findInArray(array, string) {
+ const result = array.indexOf(string) > -1;
+ return result;
+}
+
+export function prepareTags(tags) {
+ let outTags = {
+ cardPayments: findInArray(tags, "Płatność kartą"),
+ petFriendly: findInArray(tags, "Lubimy zwierzaki"),
+ glutenFree: findInArray(tags, "Bezglutenowe"),
+ vegan: findInArray(tags, "Wegańskie"),
+ vegetarian: findInArray(tags, "Wegetariańskie"),
+ alcohol: findInArray(tags, "Podajemy alkohol"),
+ delivery: findInArray(tags, "Dowozimy"),
+ };
+ return outTags;
+}
+
+export const openInNewTab = (url) => {
+ const newWindow = window.open(url, "_blank", "noopener,noreferrer");
+ if (newWindow) newWindow.opener = null;
+};
diff --git a/src/actions/index.js b/src/actions/index.js
index 56f86a0..ea51be4 100644
--- a/src/actions/index.js
+++ b/src/actions/index.js
@@ -115,15 +115,22 @@ export const tryLogin = (username, password) => {
dispatch(
toggles.setLoggedIn(
response.data.firstname,
+ response.data.lastname,
jwt,
response.data.id,
- response.data.email
+ response.data.email,
+ response.data.NIP,
+ response.data.adress,
+ response.data.companyName,
+ response.data.restaurants
)
);
dispatch(push("/"));
})
.catch((err) => {
- if (err.response.status === 404) {
+ if (!err.response) {
+ console.log(err);
+ } else if (err.response.status === 404) {
dispatch(
toggles.setLoginResult(
"Użytkownik o podanym adresie email nie istnieje."
diff --git a/src/actions/toggles.js b/src/actions/toggles.js
index 2b66e2d..178dece 100644
--- a/src/actions/toggles.js
+++ b/src/actions/toggles.js
@@ -10,10 +10,30 @@ export const hideDishes = () => {
};
};
-export const setLoggedIn = (username, jwt, id, email) => {
+export const setLoggedIn = (
+ firstname,
+ lastname,
+ jwt,
+ userId,
+ email,
+ NIP,
+ adress,
+ companyName,
+ restaurants
+) => {
return {
type: "SET_LOGGEDIN",
- payload: { username: username, jwt: jwt, id: id, email: email },
+ payload: {
+ firstname: firstname,
+ lastname: lastname,
+ jwt: jwt,
+ userId: userId,
+ email: email,
+ NIP: NIP,
+ adress: adress,
+ companyName: companyName,
+ restaurants: restaurants,
+ },
};
};
diff --git a/src/components/Dialogs/EditRestaurant.js b/src/components/Dialogs/EditRestaurant.js
new file mode 100644
index 0000000..e3b84e0
--- /dev/null
+++ b/src/components/Dialogs/EditRestaurant.js
@@ -0,0 +1,50 @@
+import React from "react";
+import PictogramsSeparate from "../Output/PictogramsSeparate";
+import DishList from "../Output/DishList";
+import CircularProgress from "@material-ui/core/CircularProgress";
+import { extractTags } from "../../Services";
+import { useSelector } from "react-redux";
+
+export default function EditRestaurant(props) {
+ const restaurant = useSelector((state) => state.restaurant);
+ const showDishList = useSelector((state) => state.data.showDishList);
+
+ return (
+
+
+
+
+
{restaurant.name}
+
{restaurant.description}
+
+
+ Miejscowość:{" "}
+ {restaurant.city}
+
+
+ Godziny pracy:{" "}
+ {restaurant.workingHours}
+
+ {restaurant.phone && (
+
+ Kontakt:{" "}
+ {restaurant.phone}
+
+ )}
+
+
+
+
+
Menu
+ {showDishList === false && }
+ {showDishList === true && }
+
+
+
+ );
+}
diff --git a/src/components/Dialogs/NewRestaurant.js b/src/components/Dialogs/NewRestaurant.js
index a1ec7c1..469510a 100644
--- a/src/components/Dialogs/NewRestaurant.js
+++ b/src/components/Dialogs/NewRestaurant.js
@@ -19,12 +19,15 @@ import validator from "validator";
import { useHistory } from "react-router-dom";
import InputGoogleMaps from "../Input/InputGoogleMaps";
import InfoDialog from "../Output/InfoDialog";
+import { prepareTags } from "../../Services.js";
+import axios from "axios";
+import { useSelector } from "react-redux";
// ICONS
import FastfoodIcon from "@material-ui/icons/Fastfood";
import LocationCityIcon from "@material-ui/icons/LocationCity";
import PhoneIcon from "@material-ui/icons/Phone";
import FacebookIcon from "@material-ui/icons/Facebook";
-import TwitterIcon from "@material-ui/icons/Twitter";
+import InstagramIcon from "@material-ui/icons/Instagram";
import LanguageIcon from "@material-ui/icons/Language";
import ButtonPrimary from "../Input/ButtonPrimary";
@@ -100,18 +103,19 @@ export default function NewRestaurant() {
tags: [],
phone: "",
facebook: "",
- twitter: "",
+ instagram: "",
www: "",
nameError: false,
cityError: false,
adressError: false,
descriptionError: false,
charLeft: 400,
- open: true,
- response: "",
+ response: "Dodawanie lokalu, prosimy o chwilę cierpliwości...",
};
const steps = ["Informacje", "Zdjęcie", "Lokalizacja"];
const [state, setState] = useState(initialState);
+ const [open, setOpen] = useState(true);
+ const [loading, setLoading] = useState(true);
const [activeStep, setActiveStep] = React.useState(0);
const styles = useStyles();
const availableTags = [
@@ -124,26 +128,59 @@ export default function NewRestaurant() {
"Dowozimy",
];
const history = useHistory();
+ const token = useSelector((state) => state.data.jwt);
// HANDLERS
const sendForm = () => {
- // format tags
- const formattedTags;
+ const formattedTags = prepareTags(state.tags);
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,
- }
+ 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,
+ facebook: state.facebook,
+ instagram: state.instagram,
+ www: state.www,
+ phone: state.phone,
+ hidden: false,
+ };
+ setOpen(false);
+ axios({
+ url: "http://localhost:4000/restaurant",
+ method: "POST",
+ data: data,
+ headers: {
+ "x-auth-token": token,
+ },
+ })
+ .then((response) => {
+ setLoading(false);
+ setState({
+ ...state,
+ response:
+ "Lokal został dodany, aktywuj subskrypcję, aby był widoczny w wynikach wyszukiwania.",
+ });
+ setTimeout(() => {
+ history.push("/");
+ }, 5000);
+ })
+ .catch((error) => {
+ setLoading(false);
+ setState({
+ ...state,
+ response:
+ "Wystąpił nieoczekiwany błąd, przepraszamy za utrudnienia. Spróbuj ponownie za chwilę.",
+ });
+ setTimeout(() => {
+ history.push("/");
+ }, 5000);
+ });
};
const setCoordinatesAndPlacesID = (coordinates, placesID) => {
@@ -167,7 +204,6 @@ export default function NewRestaurant() {
}
break;
case 2:
- setState({ ...state, open: false });
sendForm();
break;
default:
@@ -219,16 +255,16 @@ export default function NewRestaurant() {
return (
- {!state.open && (
+ {!open && (
)}