source: frontend/src/Components/Forms/AddHotelForm.js@ efaa053

Last change on this file since efaa053 was 07f4e8b, checked in by darsov2 <62809499+darsov2@…>, 10 months ago

prefinal fixes

  • Property mode set to 100644
File size: 4.2 KB
Line 
1import React from "react";
2import { useRef } from "react";
3import { Form, Button, Container } from "react-bootstrap";
4import { GiConfirmed } from "react-icons/gi";
5import useCreateHotel from "../Hooks/Hotel/useCreateHotel.js";
6import axios from "axios";
7import useFormData from "../Hooks/useFormData.js";
8
9const AddHotelForm = (props) => {
10 const { createHotel } = useCreateHotel();
11
12 console.log(props.hotel)
13
14 const dummy = {
15 hotelName: "",
16 hotelLocation: "",
17 petFriendly: false,
18 parking: false,
19 internetAvailable: false,
20 hotelDescripiton: "",
21 hotelEDBS: "",
22 }
23
24 const edit = props.hotel != null
25
26 console.log(edit)
27
28 const { formData, onFormChange, onCheckBoxChange, setFormData } = useFormData(edit ? props.hotel : dummy);
29
30
31 const { addHotel } = useCreateHotel();
32
33 return (
34 <>
35 <Container
36 className="rounded-5 m-5 my-auto mx-auto py-2 px-5"
37 style={{ backgroundColor: "#ffffff" }}
38 >
39 <Form>
40 <Form.Group className="mb-3" controlId="hotelName">
41 <Form.Label>Име на сместувањето</Form.Label>
42 <Form.Control
43 type="text"
44 name="hotelName"
45 placeholder="Внесете го името на сместувањето"
46 value={formData.hotelName}
47 onChange={onFormChange}
48 />
49 </Form.Group>
50
51 <Form.Group className="mb-3" controlId="hotelDescription">
52 <Form.Label>Опис</Form.Label>
53 <Form.Control
54 as="textarea"
55 name="hotelDescripiton"
56 placeholder="Внесете опис на сместувањето"
57 value={formData.hotelDescripiton}
58 onChange={onFormChange}
59 />
60 </Form.Group>
61
62 <Form.Group className="mb-3" controlId="hotelAddress">
63 <Form.Label>Локација</Form.Label>
64 <Form.Control
65 type="text"
66 name="hotelLocation"
67 placeholder="Внесете ја адресата на сместувањето"
68 value={formData.hotelLocation}
69 onChange={onFormChange}
70 />
71 </Form.Group>
72
73 <Form.Group className="mb-3" controlId="hotelFilters">
74 <Form.Label>Филтри</Form.Label>
75 <Form.Check
76 type="checkbox"
77 label="Паркинг"
78 name="parking"
79 value={formData.parking}
80 onChange={onCheckBoxChange}
81 />
82 <Form.Check
83 type="checkbox"
84 label="Pet friendly"
85 name="petFriendly"
86 value={formData.petFriendly}
87 onChange={onCheckBoxChange}
88 />
89 <Form.Check
90 type="checkbox"
91 name="internetAvailable"
92 label="Интернет"
93 value={formData.internetAvailable}
94 onChange={onCheckBoxChange}
95 />
96 </Form.Group>
97
98 <Form.Group className="mb-3" controlId="hotelPhone">
99 <Form.Label>Контакт телефон</Form.Label>
100 <Form.Control
101 type="text"
102 name="hotelEDBS"
103 placeholder="Внесете контакт телефон"
104 value={formData.hotelEDBS}
105 onChange={onFormChange}
106 />
107 </Form.Group>
108
109 <Form.Group className="my-1 justify-content-center">
110 <Button
111 type="submit"
112 style={{ backgroundColor: "#159895" }}
113 size="md"
114 onClick={(e) => {
115 e.preventDefault();
116 console.log(formData);
117 createHotel(formData, edit);
118 props.refresh((prevState) => {
119 return prevState + 1;
120 })
121 if(!edit)
122 props.closeModal()
123 }}
124 >
125 <span className="ikona my-1">
126 <GiConfirmed />
127 </span>
128 <span className="ikona mx-3">Поднеси апликација</span>
129 </Button>
130 </Form.Group>
131 </Form>
132 </Container>
133 </>
134 );
135};
136
137export default AddHotelForm;
Note: See TracBrowser for help on using the repository browser.