* chore: refactor config files to prevent migration tool errors * refactor: upgrade with the tailwind migration tool * chore: restore pre-commit command + mc * refactor(wip): update dependencies and migrate to Tailwind CSS v4 (mainly web) * chore: resolve Tailwind v4 migration conflicts from merging main * chore: remove unused Tailwind packages from config and update dependencies for v4 migration * chore: uncomment Tailwind CSS utility classes in globals.css * fix: resolve token conflicts between calcom and coss ui * fix: textarea scrollbar * Fix CUI-16 * fix: added @tailwindcss/forms plugin and cleaned up CSS classes in various components to remove unnecessary dark mode styles * fix: selects and inputs of different sizes * fix: remove unnecessary leading-20 class from modal titles in various components * fix: update Checkbox component styles to remove unnecessary border on checked state * fix: clean up styles in RequiresConfirmationController, Checkbox, and Radio components to enhance consistency * fix: update button and filter component styles to remove unnecessary rounded classes for consistency * fix: calendar * fix: update KBarSearch * fix: refine styles in Empty and Checkbox components for improved consistency * Fix focus state email input * fix: update button hover and active states to use 'not-disabled' instead of 'enabled' * fix: line-height issues * fix: update class name for muted background in BookingListItem component * fix: sidebar spacing * chore: update class names to use new Tailwind CSS color utilities * fix embed * chore: upgrade Tailwind CSS to version 4.1.16 and update related dependencies * Map css variables and add a playground test for heavy css customization * suggestion for coss-ui * refactor: update CSS variable usage and clean up styles - Replace instances of `--cal-brand-color` with `--cal-brand` in embed-related HTML files. - Remove the now-unnecessary `addAppCssVars` function from the embed core. - Import theme tokens in the embed core styles for better consistency. - Clean up whitespace and formatting in CSS files for improved readability. - Add a comment in `tokens.css` regarding its usage in both embed and webapp contexts. * Handle within tokens.css instead of fixing coss-ui * Remove initial, not needed. Also, remove tailwind.config.js as tailwidn scans the html automaically * fix: examples app breaking * fix: modal not resizing correctly * feat: upgrade atoms to tailwind v4 * fix: atoms build breaking * fix: atoms build breaking * chore: upgrate examples/base to tailwind 4 * chore: update globals.css * fix: add missing scheduler css variables * fix: PlatformAdditionalCalendarSelector * chore: update global styles * chore: update tailwindcss and postcss dependencies to stable versions * chore: remove unneeded class * fix: dialog and toast animation * fix: replace flex-shrink-0 with shrink-0 for consistent styling in various components * fix: dialog modal for Apple connect * add margin in SaveFilterSegmentButton * Fix radix button nested states * add cursor pointer to buttons but keep dsabled state * Fix commandK selectors and adds cursor pointer * Fix teams filter * fix - round checkboxes * fix filter checkbox * fix select indicator's margin * command group font size * style: fix badge and tooltip radius * chore: remove unneeded files * Delete PR_REVIEW_MANAGED_EVENT_REASSIGNMENT.md * remove ui-playground leftover * fix: add missing react phone input styles in atoms * Delete managed-event-reassignment-flow-and-architecture.mermaid * fix: inter font not loading * Add theme to skeleton container so that it can support dark mode * fix: create custom stack-y-* utilities post tw4 upgrade * fix: typo * fix: atoms stack class + remove unused css file * fix default radius valiue * fix space-y in embed * fix skeleton background * Hardcode radius values to match production * fix border in embed * add missing externalThemeClass * feat: create a custom stack-y-* utility * fix: add stack utility to atom global css * fix: Skeleton loader class modalbox * Add stack-y utility in embed * fix: add missing stack utilities in atoms globals.css * update yarn.lock * add popover portla * update --------- Co-authored-by: Sean Brydon <[email protected]> Co-authored-by: Hariom Balhara <[email protected]> Co-authored-by: Ryukemeister <[email protected]> Co-authored-by: cal.com <[email protected]> Co-authored-by: Eunjae Lee <[email protected]> Co-authored-by: Anik Dhabal Babu <[email protected]>
249 lines
9.4 KiB
TypeScript
249 lines
9.4 KiB
TypeScript
import { useCallback, useMemo, useRef } from "react";
|
|
|
|
import dayjs from "@calcom/dayjs";
|
|
import { AvailableTimes, AvailableTimesSkeleton } from "@calcom/features/bookings";
|
|
import { useBookerStoreContext } from "@calcom/features/bookings/Booker/BookerStoreProvider";
|
|
import type { IUseBookingLoadingStates } from "@calcom/features/bookings/Booker/components/hooks/useBookings";
|
|
import type { BookerEvent } from "@calcom/features/bookings/types";
|
|
import type { Slot } from "@calcom/features/schedules/lib/use-schedule/types";
|
|
import { useNonEmptyScheduleDays } from "@calcom/features/schedules/lib/use-schedule/useNonEmptyScheduleDays";
|
|
import { useSlotsForAvailableDates } from "@calcom/features/schedules/lib/use-schedule/useSlotsForDate";
|
|
import { PUBLIC_INVALIDATE_AVAILABLE_SLOTS_ON_BOOKING_FORM } from "@calcom/lib/constants";
|
|
import { localStorage } from "@calcom/lib/webstorage";
|
|
import { BookerLayouts } from "@calcom/prisma/zod-utils";
|
|
import classNames from "@calcom/ui/classNames";
|
|
|
|
import { AvailableTimesHeader } from "../../components/AvailableTimesHeader";
|
|
import type { useScheduleForEventReturnType } from "../utils/event";
|
|
import { getQueryParam } from "../utils/query-param";
|
|
|
|
type AvailableTimeSlotsProps = {
|
|
extraDays?: number;
|
|
limitHeight?: boolean;
|
|
schedule?: useScheduleForEventReturnType;
|
|
isLoading: boolean;
|
|
seatsPerTimeSlot?: number | null;
|
|
showAvailableSeatsCount?: boolean | null;
|
|
event: {
|
|
data?: Pick<BookerEvent, "length" | "bookingFields" | "price" | "currency" | "metadata"> | null;
|
|
};
|
|
customClassNames?: {
|
|
availableTimeSlotsContainer?: string;
|
|
availableTimeSlotsTitle?: string;
|
|
availableTimeSlotsHeaderContainer?: string;
|
|
availableTimeSlotsTimeFormatToggle?: string;
|
|
availableTimes?: string;
|
|
};
|
|
confirmStepClassNames?: {
|
|
confirmButton?: string;
|
|
};
|
|
loadingStates: IUseBookingLoadingStates;
|
|
isVerificationCodeSending: boolean;
|
|
renderConfirmNotVerifyEmailButtonCond: boolean;
|
|
onSubmit: (timeSlot?: string) => void;
|
|
skipConfirmStep: boolean;
|
|
shouldRenderCaptcha?: boolean;
|
|
watchedCfToken?: string;
|
|
/**
|
|
* This is the list of time slots that are unavailable to book
|
|
*/
|
|
unavailableTimeSlots: string[];
|
|
confirmButtonDisabled?: boolean;
|
|
onAvailableTimeSlotSelect: (time: string) => void;
|
|
};
|
|
|
|
/**
|
|
* Renders available time slots for a given date.
|
|
* It will extract the date from the booker store.
|
|
* Next to that you can also pass in the `extraDays` prop, this
|
|
* will also fetch the next `extraDays` days and show multiple days
|
|
* in columns next to each other.
|
|
*/
|
|
|
|
export const AvailableTimeSlots = ({
|
|
extraDays,
|
|
limitHeight,
|
|
showAvailableSeatsCount,
|
|
schedule,
|
|
isLoading,
|
|
customClassNames,
|
|
skipConfirmStep,
|
|
seatsPerTimeSlot,
|
|
onSubmit,
|
|
unavailableTimeSlots,
|
|
confirmButtonDisabled,
|
|
confirmStepClassNames,
|
|
onAvailableTimeSlotSelect,
|
|
...props
|
|
}: AvailableTimeSlotsProps) => {
|
|
const selectedDate = useBookerStoreContext((state) => state.selectedDate);
|
|
|
|
const setSeatedEventData = useBookerStoreContext((state) => state.setSeatedEventData);
|
|
const date = selectedDate || dayjs().format("YYYY-MM-DD");
|
|
const [layout] = useBookerStoreContext((state) => [state.layout]);
|
|
const isColumnView = layout === BookerLayouts.COLUMN_VIEW;
|
|
const containerRef = useRef<HTMLDivElement | null>(null);
|
|
const { setTentativeSelectedTimeslots, tentativeSelectedTimeslots } = useBookerStoreContext((state) => ({
|
|
setTentativeSelectedTimeslots: state.setTentativeSelectedTimeslots,
|
|
tentativeSelectedTimeslots: state.tentativeSelectedTimeslots,
|
|
}));
|
|
|
|
const onTentativeTimeSelect = ({
|
|
time,
|
|
attendees: _attendees,
|
|
seatsPerTimeSlot: _seatsPerTimeSlot,
|
|
bookingUid: _bookingUid,
|
|
}: {
|
|
time: string;
|
|
attendees: number;
|
|
seatsPerTimeSlot?: number | null;
|
|
bookingUid?: string;
|
|
}) => {
|
|
// We don't intentionally invalidate schedule here because that could remove the slot itself that was clicked, causing a bad UX.
|
|
// We could start doing that after we fix this behaviour.
|
|
// schedule?.invalidate();
|
|
|
|
// Earlier we had multiple tentative slots, but now we can only have one tentative slot.
|
|
setTentativeSelectedTimeslots([time]);
|
|
};
|
|
|
|
const scheduleData = schedule?.data;
|
|
|
|
const nonEmptyScheduleDays = useNonEmptyScheduleDays(scheduleData?.slots);
|
|
const nonEmptyScheduleDaysFromSelectedDate = nonEmptyScheduleDays.filter(
|
|
(slot) => dayjs(selectedDate).diff(slot, "day") <= 0
|
|
);
|
|
|
|
// Creates an array of dates to fetch slots for.
|
|
// If `extraDays` is passed in, we will extend the array with the next `extraDays` days.
|
|
const dates = useMemo(() => {
|
|
if (!extraDays) return [date];
|
|
if (nonEmptyScheduleDaysFromSelectedDate.length > 0) {
|
|
return nonEmptyScheduleDaysFromSelectedDate.slice(0, extraDays);
|
|
}
|
|
return [];
|
|
}, [date, extraDays, nonEmptyScheduleDaysFromSelectedDate]);
|
|
|
|
const { slotsPerDay, toggleConfirmButton } = useSlotsForAvailableDates(dates, scheduleData?.slots);
|
|
|
|
const overlayCalendarToggled =
|
|
getQueryParam("overlayCalendar") === "true" || localStorage.getItem("overlayCalendarSwitchDefault");
|
|
|
|
const onTimeSelect = useCallback(
|
|
(time: string, attendees: number, seatsPerTimeSlot?: number | null, bookingUid?: string) => {
|
|
// Temporarily allow disabling it, till we are sure that it doesn't cause any significant load on the system
|
|
if (PUBLIC_INVALIDATE_AVAILABLE_SLOTS_ON_BOOKING_FORM) {
|
|
// Ensures that user has latest available slots when they are about to confirm the booking by filling up the details
|
|
schedule?.invalidate();
|
|
}
|
|
setTentativeSelectedTimeslots([]);
|
|
// note(Lauris): setting setSeatedEventData before setSelectedTimeslot so that in useSlots we have seated event data available
|
|
// and only then we invoke handleReserveSlot that is triggered by the changes in setSelectedTimeslot.
|
|
if (seatsPerTimeSlot) {
|
|
setSeatedEventData({
|
|
seatsPerTimeSlot,
|
|
attendees,
|
|
bookingUid,
|
|
showAvailableSeatsCount,
|
|
});
|
|
}
|
|
|
|
onAvailableTimeSlotSelect(time);
|
|
|
|
const isTimeSlotAvailable = !unavailableTimeSlots.includes(time);
|
|
if (skipConfirmStep && isTimeSlotAvailable) {
|
|
onSubmit(time);
|
|
}
|
|
return;
|
|
},
|
|
[
|
|
onSubmit,
|
|
setSeatedEventData,
|
|
skipConfirmStep,
|
|
showAvailableSeatsCount,
|
|
unavailableTimeSlots,
|
|
schedule,
|
|
setTentativeSelectedTimeslots,
|
|
onAvailableTimeSlotSelect,
|
|
]
|
|
);
|
|
|
|
const handleSlotClick = useCallback(
|
|
(selectedSlot: Slot, isOverlapping: boolean) => {
|
|
if ((overlayCalendarToggled && isOverlapping) || skipConfirmStep) {
|
|
toggleConfirmButton(selectedSlot);
|
|
} else {
|
|
onTimeSelect(
|
|
selectedSlot.time,
|
|
selectedSlot?.attendees || 0,
|
|
seatsPerTimeSlot,
|
|
selectedSlot.bookingUid
|
|
);
|
|
}
|
|
},
|
|
[overlayCalendarToggled, onTimeSelect, seatsPerTimeSlot, skipConfirmStep, toggleConfirmButton]
|
|
);
|
|
|
|
return (
|
|
<>
|
|
<div className={classNames(`flex`, `${customClassNames?.availableTimeSlotsContainer}`)}>
|
|
{isLoading ? (
|
|
<div className="mb-3 h-8" />
|
|
) : (
|
|
slotsPerDay.length > 0 &&
|
|
slotsPerDay.map((slots) => (
|
|
<AvailableTimesHeader
|
|
customClassNames={{
|
|
availableTimeSlotsHeaderContainer: customClassNames?.availableTimeSlotsHeaderContainer,
|
|
availableTimeSlotsTitle: customClassNames?.availableTimeSlotsTitle,
|
|
availableTimeSlotsTimeFormatToggle: customClassNames?.availableTimeSlotsTimeFormatToggle,
|
|
}}
|
|
key={slots.date}
|
|
date={dayjs(slots.date)}
|
|
showTimeFormatToggle={!isColumnView}
|
|
availableMonth={
|
|
dayjs(selectedDate).format("MM") !== dayjs(slots.date).format("MM")
|
|
? dayjs(slots.date).format("MMM")
|
|
: undefined
|
|
}
|
|
/>
|
|
))
|
|
)}
|
|
</div>
|
|
|
|
<div
|
|
ref={containerRef}
|
|
className={classNames(
|
|
limitHeight && "scroll-bar grow overflow-auto md:h-[400px]",
|
|
!limitHeight && "flex h-full w-full flex-row gap-4",
|
|
`${customClassNames?.availableTimeSlotsContainer}`
|
|
)}>
|
|
{isLoading && // Shows exact amount of days as skeleton.
|
|
Array.from({ length: 1 + (extraDays ?? 0) }).map((_, i) => <AvailableTimesSkeleton key={i} />)}
|
|
{!isLoading &&
|
|
slotsPerDay.length > 0 &&
|
|
slotsPerDay.map((slots) => (
|
|
<div key={slots.date} className="scroll-bar h-full w-full overflow-y-auto overflow-x-hidden!">
|
|
<AvailableTimes
|
|
className={customClassNames?.availableTimeSlotsContainer}
|
|
customClassNames={customClassNames?.availableTimes}
|
|
showTimeFormatToggle={!isColumnView}
|
|
onTimeSelect={onTimeSelect}
|
|
onTentativeTimeSelect={onTentativeTimeSelect}
|
|
unavailableTimeSlots={unavailableTimeSlots}
|
|
slots={slots.slots}
|
|
showAvailableSeatsCount={showAvailableSeatsCount}
|
|
skipConfirmStep={skipConfirmStep}
|
|
seatsPerTimeSlot={seatsPerTimeSlot}
|
|
handleSlotClick={handleSlotClick}
|
|
confirmButtonDisabled={confirmButtonDisabled}
|
|
confirmStepClassNames={confirmStepClassNames}
|
|
{...props}
|
|
/>
|
|
</div>
|
|
))}
|
|
</div>
|
|
</>
|
|
);
|
|
};
|