Feature/availability page revamp (#1032)

* Refactored Schedule component

* Merge branch 'main' into feature/availability-page-revamp

* wip

* Turned value into number, many other TS tweaks

* NodeJS 16x works 100% on my local, but out of scope for this already massive PR

* Fixed TS errors in viewer.tsx and schedule/index.ts

* Reverted next.config.js

* Fixed minor remnant from moving types to @lib/types

* schema comment

* some changes to form handling

* add comments

* Turned ConfigType into number; which seems to be the value preferred by tRPC

* Fixed localized time display during onboarding

* Update components/ui/form/Schedule.tsx

Co-authored-by: Alex Johansson <[email protected]>

* Added showToast to indicate save success

* Converted number to Date, and also always establish time based on current date

* prevent height flickering of availability

by removing mb-2 of input field

* availabilty: re-added mb-2 but added min-height

* Quite a few bugs discovered, but this seems functional

Co-authored-by: KATT <[email protected]>
Co-authored-by: Bailey Pumfleet <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: Peer Richelsen <[email protected]>
This commit is contained in:
authored and GitHub committed 2021-11-10 11:16:32 +00:00
1 parent 559ccb8ca7
commit 8664d217c9
23 files changed
+2550 -2028

No files matched your search

+22 -10
View File
@@ -1,12 +1,17 @@
// import { getBusyVideoTimes } from "@lib/videoClient";
import { Prisma } from "@prisma/client";
import dayjs from "dayjs";
import timezone from "dayjs/plugin/timezone";
import utc from "dayjs/plugin/utc";
import type { NextApiRequest, NextApiResponse } from "next";
import { asStringOrNull } from "@lib/asStringOrNull";
import { getBusyCalendarTimes } from "@lib/calendarClient";
import prisma from "@lib/prisma";
dayjs.extend(utc);
dayjs.extend(timezone);
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const user = asStringOrNull(req.query.user);
const dateFrom = dayjs(asStringOrNull(req.query.dateFrom));
@@ -71,19 +76,26 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
}));
const timeZone = eventType?.timeZone || currentUser.timeZone;
const defaultAvailability = {
startTime: currentUser.startTime,
endTime: currentUser.endTime,
days: [0, 1, 2, 3, 4, 5, 6],
};
const workingHours = eventType?.availability.length
? eventType.availability
: // currentUser.availability /* note(zomars) There's no UI nor default for this as of today */
[defaultAvailability]; /* note(zomars) For now, make every day available as fallback */
const workingHours = eventType?.availability.length ? eventType.availability : currentUser.availability;
// FIXME: Currently the organizer timezone is used for the logic
// refactor to be organizerTimezone unaware, use UTC instead.
res.status(200).json({
busy: bufferedBusyTimes,
timeZone,
workingHours,
workingHours: workingHours
// FIXME: Currently the organizer timezone is used for the logic
// refactor to be organizerTimezone unaware, use UTC instead.
.map((workingHour) => ({
days: workingHour.days,
startTime: dayjs(workingHour.startTime).tz(timeZone).toDate(),
endTime: dayjs(workingHour.endTime).tz(timeZone).toDate(),
}))
.map((workingHour) => ({
days: workingHour.days,
startTime: workingHour.startTime.getHours() * 60 + workingHour.startTime.getMinutes(),
endTime: workingHour.endTime.getHours() * 60 + workingHour.endTime.getMinutes(),
})),
});
}
+14 -16
View File
@@ -1,8 +1,9 @@
import { Availability, EventTypeCustomInput, MembershipRole, Prisma } from "@prisma/client";
import { EventTypeCustomInput, MembershipRole, Prisma } from "@prisma/client";
import type { NextApiRequest, NextApiResponse } from "next";
import { getSession } from "@lib/auth";
import prisma from "@lib/prisma";
import { OpeningHours } from "@lib/types/event-type";
function handleCustomInputs(customInputs: EventTypeCustomInput[], eventTypeId: number) {
if (!customInputs || !customInputs?.length) return undefined;
@@ -160,7 +161,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
}
if (req.body.availability) {
const openingHours = req.body.availability.openingHours || [];
const openingHours: OpeningHours[] = req.body.availability.openingHours || [];
// const overrides = req.body.availability.dateOverrides || [];
const eventTypeId = +req.body.id;
@@ -172,20 +173,17 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
});
}
Promise.all(
openingHours.map((schedule: Pick<Availability, "days" | "startTime" | "endTime">) =>
prisma.availability.create({
data: {
eventTypeId: +req.body.id,
days: schedule.days,
startTime: schedule.startTime,
endTime: schedule.endTime,
},
})
)
).catch((error) => {
console.log(error);
});
const availabilityToCreate = openingHours.map((openingHour) => ({
startTime: openingHour.startTime,
endTime: openingHour.endTime,
days: openingHour.days,
}));
data.availability = {
createMany: {
data: availabilityToCreate,
},
};
}
const eventType = await prisma.eventType.update({