From 8464e74c4371f806485440504ae18e7e037c2e22 Mon Sep 17 00:00:00 2001 From: Sean Brydon Date: Tue, 31 Oct 2023 10:09:11 +0000 Subject: [PATCH] Ensure header navigation works --- .../troubleshooter/components/LargeCalendar.tsx | 15 +++++++++------ packages/features/troubleshooter/store.ts | 8 ++++++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/packages/features/troubleshooter/components/LargeCalendar.tsx b/packages/features/troubleshooter/components/LargeCalendar.tsx index 8590a7dd1e..d8b5ea750d 100644 --- a/packages/features/troubleshooter/components/LargeCalendar.tsx +++ b/packages/features/troubleshooter/components/LargeCalendar.tsx @@ -16,13 +16,17 @@ export const LargeCalendar = ({ extraDays }: { extraDays: number }) => { const selectedDate = useTroubleshooterStore((state) => state.selectedDate); const event = useTroubleshooterStore((state) => state.event); const { data: session } = useSession(); - const date = selectedDate ? dayjs(selectedDate) : dayjs(); + const startDate = selectedDate ? dayjs(selectedDate) : dayjs(); const { data: busyEvents, isLoading } = trpc.viewer.availability.user.useQuery( { username: session?.user?.username || "", - dateFrom: date.startOf("day").utc().format(), - dateTo: date.endOf("day").utc().format(), + dateFrom: startDate.startOf("day").utc().format(), + dateTo: startDate + .endOf("day") + .add(extraDays - 1, "day") + .utc() + .format(), withSource: true, }, { @@ -35,10 +39,9 @@ export const LargeCalendar = ({ extraDays }: { extraDays: number }) => { eventSlug: event?.slug, eventId: event?.id, timezone, - month: date.format("YYYY-MM"), + month: startDate.format("YYYY-MM"), }); - const startDate = selectedDate ? dayjs(selectedDate).toDate() : dayjs().toDate(); const endDate = dayjs(startDate) .add(extraDays - 1, "day") .toDate(); @@ -102,7 +105,7 @@ export const LargeCalendar = ({ extraDays }: { extraDays: number }) => { endHour={23} events={events} availableTimeslots={availableSlots} - startDate={startDate} + startDate={startDate.toDate()} endDate={endDate} gridCellsPerHour={60 / 15} hoverEventDuration={30} diff --git a/packages/features/troubleshooter/store.ts b/packages/features/troubleshooter/store.ts index cd04cc043d..bf24b6457c 100644 --- a/packages/features/troubleshooter/store.ts +++ b/packages/features/troubleshooter/store.ts @@ -58,7 +58,8 @@ export const useTroubleshooterStore = create((set, get) => } }, addToSelectedDate: (days: number) => { - const currentSelection = dayjs(get().selectedDate); + const selectedDate = get().selectedDate; + const currentSelection = selectedDate ? dayjs(get().selectedDate) : dayjs(); const newSelection = currentSelection.add(days, "day"); const newSelectionFormatted = newSelection.format("YYYY-MM-DD"); @@ -82,7 +83,10 @@ export const useTroubleshooterStore = create((set, get) => get().setSelectedDate(null); }, initialize: ({ month }: StoreInitializeType) => { - if (month) set({ month }); + if (month) { + set({ month }); + updateQueryParam("month", month); + } //removeQueryParam("layout"); }, }));