feat: advanced tab platform wrapper (#16941)

* fixed error in advanced tab atom build

-- used `DOMPurify` instead of `sanitize-html`

* hide BookerLayoutSelector for platform and removePlatformClientIdFromEmail

* fixup! Merge branch 'main' into event-advanced-platform-wrapper

* undo linting changes

* undo linting changes

* fix: active state of tabs items

---------

Co-authored-by: Morgan <[email protected]>
Co-authored-by: Morgan Vernay <[email protected]>
This commit is contained in:
authored and GitHub committed 2024-10-10 17:09:03 +03:00
1 parent 1f08bc5a4f
commit 99caae8665
17 files changed
+208 -101

No files matched your search

@@ -60,12 +60,14 @@ export const usePlatformTabsNavigations = ({ formMethods, eventType, team, tabs
onClick: (tab) => {
setCurrentTab(tab);
},
currentTab,
});
if (!requirePayment) {
navigation.splice(3, 0, {
name: "recurring",
onClick: () => setCurrentTab("recurring"),
isActive: currentTab === "recurring",
href: `${url}?tabName=recurring`,
icon: "repeat",
info: `recurring_event_tab_description`,
@@ -75,6 +77,7 @@ export const usePlatformTabsNavigations = ({ formMethods, eventType, team, tabs
navigation.splice(1, 0, {
name: "availability",
onClick: () => setCurrentTab("availability"),
isActive: currentTab === "availability",
href: `${url}?tabName=availability`,
icon: "calendar",
info:
@@ -96,6 +99,7 @@ export const usePlatformTabsNavigations = ({ formMethods, eventType, team, tabs
navigation.splice(2, 0, {
name: "assignment",
onClick: () => setCurrentTab("team"),
isActive: currentTab === "team",
href: `${url}?tabName=team`,
icon: "users",
info: `${t(watchSchedulingType?.toLowerCase() ?? "")}${
@@ -133,15 +137,17 @@ type getNavigationProps = {
tabs: PlatformTabs[];
url: string;
onClick: (tab: PlatformTabs) => void;
currentTab: PlatformTabs;
};
function getNavigation({ length, multipleDuration, t, tabs, url, onClick }: getNavigationProps) {
function getNavigation({ length, multipleDuration, t, tabs, url, onClick, currentTab }: getNavigationProps) {
const duration = multipleDuration?.map((duration) => ` ${duration}`) || length;
const tabsNavigation: VerticalTabItemProps[] = [];
tabs.includes("setup") &&
tabsNavigation.push({
name: "event_setup_tab_title",
onClick: () => onClick("setup"),
isActive: currentTab === "setup",
href: `${url}?tabName=setup`,
icon: "link",
info: `${duration} ${t("minute_timeUnit")}`, // TODO: Get this from props
@@ -150,6 +156,7 @@ function getNavigation({ length, multipleDuration, t, tabs, url, onClick }: getN
tabsNavigation.push({
name: "event_limit_tab_title",
onClick: () => onClick("limits"),
isActive: currentTab === "limits",
href: `${url}?tabName=limits`,
icon: "clock",
info: `event_limit_tab_description`,
@@ -159,6 +166,7 @@ function getNavigation({ length, multipleDuration, t, tabs, url, onClick }: getN
tabsNavigation.push({
name: "event_advanced_tab_title",
onClick: () => onClick("advanced"),
isActive: currentTab === "advanced",
href: `${url}?tabName=advanced`,
icon: "sliders-vertical",
info: `event_advanced_tab_description`,
@@ -0,0 +1,17 @@
import type { EventAdvancedBaseProps } from "@calcom/features/eventtypes/components/tabs/advanced/EventAdvancedTab";
import { EventAdvancedTab } from "@calcom/features/eventtypes/components/tabs/advanced/EventAdvancedTab";
import { useConnectedCalendars } from "../../hooks/useConnectedCalendars";
const EventAdvancedPlatformWrapper = (props: EventAdvancedBaseProps) => {
const { data: connectedCalendarsQuery } = useConnectedCalendars({});
return (
<EventAdvancedTab
{...props}
calendarsQueryData={connectedCalendarsQuery}
showBookerLayoutSelector={false}
/>
);
};
export default EventAdvancedPlatformWrapper;
@@ -1,25 +1,14 @@
import type { EventAdvancedBaseProps } from "@calcom/features/eventtypes/components/tabs/advanced/EventAdvancedTab";
import { EventAdvancedTab } from "@calcom/features/eventtypes/components/tabs/advanced/EventAdvancedTab";
import type { EventTypeSetupProps } from "@calcom/features/eventtypes/lib/types";
import type { RouterOutputs } from "@calcom/trpc/react";
import { trpc } from "@calcom/trpc/react";
export type EventAdvancedWebWrapperProps = Pick<EventTypeSetupProps, "eventType" | "team"> & {
loggedInUser?: RouterOutputs["viewer"]["me"];
isLoggedInUserPending?: boolean;
};
const EventAdvancedWebWrapper = ({
loggedInUser,
isLoggedInUserPending,
...props
}: EventAdvancedWebWrapperProps) => {
const EventAdvancedWebWrapper = ({ ...props }: EventAdvancedBaseProps) => {
const connectedCalendarsQuery = trpc.viewer.connectedCalendars.useQuery();
return (
<EventAdvancedTab
{...props}
calendarsQueryData={connectedCalendarsQuery.data}
user={loggedInUser}
isUserLoading={isLoggedInUserPending}
showBookerLayoutSelector={true}
/>
);
};
@@ -10,6 +10,7 @@ import type { EventTypeSetupProps, FormValues, TabMap } from "@calcom/features/e
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { SchedulingType } from "@calcom/prisma/enums";
import { useMe } from "../../hooks/useMe";
import { AtomsWrapper } from "../../src/components/atoms-wrapper";
import { useToast } from "../../src/components/ui/use-toast";
import { useAtomsEventTypeById, QUERY_KEY as ATOM_EVENT_TYPE_QUERY_KEY } from "../hooks/useAtomEventTypeById";
@@ -17,6 +18,7 @@ import { useAtomUpdateEventType } from "../hooks/useAtomUpdateEventType";
import { useEventTypeForm } from "../hooks/useEventTypeForm";
import { useHandleRouteChange } from "../hooks/useHandleRouteChange";
import { usePlatformTabsNavigations } from "../hooks/usePlatformTabsNavigations";
import EventAdvancedPlatformWrapper from "./EventAdvancedPlatformWrapper";
import EventLimitsTabPlatformWrapper from "./EventLimitsTabPlatformWrapper";
import EventRecurringTabPlatformWrapper from "./EventRecurringTabPlatformWrapper";
import SetupTab from "./EventSetupTabPlatformWrapper";
@@ -42,6 +44,7 @@ const EventType = ({
const [pendingRoute, setPendingRoute] = useState("");
const { eventType, locationOptions, team, teamMembers, destinationCalendar } = props;
const [slugExistsChildrenDialogOpen, setSlugExistsChildrenDialogOpen] = useState<ChildrenEventType[]>([]);
const { data: user, isLoading: isUserLoading } = useMe();
const updateMutation = useAtomUpdateEventType({
onSuccess: async () => {
@@ -73,6 +76,10 @@ const EventType = ({
const { form, handleSubmit } = useEventTypeForm({ eventType, onSubmit: updateMutation.mutate });
const slug = form.watch("slug") ?? eventType.slug;
const showToast = (message: string, variant: "success" | "warning" | "error") => {
toast({ description: message });
};
const tabMap = {
setup: tabs.includes("setup") ? (
<SetupTab
@@ -87,8 +94,19 @@ const EventType = ({
),
availability: <></>,
team: <></>,
advanced: tabs.includes("advanced") ? (
<EventAdvancedPlatformWrapper
eventType={eventType}
team={team}
user={user?.data}
isUserLoading={isUserLoading}
showToast={showToast}
/>
) : (
<></>
),
limits: tabs.includes("limits") ? <EventLimitsTabPlatformWrapper eventType={eventType} /> : <></>,
advanced: <></>,
instant: <></>,
recurring: tabs.includes("recurring") ? (
<EventRecurringTabPlatformWrapper eventType={eventType} />
@@ -250,8 +250,9 @@ const EventTypeWeb = ({
<EventAdvancedTab
eventType={eventType}
team={team}
loggedInUser={loggedInUser}
isLoggedInUserPending={isLoggedInUserPending}
user={loggedInUser}
isUserLoading={isLoggedInUserPending}
showToast={showToast}
/>
),
instant: <EventInstantTab eventType={eventType} isTeamEvent={!!team} />,