feat: Troubleshooter atom (#27497)

This commit is contained in:
Rajiv Sahal authored and GitHub committed 2026-02-06 17:34:58 +02:00
1 parent a71d62dc33
commit 8a17ebc2ef
31 files changed
+821 -305

No files matched your search

@@ -0,0 +1,39 @@
import { useQuery } from "@tanstack/react-query";
import { SUCCESS_STATUS } from "@calcom/platform-constants";
import type { ApiResponse, ApiSuccessResponse } from "@calcom/platform-types";
import http from "../lib/http";
import { useAtomsContext } from "./useAtomsContext";
type EventTypeWithTeam = {
id: number;
team: { id: number; name: string } | null;
title: string;
slug: string;
length: number;
username: string | null;
};
type ListWithTeamData = EventTypeWithTeam[];
export const QUERY_KEY = "get-event-types-list-with-team";
export const useEventTypesList = (props: { enabled?: boolean }) => {
const { isInit } = useAtomsContext();
const eventTypes = useQuery({
queryKey: [QUERY_KEY],
queryFn: () => {
return http.get<ApiResponse<ListWithTeamData>>("/atoms/event-types/list-with-team").then((res) => {
if (res.data.status === SUCCESS_STATUS) {
return (res.data as ApiSuccessResponse<ListWithTeamData>)?.data;
}
throw new Error(res.data.error.message);
});
},
enabled: props?.enabled !== undefined ? props.enabled && isInit : isInit,
staleTime: 5000,
});
return eventTypes;
};
@@ -0,0 +1,40 @@
import { useQuery } from "@tanstack/react-query";
import { SUCCESS_STATUS } from "@calcom/platform-constants";
import type { ApiResponse, ApiSuccessResponse } from "@calcom/platform-types";
import http from "../lib/http";
import { useAtomsContext } from "./useAtomsContext";
type ScheduleByEventSlugData = {
id: number;
name: string;
availability: unknown[][];
dateOverrides: unknown[];
timeZone: string;
workingHours: unknown[];
isDefault: boolean;
};
export const QUERY_KEY = "get-schedule-by-event-slug";
export const useScheduleByEventSlug = (props: { eventSlug?: string; enabled?: boolean }) => {
const { isInit } = useAtomsContext();
const schedule = useQuery({
queryKey: [QUERY_KEY, props.eventSlug],
queryFn: () => {
return http
.get<ApiResponse<ScheduleByEventSlugData>>(`/atoms/schedules/event-type/${props.eventSlug}`)
.then((res) => {
if (res.data.status === SUCCESS_STATUS) {
return (res.data as ApiSuccessResponse<ScheduleByEventSlugData>)?.data;
}
throw new Error(res.data.error.message);
});
},
enabled: !!props.eventSlug && (props?.enabled !== undefined ? props.enabled && isInit : isInit),
staleTime: 5000,
});
return schedule;
};
+40 -47
View File
@@ -1,55 +1,48 @@
export { CalProvider, CalOAuthProvider } from "./cal-provider";
export { GcalConnect } from "./connect/google/GcalConnect";
export { AvailabilitySettingsPlatformWrapper as AvailabilitySettings } from "./availability";
export type { AvailabilitySettingsPlatformWrapperProps as AvailabilitySettingsProps } from "./availability/wrappers/AvailabilitySettingsPlatformWrapper";
export type { AvailabilitySettingsScheduleType } from "./availability/AvailabilitySettings";
export { BookerPlatformWrapper as Booker } from "./booker/BookerPlatformWrapper";
export { useIsPlatform } from "./hooks/useIsPlatform";
export { useAtomsContext } from "./hooks/useAtomsContext";
export { useConnectedCalendars } from "./hooks/useConnectedCalendars";
export { useEventTypes } from "./hooks/event-types/public/useEventTypes";
export { useTeamEventTypes } from "./hooks/event-types/public/useTeamEventTypes";
export { useEventType as useEvent } from "./hooks/event-types/public/useEventType";
export { useEventTypeById } from "./hooks/event-types/private/useEventTypeById";
export { useCancelBooking } from "./hooks/bookings/useCancelBooking";
export { useBooking } from "./hooks/bookings/useBooking";
export { useBookings } from "./hooks/bookings/useBookings";
export { useMe } from "./hooks/useMe";
export { OutlookConnect } from "./connect/outlook/OutlookConnect";
export * as Connect from "./connect";
export { BookerEmbed } from "./booker-embed";
export { Router } from "./router";
export { useDeleteCalendarCredentials } from "./hooks/calendars/useDeleteCalendarCredentials";
export { useAddSelectedCalendar } from "./hooks/calendars/useAddSelectedCalendar";
export { useRemoveSelectedCalendar } from "./hooks/calendars/useRemoveSelectedCalendar";
export { useTeams } from "./hooks/teams/useTeams";
export { SelectedCalendarsSettingsPlatformWrapper as SelectedCalendarsSettings } from "./selected-calendars/index";
export { DestinationCalendarSettingsPlatformWrapper as DestinationCalendarSettings } from "./destination-calendar/index";
export { CalendarSettingsPlatformWrapper as CalendarSettings } from "./calendar-settings/index";
export type { UpdateScheduleInput_2024_06_11 as UpdateScheduleBody } from "@calcom/platform-types";
export { AvailabilitySettingsPlatformWrapper as AvailabilitySettings } from "./availability";
export type { AvailabilitySettingsScheduleType } from "./availability/AvailabilitySettings";
export type { AvailabilitySettingsFormRef } from "./availability/types";
export type { AvailabilitySettingsPlatformWrapperProps as AvailabilitySettingsProps } from "./availability/wrappers/AvailabilitySettingsPlatformWrapper";
export { BookerPlatformWrapper as Booker } from "./booker/BookerPlatformWrapper";
export { BookerEmbed } from "./booker-embed";
export { CalOAuthProvider, CalProvider } from "./cal-provider";
export { CalendarSettingsPlatformWrapper as CalendarSettings } from "./calendar-settings/index";
export { CalendarViewPlatformWrapper as CalendarView } from "./calendar-view/index";
export * as Connect from "./connect";
export type { ConferencingAppsCustomClassNames } from "./connect/conferencing-apps/ConferencingAppsViewPlatformWrapper";
export { ConferencingAppsViewPlatformWrapper as ConferencingAppsSettings } from "./connect/conferencing-apps/ConferencingAppsViewPlatformWrapper";
export { GcalConnect } from "./connect/google/GcalConnect";
export { OutlookConnect } from "./connect/outlook/OutlookConnect";
export { StripeConnect } from "./connect/stripe/StripeConnect";
export { CreateScheduleForm } from "./create-schedule/CreateScheduleForm";
export { CreateSchedulePlatformWrapper as CreateSchedule } from "./create-schedule/index";
export { DestinationCalendarSettingsPlatformWrapper as DestinationCalendarSettings } from "./destination-calendar/index";
export { ListEventTypesPlatformWrapper as ListEventTypes } from "./event-types/index";
export { PaymentForm } from "./event-types/payments/PaymentForm";
export { CreateEventTypePlatformWrapper as CreateEventType } from "./event-types/wrappers/CreateEventTypePlatformWrapper";
export { EventTypePlatformWrapper as EventTypeSettings } from "./event-types/wrappers/EventTypePlatformWrapper";
export type { EventSettingsFromRef } from "./event-types/wrappers/types";
export type { AvailabilitySettingsFormRef } from "./availability/types";
export { ConferencingAppsViewPlatformWrapper as ConferencingAppsSettings } from "./connect/conferencing-apps/ConferencingAppsViewPlatformWrapper";
export type { ConferencingAppsCustomClassNames } from "./connect/conferencing-apps/ConferencingAppsViewPlatformWrapper";
export { StripeConnect } from "./connect/stripe/StripeConnect";
export { CreateEventTypePlatformWrapper as CreateEventType } from "./event-types/wrappers/CreateEventTypePlatformWrapper";
export { PaymentForm } from "./event-types/payments/PaymentForm";
export { useBooking } from "./hooks/bookings/useBooking";
export { useBookings } from "./hooks/bookings/useBookings";
export { useCancelBooking } from "./hooks/bookings/useCancelBooking";
export { useAddSelectedCalendar } from "./hooks/calendars/useAddSelectedCalendar";
export { useDeleteCalendarCredentials } from "./hooks/calendars/useDeleteCalendarCredentials";
export { useRemoveSelectedCalendar } from "./hooks/calendars/useRemoveSelectedCalendar";
export { useCreateEventType } from "./hooks/event-types/private/useCreateEventType";
export { useCreateTeamEventType } from "./hooks/event-types/private/useCreateTeamEventType";
export { useEventTypeById } from "./hooks/event-types/private/useEventTypeById";
export { useEventType as useEvent } from "./hooks/event-types/public/useEventType";
export { useEventTypes } from "./hooks/event-types/public/useEventTypes";
export { useTeamEventTypes } from "./hooks/event-types/public/useTeamEventTypes";
export { useOrganizationBookings } from "./hooks/organizations/bookings/useOrganizationBookings";
export { useOrganizationUserBookings } from "./hooks/organizations/bookings/useOrganizationUserBookings";
export { CalendarViewPlatformWrapper as CalendarView } from "./calendar-view/index";
export { CreateSchedulePlatformWrapper as CreateSchedule } from "./create-schedule/index";
export { CreateScheduleForm } from "./create-schedule/CreateScheduleForm";
export { ListSchedulesPlatformWrapper as ListSchedules } from "./list-schedules/index";
export { ListEventTypesPlatformWrapper as ListEventTypes } from "./event-types/index";
export { useTeams } from "./hooks/teams/useTeams";
export { useAtomsContext } from "./hooks/useAtomsContext";
export { useAvailableSlots } from "./hooks/useAvailableSlots";
export { useConnectedCalendars } from "./hooks/useConnectedCalendars";
export { useIsPlatform } from "./hooks/useIsPlatform";
export { useMe } from "./hooks/useMe";
export { ListSchedulesPlatformWrapper as ListSchedules } from "./list-schedules/index";
export { Router } from "./router";
export { SelectedCalendarsSettingsPlatformWrapper as SelectedCalendarsSettings } from "./selected-calendars/index";
export { TroubleshooterPlatformWrapper as TroubleShooter } from "./troubleshooter/index";
@@ -0,0 +1 @@
export { TroubleshooterPlatformWrapper } from "./wrappers/TroubleshooterPlatformWrapper";
@@ -0,0 +1,31 @@
import { useTroubleshooterStore } from "@calcom/features/troubleshooter/store";
import { CalendarViewPlatformWrapper } from "../../calendar-view/wrappers/CalendarViewPlatformWrapper";
export const LargeCalendar = (): JSX.Element | null => {
const event = useTroubleshooterStore((state) => state.event);
if (!event?.slug) return null;
if (event.teamId) {
return (
<CalendarViewPlatformWrapper
isEventTypeView={true}
teamId={event.teamId}
eventSlug={event.slug}
/>
);
}
if (event.username) {
return (
<CalendarViewPlatformWrapper
isEventTypeView={true}
username={event.username}
eventSlug={event.slug}
/>
);
}
return null;
};
@@ -0,0 +1,27 @@
import { CalendarToggleContainerComponent } from "@calcom/features/troubleshooter/components/CalendarToggleContainerComponent";
import { useConnectedCalendars } from "../../hooks/useConnectedCalendars";
interface CalendarToggleContainerProps {
onManageCalendarsClick?: () => void;
onInstallCalendarClick?: () => void;
}
export function CalendarToggleContainer({
onManageCalendarsClick,
onInstallCalendarClick,
}: CalendarToggleContainerProps): JSX.Element {
const calendars = useConnectedCalendars({});
return (
<CalendarToggleContainerComponent
connectedCalendars={calendars.data?.connectedCalendars ?? []}
isLoading={calendars.isLoading}
{...(onManageCalendarsClick
? { manageCalendarsAction: { onClick: onManageCalendarsClick } }
: {})}
{...(onInstallCalendarClick
? { installCalendarAction: { onClick: onInstallCalendarClick } }
: {})}
/>
);
}
@@ -0,0 +1,13 @@
import { useTroubleshooterStore } from "@calcom/features/troubleshooter/store";
import { EventScheduleItemComponent } from "@calcom/features/troubleshooter/components/EventScheduleItemComponent";
import { useScheduleByEventSlug } from "../../hooks/useScheduleByEventSlug";
export function EventScheduleItem(): JSX.Element {
const selectedEventType = useTroubleshooterStore((state) => state.event);
const { data: schedule } = useScheduleByEventSlug({
eventSlug: selectedEventType?.slug,
});
return <EventScheduleItemComponent schedule={schedule ?? null} />;
}
@@ -0,0 +1,13 @@
import { EventTypeSelectComponent } from "@calcom/features/troubleshooter/components/EventTypeSelectComponent";
import { useEventTypesList } from "../../hooks/useEventTypesList";
export function EventTypeSelect(): JSX.Element {
const { data: eventTypes, isPending } = useEventTypesList({});
return (
<EventTypeSelectComponent
eventTypes={eventTypes ?? []}
isPending={isPending}
/>
);
}
@@ -0,0 +1,42 @@
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { Skeleton } from "@calcom/ui/components/skeleton";
import { CalendarToggleContainer } from "./CalendarToggleContainer";
import { EventScheduleItem } from "./EventScheduleItem";
import { EventTypeSelect } from "./EventTypeSelect";
const SidebarHeading = ({ name }: { name: string }): JSX.Element => {
return (
<Skeleton
title={name}
as="p"
className="max-w-36 min-h-4 truncate font-semibold"
loadingClassName="ms-3"
>
{name}
</Skeleton>
);
};
interface TroubleshooterSidebarProps {
onManageCalendarsClick?: () => void;
onInstallCalendarClick?: () => void;
}
export const TroubleshooterSidebar = ({
onManageCalendarsClick,
onInstallCalendarClick,
}: TroubleshooterSidebarProps): JSX.Element => {
const { t } = useLocale();
return (
<div className="relative z-10 hidden h-screen w-full flex-col gap-6 overflow-y-auto py-6 pl-4 pr-6 sm:flex md:pl-0">
<SidebarHeading name={t("troubleshooter")} />
<EventTypeSelect />
<EventScheduleItem />
<CalendarToggleContainer
onManageCalendarsClick={onManageCalendarsClick}
onInstallCalendarClick={onInstallCalendarClick}
/>
</div>
);
};
@@ -0,0 +1,89 @@
import { useInitalizeTroubleshooterStore } from "@calcom/features/troubleshooter/store";
import useMediaQuery from "@calcom/lib/hooks/useMediaQuery";
import classNames from "@calcom/ui/classNames";
import { AtomsWrapper } from "../../src/components/atoms-wrapper";
import { TroubleshooterSidebar } from "../sidebar/TroubleshooterSidebar";
import { LargeCalendar } from "../large-calendar/LargeCalendar";
import { BookerStoreProvider } from "@calcom/features/bookings/Booker/BookerStoreProvider";
interface TroubleshooterComponentProps {
month?: string | null;
onManageCalendarsClick?: () => void;
onInstallCalendarClick?: () => void;
}
export const TroubleshooterComponent = ({
month = null,
onManageCalendarsClick,
onInstallCalendarClick,
}: TroubleshooterComponentProps): JSX.Element => {
const isMobile = useMediaQuery("(max-width: 768px)");
const isTablet = useMediaQuery("(max-width: 1024px)");
useInitalizeTroubleshooterStore({
month: month,
isPlatform: true,
});
return (
<AtomsWrapper>
<>
<div
className={classNames(
"text-default flex min-h-full w-full flex-col items-center overflow-clip",
isMobile
? "[--troubleshooter-meta-width:0px]"
: "[--troubleshooter-meta-width:250px] lg:[--troubleshooter-meta-width:430px]"
)}
>
<div
style={{
display: "grid",
width: "100%",
height: "auto",
gridTemplateAreas: `"meta main"`,
gridTemplateColumns: "var(--troubleshooter-meta-width) 1fr",
gridTemplateRows: "auto",
}}
className={classNames(
"bg-default dark:bg-cal-muted text-default min-h-full w-full sm:transition-[width] sm:duration-300"
)}
>
<div className="sticky top-0 z-10 self-start ps-6 [grid-area:meta]">
<TroubleshooterSidebar
onManageCalendarsClick={onManageCalendarsClick}
onInstallCalendarClick={onInstallCalendarClick}
/>
</div>
<div className="ml-[-1px] border-subtle [grid-area:main]">
<LargeCalendar />
</div>
</div>
</div>
</>
</AtomsWrapper>
);
};
interface TroubleshooterPlatformWrapperProps {
month?: string | null;
onManageCalendarsClick?: () => void;
onInstallCalendarClick?: () => void;
}
export const TroubleshooterPlatformWrapper = ({
month,
onManageCalendarsClick,
onInstallCalendarClick,
}: TroubleshooterPlatformWrapperProps): JSX.Element => {
return (
<BookerStoreProvider>
<TroubleshooterComponent
month={month}
onManageCalendarsClick={onManageCalendarsClick}
onInstallCalendarClick={onInstallCalendarClick}
/>
</BookerStoreProvider>
);
};
@@ -25,6 +25,9 @@ export function Navbar({ username }: { username?: string }) {
<li>
<Link href="/availability">Availability</Link>
</li>
<li>
<Link href="/troubleshooter">Troubleshooter</Link>
</li>
<li>
<Link href="/event-types">EventTypes</Link>
</li>
@@ -0,0 +1,30 @@
import { TroubleShooter } from "@calcom/atoms";
import { Inter } from "next/font/google";
import { Navbar } from "@/components/Navbar";
// eslint-disable-next-line @calcom/eslint/deprecated-imports-next-router
import { useRouter } from "next/router";
const inter = Inter({ subsets: ["latin"] });
export default function Troubleshooter(props: {
calUsername: string;
calEmail: string;
}) {
const router = useRouter();
return (
<main className={`flex min-h-screen flex-col ${inter.className}`}>
<Navbar username={props.calUsername} />
<div data-testid="troubleshooter-atom">
<TroubleShooter
onManageCalendarsClick={() => {
router.push("/calendars");
}}
onInstallCalendarClick={() => {
router.push("/calendars");
}}
/>
</div>
</main>
);
}
@@ -7,6 +7,8 @@ export { getBulkUserEventTypes, getBulkTeamEventTypes } from "@calcom/app-store/
export { createHandler as createEventType } from "@calcom/trpc/server/routers/viewer/eventTypes/heavy/create.handler";
export { updateHandler as updateEventType } from "@calcom/trpc/server/routers/viewer/eventTypes/heavy/update.handler";
export { listWithTeamHandler } from "@calcom/trpc/server/routers/viewer/eventTypes/listWithTeam.handler";
export type { TUpdateInputSchema as TUpdateEventTypeInputSchema } from "@calcom/trpc/server/routers/viewer/eventTypes/heavy/update.schema";
export type { EventTypesPublic } from "@calcom/features/eventtypes/lib/getEventTypesPublic";
export { getEventTypesPublic } from "@calcom/features/eventtypes/lib/getEventTypesPublic";
+2
View File
@@ -23,3 +23,5 @@ export {
duplicateHandler as duplicateScheduleHandler,
type DuplicateScheduleHandlerReturn,
} from "@calcom/trpc/server/routers/viewer/availability/schedule/duplicate.handler";
export { getScheduleByEventSlugHandler } from "@calcom/trpc/server/routers/viewer/availability/schedule/getScheduleByEventTypeSlug.handler";