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:
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 />
|
||||
);
|
||||
}
|
||||
@@ -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}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user