Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 

412 linhas
24 KiB

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