Skip to content

perf: server-fetch data for all pages in /settings/my-account #20712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { createRouterCaller } from "app/_trpc/context";
import type { PageProps } from "app/_types";
import { _generateMetadata } from "app/_utils";
import { redirect } from "next/navigation";
import { z } from "zod";

import { AppCategories } from "@calcom/prisma/enums";
import { appsRouter } from "@calcom/trpc/server/routers/viewer/apps/_router";
import { calendarsRouter } from "@calcom/trpc/server/routers/viewer/calendars/_router";

import InstalledApps from "~/apps/installed/[category]/installed-category-view";

Expand All @@ -28,7 +31,24 @@ const InstalledAppsWrapper = async ({ params }: PageProps) => {
redirect("/apps/installed/calendar");
}

return <InstalledApps category={parsedParams.data.category} />;
const [calendarsCaller, appsCaller] = await Promise.all([
createRouterCaller(calendarsRouter),
createRouterCaller(appsRouter),
]);

const connectedCalendars = await calendarsCaller.connectedCalendars();
const installedCalendars = await appsCaller.integrations({
variant: "calendar",
onlyInstalled: true,
});

return (
<InstalledApps
connectedCalendars={connectedCalendars}
installedCalendars={installedCalendars}
category={parsedParams.data.category}
/>
);
};

export default InstalledAppsWrapper;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"use server";

import { revalidatePath } from "next/cache";

export async function revalidateSettingsAppearance() {
revalidatePath("/settings/my-account/appearance");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { SkeletonLoader } from "~/settings/my-account/appearance-skeleton";

export default function Loading() {
return <SkeletonLoader />;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { createRouterCaller } from "app/_trpc/context";
import { _generateMetadata } from "app/_utils";
import { getTranslate } from "app/_utils";
import { redirect } from "next/navigation";

import SettingsHeader from "@calcom/features/settings/appDir/SettingsHeader";
import { IS_SELF_HOSTED } from "@calcom/lib/constants";
import hasKeyInMetadata from "@calcom/lib/hasKeyInMetadata";
import { meRouter } from "@calcom/trpc/server/routers/viewer/me/_router";
import { viewerTeamsRouter } from "@calcom/trpc/server/routers/viewer/teams/_router";

import AppearancePage from "~/settings/my-account/appearance-view";

Expand All @@ -15,13 +19,23 @@ export const generateMetadata = async () =>
);

const Page = async () => {
const t = await getTranslate();
const [meCaller, teamsCaller] = await Promise.all([
createRouterCaller(meRouter),
createRouterCaller(viewerTeamsRouter),
]);

return (
<SettingsHeader title={t("appearance")} description={t("appearance_description")}>
<AppearancePage />
</SettingsHeader>
);
const user = await meCaller.get();

if (!user) {
redirect("/auth/login");
}
const isCurrentUsernamePremium =
user && hasKeyInMetadata(user, "isPremium") ? !!user.metadata.isPremium : false;
const hasPaidPlan = IS_SELF_HOSTED
? true
: (await teamsCaller.hasTeamPlan())?.hasTeamPlan || isCurrentUsernamePremium;

return <AppearancePage user={user} hasPaidPlan={hasPaidPlan} />;
};

export default Page;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"use server";

import { revalidatePath } from "next/cache";

export async function revalidateSettingsCalendars() {
revalidatePath("/settings/my-account/calendars");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { CalendarListContainerSkeletonLoader } from "@components/apps/CalendarListContainer";

export default function Loading() {
return <CalendarListContainerSkeletonLoader />;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { createRouterCaller } from "app/_trpc/context";
import { _generateMetadata } from "app/_utils";
import { getTranslate } from "app/_utils";

import SettingsHeader from "@calcom/features/settings/appDir/SettingsHeader";
import { Button } from "@calcom/ui/components/button";
import { appsRouter } from "@calcom/trpc/server/routers/viewer/apps/_router";
import { calendarsRouter } from "@calcom/trpc/server/routers/viewer/calendars/_router";

import { CalendarListContainer } from "@components/apps/CalendarListContainer";

Expand All @@ -16,25 +16,18 @@ export const generateMetadata = async () =>
);

const Page = async () => {
const t = await getTranslate();

const AddCalendarButton = () => {
return (
<>
<Button color="secondary" StartIcon="plus" href="/apps/categories/calendar">
{t("add_calendar")}
</Button>
</>
);
};
const [calendarsCaller, appsCaller] = await Promise.all([
createRouterCaller(calendarsRouter),
createRouterCaller(appsRouter),
]);

const connectedCalendars = await calendarsCaller.connectedCalendars();
const installedCalendars = await appsCaller.integrations({
variant: "calendar",
onlyInstalled: true,
});
return (
<SettingsHeader
title={t("calendars")}
description={t("calendars_description")}
CTA={<AddCalendarButton />}>
<CalendarListContainer />
</SettingsHeader>
<CalendarListContainer connectedCalendars={connectedCalendars} installedCalendars={installedCalendars} />
);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { _generateMetadata } from "app/_utils";
import { getTranslate } from "app/_utils";

import { ConferencingAppsViewWebWrapper } from "@calcom/atoms/connect/conferencing-apps/ConferencingAppsViewWebWrapper";

Expand All @@ -13,15 +12,7 @@ export const generateMetadata = async () =>
);

const Page = async () => {
const t = await getTranslate();

return (
<ConferencingAppsViewWebWrapper
title={t("conferencing")}
description={t("conferencing_description")}
add={t("add")}
/>
);
return <ConferencingAppsViewWebWrapper />;
};

export default Page;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"use server";

import { revalidatePath } from "next/cache";

export async function revalidateSettingsGeneral() {
revalidatePath("/settings/my-account/general");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { SkeletonLoader } from "~/settings/my-account/general-skeleton";

export default function Loading() {
return <SkeletonLoader />;
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { createRouterCaller } from "app/_trpc/context";
import { _generateMetadata } from "app/_utils";
import { getTranslate } from "app/_utils";
import { revalidatePath } from "next/cache";
import { redirect } from "next/navigation";

import SettingsHeader from "@calcom/features/settings/appDir/SettingsHeader";
import { meRouter } from "@calcom/trpc/server/routers/viewer/me/_router";
import { travelSchedulesRouter } from "@calcom/trpc/server/routers/viewer/travelSchedules/_router";

import GeneralQueryView from "~/settings/my-account/general-view";
import GeneralView from "~/settings/my-account/general-view";

export const generateMetadata = async () =>
await _generateMetadata(
Expand All @@ -16,17 +17,15 @@ export const generateMetadata = async () =>
);

const Page = async () => {
const t = await getTranslate();
const revalidatePage = async () => {
"use server";
revalidatePath("settings/my-account/general");
};

return (
<SettingsHeader title={t("general")} description={t("general_description")} borderInShellHeader={true}>
<GeneralQueryView revalidatePage={revalidatePage} />
</SettingsHeader>
);
const [meCaller, travelSchedulesCaller] = await Promise.all([
createRouterCaller(meRouter),
createRouterCaller(travelSchedulesRouter),
]);
const [user, travelSchedules] = await Promise.all([meCaller.get(), travelSchedulesCaller.get()]);
if (!user) {
redirect("/auth/login");
}
return <GeneralView user={user} travelSchedules={travelSchedules ?? []} />;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Component no longer uses SettingsHeader which affects UI consistency across settings pages

};

export default Page;
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { _generateMetadata } from "app/_utils";
import { getTranslate } from "app/_utils";

import SettingsHeader from "@calcom/features/settings/appDir/SettingsHeader";
import CreateNewOutOfOfficeEntryButton from "@calcom/features/settings/outOfOffice/CreateNewOutOfOfficeEntryButton";
import OutOfOfficeEntriesList from "@calcom/features/settings/outOfOffice/OutOfOfficeEntriesList";
import { OutOfOfficeToggleGroup } from "@calcom/features/settings/outOfOffice/OutOfOfficeToggleGroup";

export const generateMetadata = async () =>
await _generateMetadata(
Expand All @@ -15,22 +11,8 @@ export const generateMetadata = async () =>
"/settings/my-account/out-of-office"
);

const Page = async () => {
const t = await getTranslate();

return (
<SettingsHeader
title={t("out_of_office")}
description={t("out_of_office_description")}
CTA={
<div className="flex gap-2">
<OutOfOfficeToggleGroup />
<CreateNewOutOfOfficeEntryButton data-testid="add_entry_ooo" />
</div>
}>
<OutOfOfficeEntriesList />
</SettingsHeader>
);
const Page = () => {
return <OutOfOfficeEntriesList />;
};

export default Page;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"use server";

import { revalidatePath } from "next/cache";

export async function revalidateSettingsProfile() {
revalidatePath("/settings/my-account/profile");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { SkeletonLoader } from "~/settings/my-account/profile-skeleton";

export default function Loading() {
return <SkeletonLoader />;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { createRouterCaller } from "app/_trpc/context";
import { _generateMetadata } from "app/_utils";
import { getTranslate } from "app/_utils";
import { redirect } from "next/navigation";

import SettingsHeader from "@calcom/features/settings/appDir/SettingsHeader";
import { APP_NAME } from "@calcom/lib/constants";
import { meRouter } from "@calcom/trpc/server/routers/viewer/me/_router";

import ProfileView from "~/settings/my-account/profile-view";

Expand All @@ -16,16 +16,13 @@ export const generateMetadata = async () =>
);

const Page = async () => {
const t = await getTranslate();
const meCaller = await createRouterCaller(meRouter);
const user = await meCaller.get({ includePasswordAdded: true });
if (!user) {
redirect("/auth/login");
}

return (
<SettingsHeader
title={t("profile")}
description={t("profile_description", { appName: APP_NAME })}
borderInShellHeader={true}>
<ProfileView />
</SettingsHeader>
);
return <ProfileView user={user} />;
};

export default Page;
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { getTranslate } from "app/_utils";
import { _generateMetadata } from "app/_utils";

import SettingsHeader from "@calcom/features/settings/appDir/SettingsHeader";

import PushNotificationsView from "~/settings/my-account/push-notifications-view";

export const generateMetadata = async () =>
Expand All @@ -14,17 +11,8 @@ export const generateMetadata = async () =>
"/settings/my-account/push-notifications"
);

const Page = async () => {
const t = await getTranslate();

return (
<SettingsHeader
title={t("push_notifications")}
description={t("push_notifications_description")}
borderInShellHeader={true}>
<PushNotificationsView />
</SettingsHeader>
);
const Page = () => {
return <PushNotificationsView />;
};

export default Page;
Loading
Loading