diff --git a/pages/booking/[uuid].js b/pages/booking/[uuid].js
index 5ed5023..87c2e6a 100644
--- a/pages/booking/[uuid].js
+++ b/pages/booking/[uuid].js
@@ -1,43 +1,96 @@
-import React, { useContext } from 'react'
+import React, { useEffect, useState } from 'react'
+import { getBookingByUUIDAsJSON } from '../../db/index'
+
+import Header from '../../components/header'
import Footer from '../../components/footer'
-// TODO: load booking somehow if we navigate to booking
-// TODO: when storing data take loaded booking instead of fromData
-// TODO: show state of booking and minimal data
+import { dateFormatFrontend } from '../../helpers/date'
-export default function Booking() {
- const { state, storeData } = useContext(WizardContext)
- const { dataStored, dataStoredLoaded } = state
+import { BOOKING_STATUS } from '../../db/bookingStatus'
+
+export async function getServerSideProps(context) {
+ const { uuid } = context.params
+ const booking = await getBookingByUUIDAsJSON(uuid)
+ // TODO: hack, not sure why _id is not serilizable
+ const bookingJSON = JSON.parse(JSON.stringify(booking))
+ return {
+ props: { booking: bookingJSON },
+ }
+}
+
+function getBookingStatus(booking) {
+ switch (booking.status) {
+ case BOOKING_STATUS.REQUESTED:
+ return 'In Anfrage'
+ case BOOKING_STATUS.CONFIRMED:
+ return 'Bestätigt'
+ case BOOKING_STATUS.REJECTED:
+ return 'Abgewiesen'
+ case BOOKING_STATUS.CANCELED:
+ return 'Storniert'
+ default:
+ return 'Unbekannt - bitte kontaktieren Sie uns!'
+ }
+}
+
+async function cancelBooking(booking) {
+ const response = await fetch(`/api/booking/${booking.uuid}`, {
+ method: 'PATCH',
+ mode: 'cors',
+ cache: 'no-cache',
+ credentials: 'same-origin',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ referrerPolicy: 'no-referrer',
+ body: JSON.stringify({ status: BOOKING_STATUS.CANCELED }),
+ })
+ return response.json()
+}
+
+export default function Booking({ booking: bookingProp }) {
+ const [booking, setBooking] = useState(bookingProp)
+
+ // in case the props change, update the internal state
+ useEffect(() => setBooking(bookingProp), [bookingProp])
+
+ const onCancelBooking = async () => {
+ if (!confirm('Soll die Buchung wirklich storniert werden?')) {
+ return
+ }
+ try {
+ const updatedBooking = await cancelBooking(booking)
+ setBooking(updatedBooking)
+ } catch (e) {
+ alert(
+ 'Die Buchung konnte nicht storniert werden. Kontaktieren Sie uns bitt per E-Mail!'
+ )
+ }
+ }
return (
+
- Pfadi Bussle Buchung
-
- Vielen Dank für die Buchung!
- Nach Prüfung bestätigen wir die Buchung bald per E-Mail!
- {!dataStoredLoaded && typeof dataStored !== 'boolean' && (
- <>
-
- Sollen die eingegebenen Daten in Deinem Browser{' '}
- für die nächste Buchung gespeichert werden?
-
-
diff --git a/styles/index.css b/styles/index.css
index 76b82d4..ab378f7 100644
--- a/styles/index.css
+++ b/styles/index.css
@@ -68,6 +68,14 @@
@apply bg-blue-700;
}
+.btn-red {
+ @apply bg-red-500 text-white;
+}
+
+.btn-red:hover {
+ @apply bg-red-700;
+}
+
.btn-gray {
@apply bg-gray-500 text-white;
}