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

* create /(main-nav)/layout.tsx file that uses Shell

* Add ShellMainAppDir that clones ShellMain but with client/server separation

* event-types, availability, bookings

* update pagesAndRewritePaths logic

* fix

---------

Co-authored-by: Peer Richelsen <[email protected]>
This commit is contained in:
Benny JooandPeer Richelsen authored and GitHub committed 2025-01-27 11:08:47 +00:00
1 parent 8be2ea8117
commit ee31633e2b
10 files changed
+213 -102

No files matched your search

@@ -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,6 +212,42 @@ export default function AvailabilityPage({ currentOrg }: PageProps) {
[searchParams]
);
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;
const canViewTeamAvailability = isOrgAdminOrOwner || !isOrgAndPrivate;
const toggleGroupOptions = [{ value: "mine", label: t("my_availability") }];
if (canViewTeamAvailability) {
toggleGroupOptions.push({ value: "team", label: t("team_availability") });
}
return (
<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;
@@ -229,36 +261,9 @@ export default function AvailabilityPage({ currentOrg }: PageProps) {
toggleGroupOptions.push({ value: "team", label: t("team_availability") });
}
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>
return searchParams?.get("type") === "team" && canViewTeamAvailability ? (
<AvailabilitySliderTable userTimeFormat={me?.data?.timeFormat ?? null} isOrg={isOrg} />
) : (
<AvailabilityListWithQuery />
);
}