Updated team to also use getWorkingHours (#1188)
This commit is contained in:
parent
e0d1b6b5ea
commit
d6dd13a9d8
1 changed files with 7 additions and 20 deletions
|
@ -1,6 +1,7 @@
|
||||||
import { GetServerSidePropsContext } from "next";
|
import { GetServerSidePropsContext } from "next";
|
||||||
|
|
||||||
import { asStringOrNull } from "@lib/asStringOrNull";
|
import { asStringOrNull } from "@lib/asStringOrNull";
|
||||||
|
import { getWorkingHours } from "@lib/availability";
|
||||||
import prisma from "@lib/prisma";
|
import prisma from "@lib/prisma";
|
||||||
import { inferSSRProps } from "@lib/types/inferSSRProps";
|
import { inferSSRProps } from "@lib/types/inferSSRProps";
|
||||||
|
|
||||||
|
@ -74,26 +75,12 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
||||||
|
|
||||||
const [eventType] = team.eventTypes;
|
const [eventType] = team.eventTypes;
|
||||||
|
|
||||||
type Availability = typeof eventType["availability"];
|
const workingHours = getWorkingHours(
|
||||||
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],
|
timeZone: eventType.timeZone || undefined,
|
||||||
startTime: 0,
|
|
||||||
endTime: 1440,
|
|
||||||
},
|
},
|
||||||
].filter((availability): boolean => typeof availability["days"] !== "undefined");
|
eventType.availability
|
||||||
|
);
|
||||||
workingHours.sort((a, b) => a.startTime - b.startTime);
|
|
||||||
|
|
||||||
const eventTypeObject = Object.assign({}, eventType, {
|
const eventTypeObject = Object.assign({}, eventType, {
|
||||||
periodStartDate: eventType.periodStartDate?.toString() ?? null,
|
periodStartDate: eventType.periodStartDate?.toString() ?? null,
|
||||||
|
|
Loading…
Reference in a new issue