From 1b099036f525b382a93c9bc3f0c4dbca65e0ad90 Mon Sep 17 00:00:00 2001 From: KATT Date: Mon, 8 Nov 2021 18:26:56 +0100 Subject: [PATCH] more fixes --- components/booking/DatePicker.tsx | 9 +++++---- components/booking/pages/AvailabilityPage.tsx | 10 +++++++++- lib/useRouterPathname.ts | 9 +++++++++ pages/_middleware.ts | 9 ++++++++- 4 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 lib/useRouterPathname.ts diff --git a/components/booking/DatePicker.tsx b/components/booking/DatePicker.tsx index c776867b89..6c2c33d22e 100644 --- a/components/booking/DatePicker.tsx +++ b/components/booking/DatePicker.tsx @@ -5,12 +5,12 @@ import dayjsBusinessTime from "dayjs-business-time"; import timezone from "dayjs/plugin/timezone"; import utc from "dayjs/plugin/utc"; import Link from "next/link"; -import { useRouter } from "next/router"; import { useEffect, useState } from "react"; import classNames from "@lib/classNames"; import { useLocale } from "@lib/hooks/useLocale"; import getSlots from "@lib/slots"; +import { useRouterPathname } from "@lib/useRouterPathname"; dayjs.extend(dayjsBusinessTime); dayjs.extend(utc); @@ -40,6 +40,7 @@ function DatePicker({ : date.month() : dayjs().month() /* High chance server is going to have the same month */ ); + const basePath = useRouterPathname(); useEffect(() => { if (dayjs().month() !== selectedMonth) { @@ -129,7 +130,6 @@ function DatePicker({ setDays(days); // eslint-disable-next-line react-hooks/exhaustive-deps }, [selectedMonth]); - const router = useRouter(); return (
) : ( + )}`} + scroll={false}> { telemetry.withJitsu((jitsu) => jitsu.track(telemetryEventTypes.pageView, collectPageParameters())); }, [telemetry]); + const basePath = useRouterPathname(); const changeDate = (newDate: Dayjs) => { telemetry.withJitsu((jitsu) => jitsu.track(telemetryEventTypes.dateSelected, collectPageParameters())); + router.replace( { query: { @@ -68,7 +71,12 @@ const AvailabilityPage = ({ profile, eventType, workingHours }: Props) => { date: newDate.format("YYYY-MM-DDZZ"), }, }, - undefined, + { + pathname: basePath, + query: { + date: newDate.format("YYYY-MM-DDZZ"), + }, + }, { shallow: true, } diff --git a/lib/useRouterPathname.ts b/lib/useRouterPathname.ts new file mode 100644 index 0000000000..89ed54509c --- /dev/null +++ b/lib/useRouterPathname.ts @@ -0,0 +1,9 @@ +import { useRouter } from "next/router"; +import { useMemo } from "react"; + +export function useRouterPathname() { + const router = useRouter(); + return useMemo(() => { + return router.asPath.split("?")[0] as string; + }, [router.asPath]); +} diff --git a/pages/_middleware.ts b/pages/_middleware.ts index b62236dcd1..bd16c7e279 100644 --- a/pages/_middleware.ts +++ b/pages/_middleware.ts @@ -26,6 +26,8 @@ const SKIP_PATHS = [ "team", ]; +const FIXME_LOCALES = ["en", "fr", "it", "ru", "es", "de", "pt", "ro", "nl", "pt-BR", "es-419", "ko", "ja"]; + export async function middleware(req: NextRequest) { const pathname = req.nextUrl.pathname; @@ -37,7 +39,12 @@ export async function middleware(req: NextRequest) { const isFileRequest = pathname.includes("."); - if (SKIP_PATHS.includes(firstPart) || isFileRequest || pathname === "/") { + if ( + SKIP_PATHS.includes(firstPart) || + isFileRequest || + pathname === "/" || + FIXME_LOCALES.includes(firstPart) + ) { return; }