+
Please select your booked vehicle
+
+
+
+ {vehicles.map(({ Registration: regis, Model: model, Location_name: locationName }, index) => (
+
+
+
+
+
+
-
- )
- default:
- return (
-
-
-
-
-
-
-
-
- {Object.keys(vehicles).map((key, i) => (
-
- {key}:
- {vehicles[key]}
-
- ))}
-
-
-
+
-
- )
- }
- })()}
-
+
+
+
+
+ ))}
+
diff --git a/src/pages/vehicleedit.tsx b/src/pages/vehicleedit.tsx
new file mode 100644
index 0000000..346afc2
--- /dev/null
+++ b/src/pages/vehicleedit.tsx
@@ -0,0 +1,153 @@
+import React, { useState } from 'react'
+import router, { useRouter } from 'next/router'
+import DatePicker from 'react-datepicker'
+import axios from 'axios'
+
+import Navigation from '../components/navigation'
+import { Form, notification } from 'antd'
+
+import 'react-datepicker/dist/react-datepicker.css'
+import { ApiEndpoint } from '../constant/api'
+import { StorageKey } from '../constant/storage'
+import { BookingResponse } from '../types'
+import dayjs from 'dayjs'
+
+export default function VehicleEdit() {
+ const router = useRouter()
+ const [cost, setCost] = useState(-1)
+ const [endDate, setEndDate] = useState(null)
+ const { registration } = router.query
+ const [form] = Form.useForm()
+
+ async function onFormSubmit() {
+ try {
+ const email = localStorage.getItem(StorageKey.EMAIL)
+ if (!email) {
+ notification.error({
+ message: 'Invalid credential',
+ description: 'This user has no email',
+ placement: 'bottomRight',
+ })
+ await router.replace('/login')
+ return
+ }
+
+ const { data: bookingResData } = await axios.get
(`${ApiEndpoint.booking}?Customer_id=${email}`)
+ console.log('booking data', bookingResData)
+
+ const bookingData = bookingResData.Items.find((booking) => booking.Registration === registration)
+
+ const payload = {
+ ...bookingData,
+ Actual_end_time: dayjs(endDate).toISOString(),
+ }
+ console.log('Returning car with payload', payload)
+
+ const response = await axios.patch(`${ApiEndpoint.booking}/${bookingData.Booking_id}`, payload)
+ console.log('Returning car response', response)
+
+ const { Cost: _cost } = response.data
+ setCost(_cost)
+ } catch ({ message }) {
+ console.error('Error returning car', message)
+ notification.error({
+ message: 'Returning Failed',
+ description: message,
+ placement: 'bottomRight',
+ })
+ }
+ }
+
+ if (cost > 0) {
+ return (
+ <>
+
+
+
+ >
+ )
+ }
+
+ return (
+ <>
+
+
+
+
+
+
Please select your returning date
+
+
+
+
+ setEndDate(date)}
+ timeInputLabel="Time:"
+ dateFormat="dd/MM/yyyy HH:mm"
+ showTimeInput
+ minDate={new Date()}
+ />
+
+
+
+
+
+
+ >
+ )
+}
+
+type PaymentPromptProps = {
+ amount: number
+}
+function PaymentPrompt({ amount }: PaymentPromptProps) {
+ const { registration, model, location_name } = router.query
+
+ const onClickPay = async () => {
+ const vehiclePayload = {
+ Model: model,
+ Registration: registration,
+ Current_customer: '',
+ Location_name: location_name,
+ }
+
+ try {
+ console.log('Updating vehicle data', vehiclePayload)
+ await axios.patch(`${ApiEndpoint.vehicle}/${registration}`, vehiclePayload)
+
+ await router.replace('/main')
+ notification.success({
+ message: 'Payment Successful',
+ placement: 'bottomRight',
+ })
+ } catch ({ message }) {
+ console.error('Error sending vehicle info', message)
+ notification.error({
+ message: 'Payment Failed',
+ description: message,
+ placement: 'bottomRight',
+ })
+ }
+ }
+
+ return (
+
+
+
Your payment amount is {amount}
+
+
+
+
+
+
+ )
+}
diff --git a/src/pages/vehiclesedit.tsx b/src/pages/vehiclesedit.tsx
deleted file mode 100644
index e41ffbf..0000000
--- a/src/pages/vehiclesedit.tsx
+++ /dev/null
@@ -1,28 +0,0 @@
-import React, { useRef, useState } from 'react'
-import { Navbar, Nav} from 'react-bootstrap';
-
-export default function Returnpage({vehicles}) {
- return (
-
-
-
-
- CHS
-
-
-
-
-
-
-
-
Returning Vehicle page in progress.....
-
- );
-}
-
-
diff --git a/src/styles/returnpage.css b/src/styles/returnpage.css
index 097845e..1c5bc88 100644
--- a/src/styles/returnpage.css
+++ b/src/styles/returnpage.css
@@ -1,18 +1,7 @@
-.card {
- margin: 1rem;
- flex-basis: 45%;
- padding: 1.5rem;
- text-align: left;
- color: inherit;
- text-decoration: none;
- border: 1px solid #d8d6d6;
- border-radius: 10px;
- transition: color 0.15s ease, border-color 0.15s ease;
- }
-
- .card:hover,
- .card:focus,
- .card:active {
+
+ .clickable-card:hover,
+ .clickable-card:focus,
+ .clickable-card:active {
color: #212121;
border-color: #212121;
}
@@ -38,12 +27,6 @@
font-family: "Lato", sans-serif;
}
- .vehicle-return p {
- text-align:center;
- font-size: 1.0rem;
- font-family: "Lato", sans-serif;
- }
-
.image {
border-radius: 8px;
}
\ No newline at end of file