25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

372 lines
20 KiB

  1. import React, { useState } from 'react';
  2. import * as Icon from 'react-feather';
  3. import NumberFormat from 'react-number-format';
  4. //sweet alert
  5. import swal from 'sweetalert';
  6. const Checkout = function ({ backend, checkoutItem, ...props }) {
  7. // const [HargaFasilitas, setHargaFasilitas] = useState('');
  8. // const [NamaFasilitas, setNamaFasilitas] = useState('');
  9. const [formValue, setFormValue] = React.useState({
  10. namaPemesan: "",
  11. emailPemesan: "",
  12. teleponPemesan: "",
  13. pemesan: "",
  14. checkIn: "",
  15. checkOut: "",
  16. jumlahPengunjung: "",
  17. requestKamar: "",
  18. catatan: "",
  19. hargaKamar: "",
  20. namaKamar: "",
  21. ppnKamar: 0.1,
  22. hargaTotal: checkoutItem[0].hargaKamar + checkoutItem[0].hargaKamar * 0.1,
  23. });
  24. const disablePastDate = () => {
  25. const today = new Date();
  26. const dd = String(today.getDate() + 1).padStart(2, "0");
  27. const mm = String(today.getMonth() + 1).padStart(2, "0"); //January is 0!
  28. const yyyy = today.getFullYear();
  29. return yyyy + "-" + mm + "-" + dd;
  30. };
  31. const CheckoutKamar = checkoutItem.map((data) => {
  32. return (
  33. <div className="row">
  34. <div className="col-lg-4 col-md-6">
  35. <img style={{ borderRadius: "10px" }} src={`${backend}${data.imgKamar["url"]}`} height="120px" />
  36. </div>
  37. <div className="col-lg-8 col-md-6">
  38. <h3 className="title">Catania {data.namaKamar}</h3>
  39. <div className="row">
  40. <div className="col-lg-3 col-md-6">
  41. <p>Fasilitas : </p>
  42. </div>
  43. <div className="col-lg-4 col-md-6">
  44. <p><Icon.Wifi /> Free Wifi</p>
  45. </div>
  46. <div className="col-lg-4 col-md-6">
  47. <p><Icon.Phone /> Telepon</p>
  48. </div>
  49. </div>
  50. </div>
  51. </div>
  52. )
  53. })
  54. const CheckoutHarga = checkoutItem.map((data) => {
  55. return (
  56. <div className="order-table table-responsive">
  57. <table className="table table-bordered">
  58. <thead>
  59. <tr>
  60. <th scope="col">Jenis Kamar</th>
  61. <th scope="col">Total</th>
  62. </tr>
  63. </thead>
  64. <tbody>
  65. <tr>
  66. <td className="product-name">
  67. <span href="#">Catania {data.namaKamar}</span>
  68. </td>
  69. <td className="product-total">
  70. <span className="subtotal-amount"><NumberFormat value={data.hargaKamar} displayType={'text'} thousandSeparator={true} prefix={'Rp.'} /></span>
  71. </td>
  72. </tr>
  73. <tr>
  74. <td className="product-name">
  75. <span href="#">Pajak 10%</span>
  76. </td>
  77. <td className="product-total">
  78. <span type="disable" className="subtotal-amount"><NumberFormat value={data.hargaKamar + data.hargaKamar * 0.1} displayType={'text'} thousandSeparator={true} prefix={'Rp.'} /></span>
  79. </td>
  80. </tr>
  81. </tbody>
  82. </table>
  83. </div>
  84. )
  85. })
  86. return (
  87. <>
  88. <div className="checkout-area ptb-80">
  89. <div className="container">
  90. <div className="row">
  91. <div className="col-lg-12 col-md-12">
  92. <div className="user-actions" style={{ backgroundColor: "#eb1928" }}>
  93. <h4 style={{ color: 'white' }}><Icon.Edit style={{ color: 'white' }} width="50px" /> Important Notice</h4><br />
  94. <p style={{ color: 'white' }}>
  95. <b>As COVID-19 situation evolves, make sure the cancellation policy suits your needs.</b><br />
  96. In reference to the circular letter by the government regarding the spread control of Covid-19, please ensure that you are aware of your booking's refund, cancellation, and reschedule policy.
  97. </p>
  98. </div>
  99. </div>
  100. </div>
  101. <form
  102. onSubmit={async (e) => {
  103. e.preventDefault();
  104. var newformValue = {
  105. ...formValue,
  106. namaKamar: checkoutItem[0].namaKamar,
  107. hargaKamar: checkoutItem[0].hargaKamar,
  108. }
  109. setFormValue(newformValue)
  110. console.log(JSON.stringify(newformValue));
  111. const response = await fetch(
  112. "/api/Booking/CreateBooking",
  113. {
  114. method: "POST",
  115. headers: {
  116. 'Content-Type': 'application/json'
  117. },
  118. body: JSON.stringify(newformValue),
  119. }
  120. );
  121. console.log("response :", response);
  122. if (response.ok) {
  123. var res = await response.json();
  124. console.log("cek response :", res);
  125. if (res["STATUS"] === 1) {
  126. res["DATA"]["booking"];
  127. swal("Produk Berhasil Ditambah ke Keranjang", "Silahkan Cek Keranjang Belanja Anda", "success");
  128. router.push("/review");
  129. }
  130. else {
  131. swal("Produk Gagal Ditambah ke Keranjang", "Silahkan Coba Lagi", "error");
  132. }
  133. } else {
  134. swal("Transaksi Gagal", "Silahkan Coba Lagi", "error");
  135. }
  136. return false;
  137. }}
  138. >
  139. <div className="row">
  140. <div className="col-lg-6 col-md-6">
  141. <div className="billing-details">
  142. <h3 className="title">Masukan Informasi Pemesan</h3>
  143. <div className="row">
  144. <div className="col-lg-12 col-md-12">
  145. <div className="form-group">
  146. <label>Nama Lengkap <span className="required">*</span></label>
  147. <input
  148. name="namaPemesan"
  149. type="text"
  150. className="form-control"
  151. onInput={(e) => {
  152. setFormValue({
  153. ...formValue,
  154. namaPemesan: e.target.value.toString(),
  155. })
  156. }}
  157. />
  158. </div>
  159. </div>
  160. <div className="col-lg-6 col-md-6">
  161. <div className="form-group">
  162. <label>Alamat Email <span className="required">*</span></label>
  163. <input
  164. name="email"
  165. type="email"
  166. className="form-control"
  167. onInput={(e) => {
  168. setFormValue({
  169. ...formValue,
  170. emailPemesan: e.target.value.toString(),
  171. })
  172. }}
  173. />
  174. </div>
  175. </div>
  176. <div className="col-lg-6 col-md-6">
  177. <div className="form-group">
  178. <label>Masukan Ulang Alamat Email <span className="required">*</span></label>
  179. <input type="email" className="form-control" />
  180. </div>
  181. </div>
  182. <div className="col-lg-6 col-md-6">
  183. <div className="form-group">
  184. <label>Nomer Telepon <span className="required">*</span></label>
  185. <input
  186. name="teleponPemesan"
  187. type="text"
  188. className="form-control"
  189. onInput={(e) => {
  190. setFormValue({
  191. ...formValue,
  192. teleponPemesan: e.target.value.toString(),
  193. })
  194. }}
  195. />
  196. </div>
  197. </div>
  198. <div className="col-lg-6 col-md-6">
  199. <div className="form-group">
  200. <label>Saya Memesan Untuk ? <span className="required">*</span></label>
  201. <div className="select-box">
  202. <select
  203. name="pemesan"
  204. className="form-select"
  205. onInput={(e) => {
  206. setFormValue({
  207. ...formValue,
  208. pemesan: e.target.value.toString(),
  209. })
  210. }}
  211. >
  212. <option value="0">- Pilih Salah Satu -</option>
  213. <option value="Saya Sendiri">Saya Sendiri</option>
  214. <option value="Orang Lain">Orang Lain</option>
  215. </select>
  216. </div>
  217. </div>
  218. </div>
  219. </div>
  220. </div>
  221. </div>
  222. <div className="col-lg-6 col-md-6">
  223. <div className="billing-details">
  224. {CheckoutKamar}
  225. <br />
  226. <div className="row">
  227. <div className="col-lg-6 col-md-6">
  228. <div className="form-group">
  229. <label>Check In<span className="required">*</span></label>
  230. <input
  231. name="checkIn"
  232. type="date"
  233. min={disablePastDate()}
  234. className="form-control"
  235. onInput={(e) => {
  236. setFormValue({
  237. ...formValue,
  238. checkIn: e.target.value,
  239. })
  240. }}
  241. />
  242. </div>
  243. </div>
  244. <div className="col-lg-6 col-md-6">
  245. <div className="form-group">
  246. <label>Check Out <span className="required">*</span></label>
  247. <input
  248. data-date-format="DD MMMM YYYY"
  249. name="checkOut"
  250. type="date"
  251. min={disablePastDate()}
  252. className="form-control"
  253. onInput={(e) => {
  254. setFormValue({
  255. ...formValue,
  256. checkOut: e.target.value,
  257. })
  258. }}
  259. />
  260. </div>
  261. </div>
  262. <div className="col-lg-12 col-md-6">
  263. <div className="form-group">
  264. <label>Jumlah Pengunjung <span className="required">*</span></label>
  265. <div className="select-box">
  266. <select
  267. name="jumlahPengunjung"
  268. className="form-select"
  269. onInput={(e) => {
  270. setFormValue({
  271. ...formValue,
  272. jumlahPengunjung: e.target.value.toString(),
  273. })
  274. }}
  275. >
  276. <option value="0">- Pilih Salah Satu -</option>
  277. <option value="1">1 Orang</option>
  278. <option value="2">2 Orang</option>
  279. </select>
  280. </div>
  281. </div>
  282. </div>
  283. </div>
  284. </div>
  285. </div>
  286. <div className="col-lg-6 col-md-6" style={{ marginTop: "50px" }}>
  287. <div className="billing-details">
  288. <h3 className="title">Permintaan Khusus Untuk Kamar</h3>
  289. <div className="row">
  290. {checkoutItem[0]["fasilitas_kamars"].map((option) => (
  291. <div className="col-lg-4 col-md-4">
  292. <div className="form-check">
  293. <input
  294. name="requestKamar"
  295. type="checkbox"
  296. className="form-check-input"
  297. value={option.namaFasilitas}
  298. onInput={(e) => {
  299. setFormValue({
  300. ...formValue,
  301. requestKamar: e.target.value.toString(),
  302. })
  303. }}
  304. />
  305. <label className="form-check-label" value={option.namaFasilitas}>{option.namaFasilitas}</label>
  306. </div>
  307. </div>
  308. ))}
  309. <div className="col-lg-12 col-md-12">
  310. <div className="form-group">
  311. <textarea
  312. name="catatan"
  313. id="notes"
  314. cols="30"
  315. rows="4"
  316. placeholder="Catatan"
  317. className="form-control"
  318. onInput={(e) => {
  319. setFormValue({
  320. ...formValue,
  321. catatan: e.target.value.toString(),
  322. })
  323. }}
  324. ></textarea>
  325. </div>
  326. </div>
  327. </div>
  328. </div>
  329. </div>
  330. <div className="col-lg-6 col-md-6" style={{ marginTop: "50px" }}>
  331. <div className="order-details">
  332. <h3 className="title">Total Pesanan</h3>
  333. {CheckoutHarga}
  334. <button type="submit" className="btn btn-primary order-btn">Book</button>
  335. </div>
  336. </div>
  337. </div>
  338. </form>
  339. </div>
  340. </div>
  341. </>
  342. )
  343. }
  344. export default Checkout;