1 | import React from "react";
|
---|
2 | import { Form, Button, Container } from "react-bootstrap";
|
---|
3 | import { GiConfirmed } from "react-icons/gi"
|
---|
4 | import useCreateHotelRoom from "../Hooks/Hotel/useCreateHotelRoom.js";
|
---|
5 | import axios from "axios";
|
---|
6 | import useFormData from "../Hooks/useFormData";
|
---|
7 |
|
---|
8 |
|
---|
9 | const AddRoomForm = (props) => {
|
---|
10 | const { createHotelRoom } = useCreateHotelRoom(props.hotelId);
|
---|
11 | const edit = props.room
|
---|
12 | const dummy = {
|
---|
13 | hotelRoomDescription: "",
|
---|
14 | hotelRoomName: "",
|
---|
15 | numOfBeds: "",
|
---|
16 | price: "",
|
---|
17 | kitchenAvailable: false,
|
---|
18 | airConditioning: false,
|
---|
19 | balcony: false,
|
---|
20 | }
|
---|
21 |
|
---|
22 | console.log(edit)
|
---|
23 |
|
---|
24 | const { formData, onFormChange, onCheckBoxChange, setFormData } = useFormData(
|
---|
25 | // {
|
---|
26 | //
|
---|
27 | // hotelRoomDescription: "",
|
---|
28 | // hotelRoomName: "",
|
---|
29 | // numBeds: "",
|
---|
30 | // price: "",
|
---|
31 | // kitchenAvailable: false,
|
---|
32 | // airConditioning: false,
|
---|
33 | // balcony: false,
|
---|
34 | // }
|
---|
35 | edit ? props.room : dummy
|
---|
36 | );
|
---|
37 |
|
---|
38 | return (<>
|
---|
39 | <Container
|
---|
40 | className="rounded-5 m-5 my-auto mx-auto py-2 px-5"
|
---|
41 | style={{ backgroundColor: "#ffffff" }}
|
---|
42 | >
|
---|
43 | <Form>
|
---|
44 | <Form.Group className="mb-3" controlId="roomName">
|
---|
45 | <Form.Label>Име на соба</Form.Label>
|
---|
46 | <Form.Control
|
---|
47 | type="text"
|
---|
48 | placeholder="Внесете го името на собата"
|
---|
49 | value={formData.hotelRoomName}
|
---|
50 | name="hotelRoomName"
|
---|
51 | onChange={onFormChange}
|
---|
52 | />
|
---|
53 | </Form.Group>
|
---|
54 |
|
---|
55 | <Form.Group className="mb-3" controlId="numBeds">
|
---|
56 | <Form.Label>Број на кревети</Form.Label>
|
---|
57 | <Form.Control
|
---|
58 | type="number"
|
---|
59 | placeholder="Внесете го бројот на кревети"
|
---|
60 | value={formData.numOfBeds}
|
---|
61 | name="numOfBeds"
|
---|
62 | onChange={onFormChange}
|
---|
63 | />
|
---|
64 | </Form.Group>
|
---|
65 |
|
---|
66 | <Form.Group className="mb-3" controlId="roomDescription">
|
---|
67 | <Form.Label>Опис</Form.Label>
|
---|
68 | <Form.Control
|
---|
69 | as="textarea"
|
---|
70 | placeholder="Внесете опис на собата"
|
---|
71 | name="hotelRoomDescription"
|
---|
72 | value={formData.hotelRoomDescription}
|
---|
73 | onChange={onFormChange}
|
---|
74 | />
|
---|
75 | </Form.Group>
|
---|
76 |
|
---|
77 | <Form.Group className="mb-3" controlId="roomPrice">
|
---|
78 | <Form.Label>Цена од ноќ</Form.Label>
|
---|
79 | <Form.Control
|
---|
80 | type="number"
|
---|
81 | placeholder="Внесете ја цената од ноќ"
|
---|
82 | value={formData.price}
|
---|
83 | name="price"
|
---|
84 | onChange={onFormChange}
|
---|
85 | />
|
---|
86 | </Form.Group>
|
---|
87 |
|
---|
88 | <Form.Group className="mb-3" controlId="roomFilters">
|
---|
89 | <Form.Label>Филтри</Form.Label>
|
---|
90 | <Form.Check
|
---|
91 | type="checkbox"
|
---|
92 | label="Кујна"
|
---|
93 | name="kitchenAvailable"
|
---|
94 | checked={formData.kitchenAvailable}
|
---|
95 | onChange={onCheckBoxChange}
|
---|
96 | />
|
---|
97 | <Form.Check
|
---|
98 | type="checkbox"
|
---|
99 | label="Клима"
|
---|
100 | checked={formData.airConditioning}
|
---|
101 | name="airConditioning"
|
---|
102 | onChange={onCheckBoxChange}
|
---|
103 | />
|
---|
104 | <Form.Check
|
---|
105 | type="checkbox"
|
---|
106 | label="Тераса"
|
---|
107 | name="balcony"
|
---|
108 | checked={formData.balcony}
|
---|
109 | onChange={onCheckBoxChange}
|
---|
110 | />
|
---|
111 |
|
---|
112 | </Form.Group>
|
---|
113 |
|
---|
114 | <Form.Group className="my-1 justify-content-center">
|
---|
115 | <Button
|
---|
116 | type="submit"
|
---|
117 | style={{ backgroundColor: "#159895" }}
|
---|
118 | size="md"
|
---|
119 | onClick={(e) => {
|
---|
120 | e.preventDefault();
|
---|
121 | props.refresh((prev) => {
|
---|
122 | return ++prev;
|
---|
123 | })
|
---|
124 | createHotelRoom(formData);
|
---|
125 | props.closeModal();
|
---|
126 | }}
|
---|
127 | >
|
---|
128 | <span className="ikona my-1">
|
---|
129 | <GiConfirmed />
|
---|
130 | </span>
|
---|
131 | <span className="ikona mx-3">Поднеси апликација</span>
|
---|
132 | </Button>
|
---|
133 | </Form.Group>
|
---|
134 | </Form>
|
---|
135 | </Container>
|
---|
136 | </>)
|
---|
137 | }
|
---|
138 |
|
---|
139 | export default AddRoomForm; |
---|