* feat: Don't allow unavailable slot's booking form to be visible - Send back to slots listing * Improvements * feat: Add env variables and strategies to prevent booking failures - Added new environment variables for configuring slot reservation and availability checks - Implemented strategies to handle concurrent bookings and slot availability - Updated Booker component and related files to support new reservation and slot checking mechanisms - Added README with detailed explanation of booking prevention strategies - Configured dynamic intervals for slot and reservation queries * docs: Update Booker README with detailed slot reservation and availability explanation - Clarified slot reservation behavior when multiple users access the same booking page - Added details about `getSchedule` refetching strategies and timing - Explained how slot availability is detected and communicated to users * Support for skip confirmation form flow * feat: Enhance slot availability and reservation mechanism - Refactored slot availability checking to support multiple slots - Added tentative selected timeslots to improve booking UX - Updated trpc handler to check availability for multiple slots - Introduced new store methods for managing tentative slot selections - Improved slot reservation and availability status tracking * refactor: Improve slot availability quick check mechanism - Renamed and restructured slot availability check parameters - Extracted quick availability checks into a separate hook - Updated type definitions for slot status and availability checks - Simplified slot availability logic in Booker and related components - Maintained cached state for quick availability checks * Support minimu booking check too * change data-testid * Rneame * Fix race condition with uid cookie not set * fix tests * Remove unsded variable --------- Co-authored-by: Hariom Balhara <[email protected]> Co-authored-by: Udit Takkar <[email protected]>
124 lines
3.5 KiB
TypeScript
124 lines
3.5 KiB
TypeScript
import { shallow } from "zustand/shallow";
|
|
|
|
import { useSchedule } from "@calcom/features/schedules";
|
|
import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams";
|
|
import { trpc } from "@calcom/trpc/react";
|
|
|
|
import { useBookerTime } from "../components/hooks/useBookerTime";
|
|
import { useBookerStore } from "../store";
|
|
|
|
export type useEventReturnType = ReturnType<typeof useEvent>;
|
|
export type useScheduleForEventReturnType = ReturnType<typeof useScheduleForEvent>;
|
|
|
|
/**
|
|
* Wrapper hook around the trpc query that fetches
|
|
* the event currently viewed in the booker. It will get
|
|
* the current event slug and username from the booker store.
|
|
*
|
|
* Using this hook means you only need to use one hook, instead
|
|
* of combining multiple conditional hooks.
|
|
*/
|
|
export const useEvent = (props?: { fromRedirectOfNonOrgLink?: boolean }) => {
|
|
const [username, eventSlug, isTeamEvent, org] = useBookerStore(
|
|
(state) => [state.username, state.eventSlug, state.isTeamEvent, state.org],
|
|
shallow
|
|
);
|
|
|
|
const event = trpc.viewer.public.event.useQuery(
|
|
{
|
|
username: username ?? "",
|
|
eventSlug: eventSlug ?? "",
|
|
isTeamEvent,
|
|
org: org ?? null,
|
|
fromRedirectOfNonOrgLink: props?.fromRedirectOfNonOrgLink,
|
|
},
|
|
{
|
|
refetchOnWindowFocus: false,
|
|
enabled: Boolean(username) && Boolean(eventSlug),
|
|
}
|
|
);
|
|
|
|
return {
|
|
data: event?.data,
|
|
isSuccess: event?.isSuccess,
|
|
isError: event?.isError,
|
|
isPending: event?.isPending,
|
|
};
|
|
};
|
|
|
|
/**
|
|
* Gets schedule for the current event and current month.
|
|
* Gets all values right away and not the store because it increases network timing, only for the first render.
|
|
* We can read from the store if we want to get the latest values.
|
|
*
|
|
* Using this hook means you only need to use one hook, instead
|
|
* of combining multiple conditional hooks.
|
|
*
|
|
* The prefetchNextMonth argument can be used to prefetch two months at once,
|
|
* useful when the user is viewing dates near the end of the month,
|
|
* this way the multi day view will show data of both months.
|
|
*/
|
|
export const useScheduleForEvent = ({
|
|
prefetchNextMonth,
|
|
username,
|
|
eventSlug,
|
|
eventId,
|
|
month,
|
|
duration,
|
|
monthCount,
|
|
dayCount,
|
|
selectedDate,
|
|
orgSlug,
|
|
teamMemberEmail,
|
|
isTeamEvent,
|
|
}: {
|
|
prefetchNextMonth?: boolean;
|
|
username?: string | null;
|
|
eventSlug?: string | null;
|
|
eventId?: number | null;
|
|
month?: string | null;
|
|
duration?: number | null;
|
|
monthCount?: number;
|
|
dayCount?: number | null;
|
|
selectedDate?: string | null;
|
|
orgSlug?: string;
|
|
teamMemberEmail?: string | null;
|
|
fromRedirectOfNonOrgLink?: boolean;
|
|
isTeamEvent?: boolean;
|
|
} = {}) => {
|
|
const { timezone } = useBookerTime();
|
|
const [usernameFromStore, eventSlugFromStore, monthFromStore, durationFromStore] = useBookerStore(
|
|
(state) => [state.username, state.eventSlug, state.month, state.selectedDuration],
|
|
shallow
|
|
);
|
|
|
|
const searchParams = useCompatSearchParams();
|
|
const rescheduleUid = searchParams?.get("rescheduleUid");
|
|
|
|
const schedule = useSchedule({
|
|
username: usernameFromStore ?? username,
|
|
eventSlug: eventSlugFromStore ?? eventSlug,
|
|
eventId,
|
|
timezone,
|
|
selectedDate,
|
|
prefetchNextMonth,
|
|
monthCount,
|
|
dayCount,
|
|
rescheduleUid,
|
|
month: monthFromStore ?? month,
|
|
duration: durationFromStore ?? duration,
|
|
isTeamEvent,
|
|
orgSlug,
|
|
teamMemberEmail,
|
|
});
|
|
|
|
return {
|
|
data: schedule?.data,
|
|
isPending: schedule?.isPending,
|
|
isError: schedule?.isError,
|
|
isSuccess: schedule?.isSuccess,
|
|
isLoading: schedule?.isLoading,
|
|
invalidate: schedule?.invalidate,
|
|
};
|
|
};
|