Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 

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