From 74671263bf60fd6bbac2d8015932c067efda3b95 Mon Sep 17 00:00:00 2001 From: Alex van Andel Date: Fri, 16 Jun 2023 18:08:58 +0200 Subject: [PATCH] fix: New booker selected date issues (#9570) * Pick correct selected date * Commented out unused booking page revalidation * Fixed selected default bookerLayout not being applied * Use the right weekdayOfFirst - date(1) of browsingDate --- packages/features/bookings/Booker/store.ts | 5 ++--- packages/features/calendars/DatePicker.tsx | 2 +- packages/features/calendars/weeklyview/state/store.ts | 4 ++-- packages/features/eventtypes/lib/getPublicEvent.ts | 9 +++++---- .../routers/loggedInViewer/updateProfile.handler.ts | 10 ++++++---- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/packages/features/bookings/Booker/store.ts b/packages/features/bookings/Booker/store.ts index e595add8ba..1d83f475f6 100644 --- a/packages/features/bookings/Booker/store.ts +++ b/packages/features/bookings/Booker/store.ts @@ -167,9 +167,8 @@ export const useBookerStore = create((set, get) => ({ layout: layout || BookerLayouts.MONTH_VIEW, // Preselect today's date in week / column view, since they use this to show the week title. selectedDate: - selectedDateInStore || ["week_view", "column_view"].includes(layout) - ? dayjs().format("YYYY-MM-DD") - : null, + selectedDateInStore || + (["week_view", "column_view"].includes(layout) ? dayjs().format("YYYY-MM-DD") : null), }); // Unset selected timeslot if user is rescheduling. This could happen diff --git a/packages/features/calendars/DatePicker.tsx b/packages/features/calendars/DatePicker.tsx index 22b8c0b928..2eb267b51a 100644 --- a/packages/features/calendars/DatePicker.tsx +++ b/packages/features/calendars/DatePicker.tsx @@ -109,7 +109,7 @@ const Days = ({ nextMonthButton: () => void; }) => { // Create placeholder elements for empty days in first week - const weekdayOfFirst = browsingDate.day(); + const weekdayOfFirst = browsingDate.date(1).day(); const currentDate = minDate.utcOffset(browsingDate.utcOffset()); const availableDates = (includedDates: string[] | undefined) => { const dates = []; diff --git a/packages/features/calendars/weeklyview/state/store.ts b/packages/features/calendars/weeklyview/state/store.ts index 09315f6d2f..9424eec9b8 100644 --- a/packages/features/calendars/weeklyview/state/store.ts +++ b/packages/features/calendars/weeklyview/state/store.ts @@ -1,8 +1,8 @@ -import create from "zustand"; +import { create } from "zustand"; import dayjs from "@calcom/dayjs"; -import { +import type { CalendarComponentProps, CalendarPublicActions, CalendarState, diff --git a/packages/features/eventtypes/lib/getPublicEvent.ts b/packages/features/eventtypes/lib/getPublicEvent.ts index 415e618c62..94b95208bd 100644 --- a/packages/features/eventtypes/lib/getPublicEvent.ts +++ b/packages/features/eventtypes/lib/getPublicEvent.ts @@ -16,7 +16,7 @@ import { EventTypeMetaDataSchema, customInputSchema, userMetadata as userMetadataSchema, - bookerLayouts, + bookerLayouts as bookerLayoutsSchema, BookerLayouts, } from "@calcom/prisma/zod-utils"; @@ -69,6 +69,7 @@ const publicEventSelect = Prisma.validator()({ username: true, name: true, theme: true, + metadata: true, }, }, hidden: true, @@ -132,7 +133,7 @@ export const getPublicEvent = async (username: string, eventSlug: string, prisma brandColor: users[0].brandColor, darkBrandColor: users[0].darkBrandColor, theme: null, - bookerLayouts: bookerLayouts.parse( + bookerLayouts: bookerLayoutsSchema.parse( firstUsersMetadata?.defaultBookerLayouts || defaultEventBookerLayouts ), }, @@ -167,7 +168,7 @@ export const getPublicEvent = async (username: string, eventSlug: string, prisma return { ...event, - bookerLayouts: bookerLayouts.parse(eventMetaData?.bookerLayouts || null), + bookerLayouts: bookerLayoutsSchema.parse(eventMetaData?.bookerLayouts || null), description: markdownToSafeHTML(event.description), metadata: eventMetaData, customInputs: customInputSchema.array().parse(event.customInputs || []), @@ -220,7 +221,7 @@ function getProfileFromEvent(event: Event) { brandColor: profile.brandColor, darkBrandColor: profile.darkBrandColor, theme: profile.theme, - bookerLayouts: bookerLayouts.parse( + bookerLayouts: bookerLayoutsSchema.parse( eventMetaData?.bookerLayouts || (userMetaData && "defaultBookerLayouts" in userMetaData ? userMetaData.defaultBookerLayouts : null) ), diff --git a/packages/trpc/server/routers/loggedInViewer/updateProfile.handler.ts b/packages/trpc/server/routers/loggedInViewer/updateProfile.handler.ts index 7e19f82ec6..0207f44c42 100644 --- a/packages/trpc/server/routers/loggedInViewer/updateProfile.handler.ts +++ b/packages/trpc/server/routers/loggedInViewer/updateProfile.handler.ts @@ -129,13 +129,13 @@ export const updateProfileHandler = async ({ ctx, input }: UpdateProfileOptions) }); } // Revalidate booking pages - const res = ctx.res as NextApiResponse; + // Disabled because the booking pages are currently not using getStaticProps + /*const res = ctx.res as NextApiResponse; if (typeof res?.revalidate !== "undefined") { const eventTypes = await prisma.eventType.findMany({ where: { userId: user.id, team: null, - hidden: false, }, select: { id: true, @@ -143,9 +143,11 @@ export const updateProfileHandler = async ({ ctx, input }: UpdateProfileOptions) }, }); // waiting for this isn't needed - Promise.all(eventTypes.map((eventType) => res?.revalidate(`/${ctx.user.username}/${eventType.slug}`))) + Promise.all( + eventTypes.map((eventType) => res?.revalidate(`/new-booker/${ctx.user.username}/${eventType.slug}`)) + ) .then(() => console.info("Booking pages revalidated")) .catch((e) => console.error(e)); - } + }*/ return input; };