Updated team to also use getWorkingHours (#1188)
parent
e0d1b6b5ea
commit
d6dd13a9d8
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue