diff --git a/lib/telemetry.ts b/lib/telemetry.ts index c1047c9e..432a79ae 100644 --- a/lib/telemetry.ts +++ b/lib/telemetry.ts @@ -9,7 +9,8 @@ export const telemetryEventTypes = { pageView: 'page_view', dateSelected: 'date_selected', timeSelected: 'time_selected', - bookingConfirmed: 'booking_confirmed' + bookingConfirmed: 'booking_confirmed', + bookingCancelled: 'booking_cancelled' } /** diff --git a/pages/cancel/[uid].tsx b/pages/cancel/[uid].tsx index 8235c8df..73efeafd 100644 --- a/pages/cancel/[uid].tsx +++ b/pages/cancel/[uid].tsx @@ -8,6 +8,7 @@ import isSameOrBefore from 'dayjs/plugin/isSameOrBefore'; import isBetween from 'dayjs/plugin/isBetween'; import utc from 'dayjs/plugin/utc'; import timezone from 'dayjs/plugin/timezone'; +import {collectPageParameters, telemetryEventTypes, useTelemetry} from "../../lib/telemetry"; dayjs.extend(isSameOrBefore); dayjs.extend(isBetween); @@ -21,8 +22,39 @@ function classNames(...classes) { export default function Type(props) { // Get router variables const router = useRouter(); + const { uid } = router.query; const [is24h, setIs24h] = useState(false); + const [loading, setLoading] = useState(false); + const [error, setError] = useState(null); + const telemetry = useTelemetry(); + + const cancellationHandler = async (event) => { + setLoading(true); + + let payload = { + uid: uid + }; + + telemetry.withJitsu(jitsu => jitsu.track(telemetryEventTypes.bookingCancelled, collectPageParameters())); + const res = await fetch( + '/api/cancel', + { + body: JSON.stringify(payload), + headers: { + 'Content-Type': 'application/json' + }, + method: 'POST' + } + ); + + if(res.status >= 200 && res.status < 300) { + router.push('/cancel/success'); + } else { + setLoading(false); + setError("An error with status code " + res.status + " occurred. Please try again later."); + } + } return (
@@ -43,7 +75,17 @@ export default function Type(props) {
-
+ {error &&
+
+ +
+
+ +
+
} + {!error &&
@@ -54,7 +96,7 @@ export default function Type(props) {

- You can also reschedule it with the button below. + Instead, you could also reschedule it.

@@ -69,14 +111,14 @@ export default function Type(props) {

-
+
}
- -