Skip to content

Scheduling infrastructure for absolutely everyone.

perf: layout persistence and reduced bundle size (#18889)

Benny Jooee31633e2b03
diff --git a/apps/web/app/(use-page-wrapper)/(main-nav)/ShellMainAppDir.tsx b/apps/web/app/(use-page-wrapper)/(main-nav)/ShellMainAppDir.tsx
new file mode 100644
index 00000000000..8aedfe510be
--- /dev/null
+++ b/apps/web/app/(use-page-wrapper)/(main-nav)/ShellMainAppDir.tsx
@@ -0,0 +1,65 @@
+import { ShellMainAppDirBackButton } from "app/(use-page-wrapper)/(main-nav)/ShellMainAppDirBackButton";
+import classNames from "classnames";
+
+import type { LayoutProps } from "@calcom/features/shell/Shell";
+
+// Copied from `ShellMain` but with a different `ShellMainAppDirBackButton` import
+// for client/server component separation
+export function ShellMainAppDir(props: LayoutProps) {
+ return (
+ <>
+ {(props.heading || !!props.backPath) && (
+ <div
+ className={classNames(
+ "flex items-center md:mb-6 md:mt-0",
+ props.smallHeading ? "lg:mb-7" : "lg:mb-8",
+ props.hideHeadingOnMobile ? "mb-0" : "mb-6"
+ )}>
+ {!!props.backPath && <ShellMainAppDirBackButton backPath={props.backPath} />}
+ {props.heading && (
+ <header
+ className={classNames(props.large && "py-8", "flex w-full max-w-full items-center truncate")}>
+ {props.HeadingLeftIcon && <div className="ltr:mr-4">{props.HeadingLeftIcon}</div>}
+ <div
+ className={classNames("w-full truncate ltr:mr-4 rtl:ml-4 md:block", props.headerClassName)}>
+ {props.heading && (
+ <h3
+ className={classNames(
+ "font-cal text-emphasis max-w-28 sm:max-w-72 md:max-w-80 inline truncate text-lg font-semibold tracking-wide sm:text-xl md:block xl:max-w-full",
+ props.smallHeading ? "text-base" : "text-xl",
+ props.hideHeadingOnMobile && "hidden"
+ )}>
+ {props.heading}
+ </h3>
+ )}
+ {props.subtitle && (
+ <p className="text-default hidden text-sm md:block" data-testid="subtitle">
+ {props.subtitle}
+ </p>
+ )}
+ </div>
+ {props.beforeCTAactions}
+ {props.CTA && (
+ <div
+ className={classNames(
+ props.backPath
+ ? "relative"
+ : "pwa:bottom-[max(7rem,_calc(5rem_+_env(safe-area-inset-bottom)))] fixed bottom-20 z-40 ltr:right-4 rtl:left-4 md:z-auto md:ltr:right-0 md:rtl:left-0",
+ "flex-shrink-0 [-webkit-app-region:no-drag] md:relative md:bottom-auto md:right-auto"
+ )}>
+ {props.CTA}
+ </div>
+ )}
+ {props.actions && props.actions}
+ </header>
+ )}
+ </div>
+ )}
+ {props.afterHeading && <>{props.afterHeading}</>}
+
+ <div className={classNames(props.flexChildrenContainer && "flex flex-1 flex-col")}>
+ {props.children}
+ </div>
+ </>
+ );
+}
diff --git a/apps/web/app/(use-page-wrapper)/(main-nav)/ShellMainAppDirBackButton.tsx b/apps/web/app/(use-page-wrapper)/(main-nav)/ShellMainAppDirBackButton.tsx
new file mode 100644
index 00000000000..2be728fbd93
--- /dev/null
+++ b/apps/web/app/(use-page-wrapper)/(main-nav)/ShellMainAppDirBackButton.tsx
@@ -0,0 +1,22 @@
+"use client";
+
+import { useRouter } from "next/navigation";
+
+import type { LayoutProps } from "@calcom/features/shell/Shell";
+import { Button } from "@calcom/ui";
+
+export const ShellMainAppDirBackButton = ({ backPath }: { backPath: LayoutProps["backPath"] }) => {
+ const router = useRouter();
+ return (
+ <Button
+ variant="icon"
+ size="sm"
+ color="minimal"
+ onClick={() => (typeof backPath === "string" ? router.push(backPath as string) : router.back())}
+ StartIcon="arrow-left"
+ aria-label="Go Back"
+ className="rounded-md ltr:mr-2 rtl:ml-2"
+ data-testid="go-back-button"
+ />
+ );
+};
diff --git a/apps/web/app/(use-page-wrapper)/availability/page.tsx b/apps/web/app/(use-page-wrapper)/(main-nav)/availability/page.tsx
similarity index 68%
rename from apps/web/app/(use-page-wrapper)/availability/page.tsx
rename to apps/web/app/(use-page-wrapper)/(main-nav)/availability/page.tsx
index ba6a4288c9d..e7d7ac50df6 100644
--- a/apps/web/app/(use-page-wrapper)/availability/page.tsx
+++ b/apps/web/app/(use-page-wrapper)/(main-nav)/availability/page.tsx
@@ -1,11 +1,13 @@
-import { _generateMetadata } from "app/_utils";
+import { _generateMetadata, getTranslate } from "app/_utils";
// import { cookies, headers } from "next/headers";
import { notFound } from "next/navigation";
// import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
// import { buildLegacyRequest } from "@lib/buildLegacyCtx";
// import { OrganizationRepository } from "@calcom/lib/server/repository/organization";
-import AvailabilityPage from "~/availability/availability-view";
+import AvailabilityPage, { AvailabilityCTA } from "~/availability/availability-view";
+
+import { ShellMainAppDir } from "../ShellMainAppDir";
export const generateMetadata = async () => {
return await _generateMetadata(
@@ -27,10 +29,14 @@ const Page = async () => {
// orgId,
// userId,
// });
+ const t = await getTranslate();
return (
- <AvailabilityPage
- // currentOrg={currentOrg}
- />
+ <ShellMainAppDir
+ heading={t("availability")}
+ subtitle={t("configure_availability")}
+ CTA={<AvailabilityCTA />}>
+ <AvailabilityPage />
+ </ShellMainAppDir>
);
} catch {
notFound();
diff --git a/apps/web/app/(use-page-wrapper)/bookings/[status]/page.tsx b/apps/web/app/(use-page-wrapper)/(main-nav)/bookings/[status]/page.tsx
similarity index 59%
rename from apps/web/app/(use-page-wrapper)/bookings/[status]/page.tsx
rename to apps/web/app/(use-page-wrapper)/(main-nav)/bookings/[status]/page.tsx
index 940e7c09b24..1355403f274 100644
--- a/apps/web/app/(use-page-wrapper)/bookings/[status]/page.tsx
+++ b/apps/web/app/(use-page-wrapper)/(main-nav)/bookings/[status]/page.tsx
@@ -1,5 +1,6 @@
+import { ShellMainAppDir } from "app/(use-page-wrapper)/(main-nav)/ShellMainAppDir";
import type { PageProps } from "app/_types";
-import { _generateMetadata } from "app/_utils";
+import { _generateMetadata, getTranslate } from "app/_utils";
import { redirect } from "next/navigation";
import { z } from "zod";
@@ -16,13 +17,18 @@ export const generateMetadata = async () =>
(t) => t("bookings_description")
);
-const Page = ({ params }: PageProps) => {
+const Page = async ({ params }: PageProps) => {
const parsed = querySchema.safeParse(params);
if (!parsed.success) {
redirect("/bookings/upcoming");
}
+ const t = await getTranslate();
- return <BookingsList status={parsed.data.status} />;
+ return (
+ <ShellMainAppDir heading={t("bookings")} subtitle={t("bookings_description")}>
+ <BookingsList status={parsed.data.status} />
+ </ShellMainAppDir>
+ );
};
export default Page;
diff --git a/apps/web/app/(use-page-wrapper)/event-types/page.tsx b/apps/web/app/(use-page-wrapper)/(main-nav)/event-types/page.tsx
similarity index 62%
rename from apps/web/app/(use-page-wrapper)/event-types/page.tsx
rename to apps/web/app/(use-page-wrapper)/(main-nav)/event-types/page.tsx
index bc0d85e022e..d975c7de607 100644
--- a/apps/web/app/(use-page-wrapper)/event-types/page.tsx
+++ b/apps/web/app/(use-page-wrapper)/(main-nav)/event-types/page.tsx
@@ -1,5 +1,6 @@
+import { ShellMainAppDir } from "app/(use-page-wrapper)/(main-nav)/ShellMainAppDir";
import type { PageProps } from "app/_types";
-import { _generateMetadata } from "app/_utils";
+import { _generateMetadata, getTranslate } from "app/_utils";
import { cookies, headers } from "next/headers";
import { redirect } from "next/navigation";
@@ -9,7 +10,7 @@ import { buildLegacyCtx } from "@lib/buildLegacyCtx";
import { ssrInit } from "@server/lib/ssr";
-import EventTypes from "~/event-types/views/event-types-listing-view";
+import EventTypes, { EventTypesCTA } from "~/event-types/views/event-types-listing-view";
export const generateMetadata = async () =>
await _generateMetadata(
@@ -20,13 +21,22 @@ export const generateMetadata = async () =>
const Page = async ({ params, searchParams }: PageProps) => {
const context = buildLegacyCtx(headers(), cookies(), params, searchParams);
const session = await getServerSession({ req: context.req });
+
if (!session?.user?.id) {
redirect("/auth/login");
}
await ssrInit(context);
-
- return <EventTypes />;
+ const t = await getTranslate();
+
+ return (
+ <ShellMainAppDir
+ heading={t("event_types_page_title")}
+ subtitle={t("event_types_page_subtitle")}
+ CTA={<EventTypesCTA />}>
+ <EventTypes />
+ </ShellMainAppDir>
+ );
};
export default Page;
diff --git a/apps/web/app/(use-page-wrapper)/(main-nav)/layout.tsx b/apps/web/app/(use-page-wrapper)/(main-nav)/layout.tsx
new file mode 100644
index 00000000000..fb0a1131865
--- /dev/null
+++ b/apps/web/app/(use-page-wrapper)/(main-nav)/layout.tsx
@@ -0,0 +1,11 @@
+import Shell from "@calcom/features/shell/Shell";
+
+const Layout = ({ children }: { children: React.ReactNode }) => {
+ return (
+ <Shell hideHeadingOnMobile withoutSeo={true} withoutMain={true}>
+ {children}
+ </Shell>
+ );
+};
+
+export default Layout;
diff --git a/apps/web/app/(use-page-wrapper)/bookings/layout.tsx b/apps/web/app/(use-page-wrapper)/bookings/layout.tsx
deleted file mode 100644
index 9297d1d425b..00000000000
--- a/apps/web/app/(use-page-wrapper)/bookings/layout.tsx
+++ /dev/null
@@ -1,21 +0,0 @@
-import { getTranslate } from "app/_utils";
-
-import Shell from "@calcom/features/shell/Shell";
-
-async function BookingsStatusLayout({ children }: { children: React.ReactNode }) {
- const t = await getTranslate();
- return (
- <Shell
- withoutMain={false}
- withoutSeo={true}
- hideHeadingOnMobile
- heading={t("bookings")}
- subtitle={t("bookings_description")}
- title={t("bookings")}
- description={t("bookings_description")}>
- {children}
- </Shell>
- );
-}
-
-export default BookingsStatusLayout;
diff --git a/apps/web/modules/availability/availability-view.tsx b/apps/web/modules/availability/availability-view.tsx
index 0f79c2d68f9..a58712b4680 100644
--- a/apps/web/modules/availability/availability-view.tsx
+++ b/apps/web/modules/availability/availability-view.tsx
@@ -9,7 +9,6 @@ import SkeletonLoader from "@calcom/features/availability/components/SkeletonLoa
import { BulkEditDefaultForEventsModal } from "@calcom/features/eventtypes/components/BulkEditDefaultForEventsModal";
import type { BulkUpdatParams } from "@calcom/features/eventtypes/components/BulkEditDefaultForEventsModal";
import { NewScheduleButton, ScheduleListItem } from "@calcom/features/schedules";
-import Shell from "@calcom/features/shell/Shell";
import { AvailabilitySliderTable } from "@calcom/features/timezone-buddy/components/AvailabilitySliderTable";
import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams";
import { useLocale } from "@calcom/lib/hooks/useLocale";
@@ -195,14 +194,11 @@ type PageProps = {
currentOrg?: Awaited<ReturnType<typeof OrganizationRepository.findCurrentOrg>> | null;
};
-export default function AvailabilityPage({ currentOrg }: PageProps) {
+export const AvailabilityCTA = () => {
const { t } = useLocale();
const searchParams = useCompatSearchParams();
const router = useRouter();
const pathname = usePathname();
- const me = useMeQuery();
- const { data: _data } = trpc.viewer.organizations.listCurrent.useQuery(undefined, { enabled: !currentOrg });
- const data = currentOrg ?? _data;
// Get a new searchParams string by merging the current
// searchParams with a provided key/value pair
@@ -216,7 +212,7 @@ export default function AvailabilityPage({ currentOrg }: PageProps) {
[searchParams]
);
- const isOrg = Boolean(data);
+ const { data } = trpc.viewer.organizations.listCurrent.useQuery();
const isOrgAdminOrOwner =
(data && (data.user.role === MembershipRole.OWNER || data.user.role === MembershipRole.ADMIN)) ?? false;
const isOrgAndPrivate = data?.isOrganization && data.isPrivate;
@@ -230,35 +226,44 @@ export default function AvailabilityPage({ currentOrg }: PageProps) {
}
return (
- <div>
- <Shell
- heading={t("availability")}
- subtitle={t("configure_availability")}
- title={t("availability")}
- description={t("configure_availability")}
- hideHeadingOnMobile
- withoutSeo={true}
- withoutMain={false}
- CTA={
- <div className="flex gap-2">
- <ToggleGroup
- className="hidden md:block"
- defaultValue={searchParams?.get("type") ?? "mine"}
- onValueChange={(value) => {
- if (!value) return;
- router.push(`${pathname}?${createQueryString("type", value)}`);
- }}
- options={toggleGroupOptions}
- />
- <NewScheduleButton />
- </div>
- }>
- {searchParams?.get("type") === "team" && canViewTeamAvailability ? (
- <AvailabilitySliderTable userTimeFormat={me?.data?.timeFormat ?? null} isOrg={isOrg} />
- ) : (
- <AvailabilityListWithQuery />
- )}
- </Shell>
+ <div className="flex gap-2">
+ <ToggleGroup
+ className="hidden md:block"
+ defaultValue={searchParams?.get("type") ?? "mine"}
+ onValueChange={(value) => {
+ if (!value) return;
+ router.push(`${pathname}?${createQueryString("type", value)}`);
+ }}
+ options={toggleGroupOptions}
+ />
+ <NewScheduleButton />
</div>
);
+};
+
+export default function AvailabilityPage({ currentOrg }: PageProps) {
+ const { t } = useLocale();
+ const searchParams = useCompatSearchParams();
+ const me = useMeQuery();
+ const { data: _data } = trpc.viewer.organizations.listCurrent.useQuery(undefined, { enabled: !currentOrg });
+ const data = currentOrg ?? _data;
+
+ const isOrg = Boolean(data);
+ const isOrgAdminOrOwner =
+ (data && (data.user.role === MembershipRole.OWNER || data.user.role === MembershipRole.ADMIN)) ?? false;
+ const isOrgAndPrivate = data?.isOrganization && data.isPrivate;
+
+ const canViewTeamAvailability = isOrgAdminOrOwner || !isOrgAndPrivate;
+
+ const toggleGroupOptions = [{ value: "mine", label: t("my_availability") }];
+
+ if (canViewTeamAvailability) {
+ toggleGroupOptions.push({ value: "team", label: t("team_availability") });
+ }
+
+ return searchParams?.get("type") === "team" && canViewTeamAvailability ? (
+ <AvailabilitySliderTable userTimeFormat={me?.data?.timeFormat ?? null} isOrg={isOrg} />
+ ) : (
+ <AvailabilityListWithQuery />
+ );
}
diff --git a/apps/web/modules/event-types/views/event-types-listing-view.tsx b/apps/web/modules/event-types/views/event-types-listing-view.tsx
index 4bd017461ec..d5b42ba4ecc 100644
--- a/apps/web/modules/event-types/views/event-types-listing-view.tsx
+++ b/apps/web/modules/event-types/views/event-types-listing-view.tsx
@@ -15,7 +15,6 @@ import CreateEventTypeDialog from "@calcom/features/eventtypes/components/Create
import { DuplicateDialog } from "@calcom/features/eventtypes/components/DuplicateDialog";
import { InfiniteSkeletonLoader } from "@calcom/features/eventtypes/components/SkeletonLoader";
import { getTeamsFiltersFromQuery } from "@calcom/features/filters/lib/getTeamsFiltersFromQuery";
-import Shell from "@calcom/features/shell/Shell";
import { classNames, parseEventTypeColor } from "@calcom/lib";
import { APP_NAME, WEBSITE_URL } from "@calcom/lib/constants";
import { useCopy } from "@calcom/lib/hooks/useCopy";
@@ -942,8 +941,36 @@ const InfiniteScrollMain = ({
);
};
+export const EventTypesCTA = () => {
+ const { data: user } = useMeQuery();
+ const routerQuery = useRouterQuery();
+ const filters = getTeamsFiltersFromQuery(routerQuery);
+ const { data: getUserEventGroupsData } = trpc.viewer.eventTypes.getUserEventGroups.useQuery(
+ filters && { filters },
+ {
+ refetchOnWindowFocus: false,
+ gcTime: 1 * 60 * 60 * 1000,
+ staleTime: 1 * 60 * 60 * 1000,
+ }
+ );
+ const profileOptions =
+ getUserEventGroupsData?.profiles
+ ?.filter((profile) => !profile.readOnly)
+ ?.filter((profile) => !profile.eventTypesLockedByOrg)
+ ?.map((profile) => {
+ return {
+ teamId: profile.teamId,
+ label: profile.name || profile.slug,
+ image: profile.image,
+ membershipRole: profile.membershipRole,
+ slug: profile.slug,
+ };
+ }) ?? [];
+
+ return <CTA profileOptions={profileOptions} isOrganization={!!user?.organizationId} />;
+};
+
const EventTypesPage: React.FC = () => {
- const { t } = useLocale();
const { data: user } = useMeQuery();
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [_showProfileBanner, setShowProfileBanner] = useState(false);
@@ -980,37 +1007,13 @@ const EventTypesPage: React.FC = () => {
);
}, [orgBranding, user]);
- const profileOptions =
- getUserEventGroupsData?.profiles
- ?.filter((profile) => !profile.readOnly)
- ?.filter((profile) => !profile.eventTypesLockedByOrg)
- ?.map((profile) => {
- return {
- teamId: profile.teamId,
- label: profile.name || profile.slug,
- image: profile.image,
- membershipRole: profile.membershipRole,
- slug: profile.slug,
- };
- }) ?? [];
-
return (
- <Shell
- withoutMain={false}
- title={t("event_types_page_title")}
- description={t("event_types_page_subtitle")}
- withoutSeo
- heading={t("event_types_page_title")}
- hideHeadingOnMobile
- subtitle={t("event_types_page_subtitle")}
- CTA={<CTA profileOptions={profileOptions} isOrganization={!!user?.organizationId} />}>
- <InfiniteScrollMain
- profiles={getUserEventGroupsData?.profiles}
- eventTypeGroups={getUserEventGroupsData?.eventTypeGroups}
- status={getUserEventGroupsStatus}
- errorMessage={getUserEventGroupsStatusError?.message}
- />
- </Shell>
+ <InfiniteScrollMain
+ profiles={getUserEventGroupsData?.profiles}
+ eventTypeGroups={getUserEventGroupsData?.eventTypeGroups}
+ status={getUserEventGroupsStatus}
+ errorMessage={getUserEventGroupsStatusError?.message}
+ />
);
};
diff --git a/apps/web/pagesAndRewritePaths.js b/apps/web/pagesAndRewritePaths.js
index f34685a7ab1..7c2f1f083be 100644
--- a/apps/web/pagesAndRewritePaths.js
+++ b/apps/web/pagesAndRewritePaths.js
@@ -3,10 +3,12 @@ const { nextJsOrgRewriteConfig } = require("./getNextjsOrgRewriteConfig");
/** Needed to rewrite public booking page, gets all static pages but [user] */
// Pages found here are excluded from redirects in beforeFiles in next.config.js
let pages = (exports.pages = glob
- .sync("{pages,app,app/(use-page-wrapper)}/**/[^_]*.{tsx,js,ts}", { cwd: __dirname })
+ .sync("{pages,app,app/(use-page-wrapper),app/(use-page-wrapper)/(main-nav)}/**/[^_]*.{tsx,js,ts}", {
+ cwd: __dirname,
+ })
.map((filename) =>
filename
- .replace(/^(app\/\(use-page-wrapper\)|pages|app)\//, "")
+ .replace(/^(app\/\(use-page-wrapper\)\/\(main-nav\)|app\/\(use-page-wrapper\)|pages|app)\//, "")
.replace(/(\.tsx|\.js|\.ts)/, "")
.replace(/\/.*/, "")
)
@@ -25,6 +27,8 @@ let pages = (exports.pages = glob
"WithAppDirSsr",
"WithEmbedSSR",
"WithEmbedSSR.test",
+ "ShellMainAppDir",
+ "ShellMainAppDirBackButton",
].some((prefix) => v.startsWith(prefix))
));