From 376b693d91ee52eeaba7a9c3c03ea1b30483bdcc Mon Sep 17 00:00:00 2001 From: Leo Giovanetti Date: Wed, 1 Feb 2023 19:19:37 -0300 Subject: [PATCH] Not allowing random duration (#6743) --- .../components/booking/pages/AvailabilityPage.tsx | 12 ++++++++++-- apps/web/components/booking/pages/BookingPage.tsx | 7 ++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/apps/web/components/booking/pages/AvailabilityPage.tsx b/apps/web/components/booking/pages/AvailabilityPage.tsx index 6ebf471179..08e7922710 100644 --- a/apps/web/components/booking/pages/AvailabilityPage.tsx +++ b/apps/web/components/booking/pages/AvailabilityPage.tsx @@ -27,6 +27,7 @@ import notEmpty from "@calcom/lib/notEmpty"; import { getRecurringFreq } from "@calcom/lib/recurringStrings"; import { collectPageParameters, telemetryEventTypes, useTelemetry } from "@calcom/lib/telemetry"; import { detectBrowserTimeFormat, setIs24hClockInLocalStorage, TimeFormat } from "@calcom/lib/timeFormat"; +import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils"; import { trpc } from "@calcom/trpc/react"; import { HeadSeo } from "@calcom/ui"; import { FiChevronDown, FiChevronUp, FiCreditCard, FiGlobe, FiRefreshCcw } from "@calcom/ui/components/icon"; @@ -98,7 +99,10 @@ const SlotPicker = ({ weekStart = 0, ethSignature, }: { - eventType: Pick; + eventType: Pick< + EventType & { metadata: z.infer }, + "id" | "schedulingType" | "slug" | "length" | "metadata" + >; timeFormat: TimeFormat; onTimeFormatChange: (is24Hour: boolean) => void; timeZone?: string; @@ -110,11 +114,15 @@ const SlotPicker = ({ }) => { const [selectedDate, setSelectedDate] = useState(); const [browsingDate, setBrowsingDate] = useState(); - const { duration } = useRouterQuery("duration"); + let { duration = eventType.length.toString() } = useRouterQuery("duration"); const { date, setQuery: setDate } = useRouterQuery("date"); const { month, setQuery: setMonth } = useRouterQuery("month"); const router = useRouter(); + if (!eventType.metadata?.multipleDuration) { + duration = eventType.length.toString(); + } + const [slotPickerRef] = useAutoAnimate(); useEffect(() => { diff --git a/apps/web/components/booking/pages/BookingPage.tsx b/apps/web/components/booking/pages/BookingPage.tsx index 17fbba2e8d..fcd30b24e9 100644 --- a/apps/web/components/booking/pages/BookingPage.tsx +++ b/apps/web/components/booking/pages/BookingPage.tsx @@ -125,7 +125,12 @@ const BookingPage = ({ const stripeAppData = getStripeAppData(eventType); // Define duration now that we support multiple duration eventTypes let duration = eventType.length; - if (queryDuration && !isNaN(Number(queryDuration))) { + if ( + queryDuration && + !isNaN(Number(queryDuration)) && + eventType.metadata?.multipleDuration && + eventType.metadata?.multipleDuration.includes(Number(queryDuration)) + ) { duration = Number(queryDuration); }