[e6c2521] | 1 | import React, { useEffect } from "react";
|
---|
| 2 | import { Form, Button, Container } from "react-bootstrap";
|
---|
| 3 | import { GiConfirmed } from "react-icons/gi";
|
---|
| 4 | import useCreateRestaurant from "../Hooks/Restaurant/useCreateRestaurant";
|
---|
| 5 | import useFormData from "../Hooks/useFormData";
|
---|
| 6 | import useGet from "../Hooks/useGet";
|
---|
| 7 |
|
---|
| 8 | const AddRestaurantForm = (props) => {
|
---|
| 9 |
|
---|
| 10 | const { createRestaurant } = useCreateRestaurant();
|
---|
| 11 | var dummy = {
|
---|
| 12 | restaurantName: "",
|
---|
| 13 | restaurantLocation: "",
|
---|
| 14 | cousineType: "",
|
---|
| 15 | restaurantDescription: "",
|
---|
| 16 | restaurantEdbs: "111",
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | const edit = props.restaurant != null
|
---|
| 20 |
|
---|
| 21 | const { formData, onFormChange, onCheckBoxChange, setFormData } = useFormData(edit ? props.restaurant : dummy);
|
---|
| 22 |
|
---|
| 23 | console.log(formData)
|
---|
| 24 |
|
---|
| 25 | return (
|
---|
| 26 | <>
|
---|
| 27 | <Container
|
---|
| 28 | className="rounded-5 m-5 my-auto mx-auto py-2 px-5"
|
---|
| 29 | style={{ backgroundColor: "#ffffff" }}
|
---|
| 30 | >
|
---|
| 31 | <Form>
|
---|
| 32 | <Form.Group className="mb-3" controlId="restaurantName">
|
---|
| 33 | <Form.Label>Име на ресторант</Form.Label>
|
---|
| 34 | <Form.Control
|
---|
| 35 | type="text"
|
---|
| 36 | name="restaurantName"
|
---|
| 37 | placeholder="Внесете го името на ресторантот"
|
---|
| 38 | value={formData.restaurantName}
|
---|
| 39 | onChange={onFormChange}
|
---|
| 40 | />
|
---|
| 41 | </Form.Group>
|
---|
| 42 |
|
---|
| 43 | <Form.Group className="mb-3" controlId="restaurantLocation">
|
---|
| 44 | <Form.Label>Локација на ресторант</Form.Label>
|
---|
| 45 | <Form.Control
|
---|
| 46 | type="text"
|
---|
| 47 | name="restaurantLocation"
|
---|
| 48 | placeholder="Внесете ја локацијата на ресторантот"
|
---|
| 49 | value={formData.restaurantLocation}
|
---|
| 50 | onChange={onFormChange}
|
---|
| 51 | />
|
---|
| 52 | </Form.Group>
|
---|
| 53 |
|
---|
| 54 | <Form.Group className="mb-3" controlId="restaurantDescription">
|
---|
| 55 | <Form.Label>Опис</Form.Label>
|
---|
| 56 | <Form.Control
|
---|
| 57 | as="textarea"
|
---|
| 58 | name="restaurantDescription"
|
---|
| 59 | placeholder="Внесете опис на ресторантот"
|
---|
| 60 | value={formData.restaurantDescription}
|
---|
| 61 | onChange={onFormChange}
|
---|
| 62 | />
|
---|
| 63 | </Form.Group>
|
---|
| 64 |
|
---|
| 65 | <Form.Group className="mb-3" controlId="restaurantCuisine">
|
---|
| 66 | <Form.Label>Тип кујна</Form.Label>
|
---|
| 67 | <Form.Control
|
---|
| 68 | type="text"
|
---|
| 69 | name="cousineType"
|
---|
| 70 | placeholder="Внесете го типот на кујна"
|
---|
| 71 | value={formData.cousineType}
|
---|
| 72 | onChange={onFormChange}
|
---|
| 73 | />
|
---|
| 74 | </Form.Group>
|
---|
| 75 |
|
---|
| 76 | <Form.Group className="my-1 justify-content-center">
|
---|
| 77 | <Button
|
---|
| 78 | type="submit"
|
---|
| 79 | style={{ backgroundColor: "#159895" }}
|
---|
| 80 | size="md"
|
---|
| 81 | onClick={(e) => {
|
---|
| 82 | e.preventDefault()
|
---|
| 83 | createRestaurant(formData, edit);
|
---|
[07f4e8b] | 84 | props.refresh(Math.random())
|
---|
| 85 | if(!edit) props.closeModal()
|
---|
[e6c2521] | 86 | }}
|
---|
| 87 | >
|
---|
| 88 | <span className="ikona my-1">
|
---|
| 89 | <GiConfirmed />
|
---|
| 90 | </span>
|
---|
| 91 | <span className="ikona mx-3">Поднеси апликација</span>
|
---|
| 92 | </Button>
|
---|
| 93 | </Form.Group>
|
---|
| 94 | </Form>
|
---|
| 95 | </Container>
|
---|
| 96 | </>
|
---|
| 97 | );
|
---|
| 98 | };
|
---|
| 99 |
|
---|
| 100 | export default AddRestaurantForm;
|
---|