From a4fb4cec69072d0ea25e4a1e85d887edfbd61aec Mon Sep 17 00:00:00 2001 From: yusmardianto Date: Fri, 3 Dec 2021 14:58:03 +0700 Subject: [PATCH] review page & midtrans payment --- api/Booking/booking.js | 43 ++++-- components/Booking/checkout.js | 36 ++++- components/Booking/review.js | 295 +++++++++++++++++++++++------------------ package.json | 4 +- pages/review.js | 76 ++++++++++- yarn.lock | 73 +++++++++- 6 files changed, 379 insertions(+), 148 deletions(-) diff --git a/api/Booking/booking.js b/api/Booking/booking.js index c159a25..13729ae 100644 --- a/api/Booking/booking.js +++ b/api/Booking/booking.js @@ -1,8 +1,8 @@ import apollo from "../../lib/apollo.js"; async function AddBooking(content, token = "") { - var res = await apollo.mutation( - ` + var res = await apollo.mutation( + ` mutation($input: BookingInput!) { createBooking(input: { data: $input }) { booking { @@ -12,13 +12,40 @@ async function AddBooking(content, token = "") { } `, token, - { - input: content, + { + input: content, + } + ); + return res; +} + +async function getReview(token = "") { + var res = await apollo.query( + ` + query { + bookings{ + id + namaPemesan + emailPemesan + teleponPemesan + pemesan + checkIn + checkOut + jumlahPengunjung + namaKamar + requestKamar + hargaKamar + ppnKamar + hargaTotal + catatan } - ); - return res; - } + }`, + token + ); + return res; +} module.exports = { - AddBooking: AddBooking, + AddBooking: AddBooking, + getReview: getReview, }; \ No newline at end of file diff --git a/components/Booking/checkout.js b/components/Booking/checkout.js index 57487ad..605d9c0 100644 --- a/components/Booking/checkout.js +++ b/components/Booking/checkout.js @@ -1,5 +1,6 @@ import React, { useState } from 'react'; import * as Icon from 'react-feather'; +import { useRouter } from 'next/router' import NumberFormat from 'react-number-format'; @@ -35,6 +36,17 @@ const Checkout = function ({ backend, checkoutItem, ...props }) { return yyyy + "-" + mm + "-" + dd; }; + const [TglCheckIn, setCheckIn] = useState(''); + const [TglCheckOut, setCheckOut] = useState(''); + + const date = (new Date(TglCheckIn)).getTime(); + const today = (new Date(TglCheckOut)).getTime(); + const msDay = 24 * 60 * 60 * 1000; // milliseconds per day + + const days = Math.floor((today - date) / msDay); + + const router = useRouter(); + const CheckoutKamar = checkoutItem.map((data) => { return (
@@ -77,7 +89,16 @@ const Checkout = function ({ backend, checkoutItem, ...props }) { - + + + + + + Total Hari + + + + {days} Hari @@ -86,7 +107,16 @@ const Checkout = function ({ backend, checkoutItem, ...props }) { - + + + + + + Total + + + + @@ -251,6 +281,7 @@ const Checkout = function ({ backend, checkoutItem, ...props }) { type="date" min={disablePastDate()} className="form-control" + onChange={e => setCheckIn(e.target.value)} onInput={(e) => { setFormValue({ ...formValue, @@ -270,6 +301,7 @@ const Checkout = function ({ backend, checkoutItem, ...props }) { type="date" min={disablePastDate()} className="form-control" + onChange={e => setCheckOut(e.target.value)} onInput={(e) => { setFormValue({ ...formValue, diff --git a/components/Booking/review.js b/components/Booking/review.js index f67bd1e..e5fc1f1 100644 --- a/components/Booking/review.js +++ b/components/Booking/review.js @@ -1,150 +1,183 @@ import React, { useState } from 'react'; import * as Icon from 'react-feather'; -const Checkout = () => { - return ( - <> -
-
-
-
-
-

Mohon Periksa Ulang Pesanan Anda


-
-
-
+import NumberFormat from 'react-number-format'; + +const Checkout = function ({ transactionToken, backend, review, ...props }) { + + console.log(transactionToken); + + const Checkin = review[0].checkIn; + const [Checkinyear, Checkinmonth, Checkinday] = Checkin.split('-') + + const Checkout = review[0].checkOut; + const [Checkoutnyear, Checkoutnmonth, Checkoutnday] = Checkout.split('-') + + const date = (new Date(review[0].checkIn)).getTime(); + const today = (new Date(review[0].checkOut)).getTime(); + const msDay = 24 * 60 * 60 * 1000; // milliseconds per day -
+ const days = Math.floor((today - date) / msDay); + + const ReviewContens = review.map((data) => { + return ( +
+
+
-
-
-
-
- -
-
-

Catania Double Room

-
-
-

Fasilitas :

-
-
-
-
-

Free Wifi

-
-
-

Telepon

-
-


-
-
-
Check In
-

25 Nov 2021

-

From 14:00

-
-
-
Check Out
-

25 Nov 2021

-

Before 14:00

-
-
-
Durasi Hari
-

1 Hari

-
-
-
Pengunjung
-

1 Orang

-
-
-
-

+
+ +
+
+

{data.namaKamar}

+
+
+

Fasilitas :

+
+
+
+
+

Free Wifi

+
+
+

Telepon

+
+


+
+
+
Check In
+

{`${Checkinday}/${Checkinmonth}/${Checkinyear}`}

+

Setelah 14:00

+
+
+
Check Out
+

{`${Checkoutnday}/${Checkoutnmonth}/${Checkoutnyear}`}

+

Sebelum 14:00

+
+
+
Durasi Hari
+

{days} Hari

+
+
+
Pengunjung
+

1 Orang

+
+

+
+
-
-
-

Informasi Pemesan

- -
-
-
-
-
Nama Pemesan : Yusmardianto
-
-
-
Nomer HP Pemesan : 087797315685
-
-
-
Alamat Email Pemesan : yusmardianto@thamrin.co.id
-
-
-
-
-
-
-
Pesan Khusus : Yusmardianto
-
-
-
-
-
-
+
+
+

Informasi Pemesan

+ +
+
+
+
+
Nama Pemesan : {data.namaPemesan}
+
+
+
Nomer HP Pemesan : {data.teleponPemesan}
+
+
+
Alamat Email Pemesan : {data.emailPemesan}
- -
-
-

Total Pesanan

- -
- - - - - - - - - - - - - - - - - - - - - - - - - -
Jenis KamarTotal
- Double Room - - Rp.180.000 -
- Extra Bed - - Rp.50.000 -
- Pajak 10% - - Rp.23.000 -
+
+
+
+
Pesan Khusus : {data.requestKamar}
+
+
+
Jumlah Pengunjung : {data.jumlahPengunjung} Orang
+
+
+
Catatan : {data.catatan} Orang
- - Bayar Pesanan
+
+
+
+
+
+

Total Pesanan

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
Jenis KamarTotal
+ Catania {data.namaKamar} + + +
+ Pajak 10% + + +
+ Total + + +
- + + +
+
+
+ ); + }) + + return ( + <> + +
+
+
+
+
+

Mohon Periksa Ulang Pesanan Anda


+
+
+
+ + {ReviewContens} +
diff --git a/package.json b/package.json index 13ebb78..495093d 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,8 @@ "dotenv": "^10.0.0", "graphql": "^16.0.1", "next": "^10.0.7", + "midtrans-client": "^1.2.3", + "midtrans-payment": "^1.2.7", "nodemailer": "^6.5.0", "nodemailer-sendgrid-transport": "^0.2.0", "react": "^17.0.1", @@ -44,4 +46,4 @@ "sweetalert2-react-content": "^3.3.1" }, "license": "MIT" -} +} \ No newline at end of file diff --git a/pages/review.js b/pages/review.js index 035dfb1..adfcff1 100644 --- a/pages/review.js +++ b/pages/review.js @@ -3,16 +3,86 @@ import Navbar from "@/components/_App/NavbarHome"; import Footer from "@/components/_App/Footer"; import ReviewContent from '@/components/Booking/review'; -const Checkout = () => { +import GetReviewItem from "api/Booking/booking"; + +const Checkout = function ({ transactionToken, backend, review, ...props }) { return ( <>

- +