web client v0.5
//notifications //delete restaurant //change picture //redesigned data store
This commit is contained in:
@@ -1,9 +1,77 @@
|
||||
import React from "react";
|
||||
import React, { useState } from "react";
|
||||
import ImageUpload from "../Input/ImageUpload";
|
||||
import ButtonSecondary from "../Input/ButtonSecondary";
|
||||
import ButtonPrimary from "../Input/ButtonPrimary";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { notification } from "../../actions";
|
||||
import { showBackdrop, hideBackdrop } from "../../actions/toggles.js";
|
||||
import axios from "axios";
|
||||
|
||||
export default function EditRestaurantPhoto(props) {
|
||||
const {
|
||||
imgUrl,
|
||||
dishes,
|
||||
categories,
|
||||
lunchMenu,
|
||||
name,
|
||||
city,
|
||||
adress,
|
||||
placesId,
|
||||
location,
|
||||
workingHours,
|
||||
description,
|
||||
tags,
|
||||
links,
|
||||
phone,
|
||||
hidden,
|
||||
} = props.restaurant;
|
||||
const [url, setUrl] = useState(imgUrl);
|
||||
const token = useSelector((state) => state.data.userData.jwt);
|
||||
const dispatch = useDispatch();
|
||||
const handleSave = () => {
|
||||
dispatch(showBackdrop());
|
||||
const data = {
|
||||
restaurantId: props.restaurant._id,
|
||||
dishes: dishes,
|
||||
categories: categories,
|
||||
lunchMenu: lunchMenu,
|
||||
name: name,
|
||||
city: city,
|
||||
adress: adress,
|
||||
coordinates: location.coordinates,
|
||||
placesId: placesId,
|
||||
imgUrl: url,
|
||||
workingHours: workingHours,
|
||||
description: description,
|
||||
tags: tags,
|
||||
links: links,
|
||||
phone: phone,
|
||||
hidden: hidden,
|
||||
};
|
||||
axios({
|
||||
url: "http://localhost:4000/restaurant",
|
||||
method: "PUT",
|
||||
data: data,
|
||||
headers: {
|
||||
"x-auth-token": token,
|
||||
},
|
||||
})
|
||||
.then((res) => {
|
||||
dispatch(hideBackdrop());
|
||||
dispatch(notification("Zmieniono zdjęcie.", "success"));
|
||||
})
|
||||
.catch((e) => {
|
||||
dispatch(hideBackdrop());
|
||||
dispatch(notification("Nie udało się zmienić zdjęcia :(", "error"));
|
||||
});
|
||||
};
|
||||
return (
|
||||
<div className="editRestaurant-tab">
|
||||
<p>Phottttto</p>
|
||||
<ImageUpload img={url} onUpload={(newUrl) => setUrl(newUrl)} />
|
||||
<div className="editRestaurant-bottom">
|
||||
<ButtonPrimary text="Anuluj" onClick={() => setUrl(imgUrl)} />
|
||||
<ButtonSecondary onClick={handleSave} text="Zapisz" />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user