From d6dd13a9d8cf7b23055a0e055eecc045b03e0319 Mon Sep 17 00:00:00 2001 From: Alex van Andel Date: Thu, 18 Nov 2021 10:20:48 +0000 Subject: [PATCH] Updated team to also use getWorkingHours (#1188) --- pages/team/[slug]/[type].tsx | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/pages/team/[slug]/[type].tsx b/pages/team/[slug]/[type].tsx index 797be274..8f9e8725 100644 --- a/pages/team/[slug]/[type].tsx +++ b/pages/team/[slug]/[type].tsx @@ -1,6 +1,7 @@ import { GetServerSidePropsContext } from "next"; import { asStringOrNull } from "@lib/asStringOrNull"; +import { getWorkingHours } from "@lib/availability"; import prisma from "@lib/prisma"; import { inferSSRProps } from "@lib/types/inferSSRProps"; @@ -74,26 +75,12 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) => const [eventType] = team.eventTypes; - type Availability = typeof eventType["availability"]; - const getWorkingHours = (availability: Availability) => - availability?.length - ? availability.map((schedule) => ({ - ...schedule, - startTime: schedule.startTime.getUTCHours() * 60 + schedule.startTime.getUTCMinutes(), - endTime: schedule.endTime.getUTCHours() * 60 + schedule.endTime.getUTCMinutes(), - })) - : null; - const workingHours = - getWorkingHours(eventType.availability) || - [ - { - days: [0, 1, 2, 3, 4, 5, 6], - startTime: 0, - endTime: 1440, - }, - ].filter((availability): boolean => typeof availability["days"] !== "undefined"); - - workingHours.sort((a, b) => a.startTime - b.startTime); + const workingHours = getWorkingHours( + { + timeZone: eventType.timeZone || undefined, + }, + eventType.availability + ); const eventTypeObject = Object.assign({}, eventType, { periodStartDate: eventType.periodStartDate?.toString() ?? null,