perf: server-fetch data for all pages in /settings/my-account (#20712)
* wip * fix type check * refactor "/settings/my-account/profile" * refactor "settings/my-account/general" * refactor "/settings/my-accouunt/calendars" * refactor "/settings/my-account/appearance" * fix: type-check --------- Co-authored-by: Amit Sharma <[email protected]> Co-authored-by: Amit Sharma <[email protected]>
This commit is contained in:
32 files changed
+721
-524
No files matched your search
@@ -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";
|
||||
|
||||
@@ -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;
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
"use server";
|
||||
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
export async function revalidateSettingsAppearance() {
|
||||
revalidatePath("/settings/my-account/appearance");
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import { SkeletonLoader } from "~/settings/my-account/appearance-skeleton";
|
||||
|
||||
export default function Loading() {
|
||||
return <SkeletonLoader />;
|
||||
}
|
||||
+32
-8
@@ -1,7 +1,15 @@
|
||||
import { createRouterCaller } from "app/_trpc/context";
|
||||
import { _generateMetadata } from "app/_utils";
|
||||
import { getTranslate } from "app/_utils";
|
||||
import { cookies, headers } from "next/headers";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import SettingsHeader from "@calcom/features/settings/appDir/SettingsHeader";
|
||||
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
||||
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 { getCachedHasTeamPlan } from "@calcom/web/app/cache/membership";
|
||||
|
||||
import { buildLegacyRequest } from "@lib/buildLegacyCtx";
|
||||
|
||||
import AppearancePage from "~/settings/my-account/appearance-view";
|
||||
|
||||
@@ -15,13 +23,29 @@ export const generateMetadata = async () =>
|
||||
);
|
||||
|
||||
const Page = async () => {
|
||||
const t = await getTranslate();
|
||||
const session = await getServerSession({ req: buildLegacyRequest(await headers(), await cookies()) });
|
||||
const userId = session?.user?.id;
|
||||
const redirectUrl = "/auth/login?callbackUrl=/settings/my-account/appearance";
|
||||
|
||||
return (
|
||||
<SettingsHeader title={t("appearance")} description={t("appearance_description")}>
|
||||
<AppearancePage />
|
||||
</SettingsHeader>
|
||||
);
|
||||
if (!userId) {
|
||||
redirect(redirectUrl);
|
||||
}
|
||||
|
||||
const [meCaller, hasTeamPlan] = await Promise.all([
|
||||
createRouterCaller(meRouter),
|
||||
getCachedHasTeamPlan(userId),
|
||||
]);
|
||||
|
||||
const user = await meCaller.get();
|
||||
|
||||
if (!user) {
|
||||
redirect(redirectUrl);
|
||||
}
|
||||
const isCurrentUsernamePremium =
|
||||
user && hasKeyInMetadata(user, "isPremium") ? !!user.metadata.isPremium : false;
|
||||
const hasPaidPlan = IS_SELF_HOSTED ? true : hasTeamPlan?.hasTeamPlan || isCurrentUsernamePremium;
|
||||
|
||||
return <AppearancePage user={user} hasPaidPlan={hasPaidPlan} />;
|
||||
};
|
||||
|
||||
export default Page;
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import { CalendarListContainerSkeletonLoader } from "@components/apps/CalendarListContainer";
|
||||
|
||||
export default function Loading() {
|
||||
return <CalendarListContainerSkeletonLoader />;
|
||||
}
|
||||
+13
-20
@@ -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";
|
||||
|
||||
@@ -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} />
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
+1
-10
@@ -1,5 +1,4 @@
|
||||
import { _generateMetadata } from "app/_utils";
|
||||
import { getTranslate } from "app/_utils";
|
||||
|
||||
import { ConferencingAppsViewWebWrapper } from "@calcom/atoms/connect/conferencing-apps/ConferencingAppsViewWebWrapper";
|
||||
|
||||
@@ -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;
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
"use server";
|
||||
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
export async function revalidateSettingsGeneral() {
|
||||
revalidatePath("/settings/my-account/general");
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import { SkeletonLoader } from "~/settings/my-account/general-skeleton";
|
||||
|
||||
export default function Loading() {
|
||||
return <SkeletonLoader />;
|
||||
}
|
||||
+22
-14
@@ -1,10 +1,15 @@
|
||||
import { createRouterCaller } from "app/_trpc/context";
|
||||
import { _generateMetadata } from "app/_utils";
|
||||
import { getTranslate } from "app/_utils";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { cookies, headers } from "next/headers";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import SettingsHeader from "@calcom/features/settings/appDir/SettingsHeader";
|
||||
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
||||
import { meRouter } from "@calcom/trpc/server/routers/viewer/me/_router";
|
||||
import { getTravelSchedule } from "@calcom/web/app/cache/travelSchedule";
|
||||
|
||||
import GeneralQueryView from "~/settings/my-account/general-view";
|
||||
import { buildLegacyRequest } from "@lib/buildLegacyCtx";
|
||||
|
||||
import GeneralView from "~/settings/my-account/general-view";
|
||||
|
||||
export const generateMetadata = async () =>
|
||||
await _generateMetadata(
|
||||
@@ -16,17 +21,20 @@ export const generateMetadata = async () =>
|
||||
);
|
||||
|
||||
const Page = async () => {
|
||||
const t = await getTranslate();
|
||||
const revalidatePage = async () => {
|
||||
"use server";
|
||||
revalidatePath("settings/my-account/general");
|
||||
};
|
||||
const session = await getServerSession({ req: buildLegacyRequest(await headers(), await cookies()) });
|
||||
const userId = session?.user?.id;
|
||||
const redirectUrl = "/auth/login?callbackUrl=/settings/my-account/general";
|
||||
|
||||
return (
|
||||
<SettingsHeader title={t("general")} description={t("general_description")} borderInShellHeader={true}>
|
||||
<GeneralQueryView revalidatePage={revalidatePage} />
|
||||
</SettingsHeader>
|
||||
);
|
||||
if (!userId) {
|
||||
return redirect(redirectUrl);
|
||||
}
|
||||
|
||||
const meCaller = await createRouterCaller(meRouter);
|
||||
const [user, travelSchedules] = await Promise.all([meCaller.get(), getTravelSchedule(userId)]);
|
||||
if (!user) {
|
||||
redirect(redirectUrl);
|
||||
}
|
||||
return <GeneralView user={user} travelSchedules={travelSchedules ?? []} />;
|
||||
};
|
||||
|
||||
export default Page;
|
||||
+2
-20
@@ -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(
|
||||
@@ -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;
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import { SkeletonLoader } from "~/settings/my-account/profile-skeleton";
|
||||
|
||||
export default function Loading() {
|
||||
return <SkeletonLoader />;
|
||||
}
|
||||
+9
-12
@@ -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";
|
||||
|
||||
@@ -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;
|
||||
+2
-14
@@ -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 () =>
|
||||
@@ -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;
|
||||
Vendored
+27
@@ -0,0 +1,27 @@
|
||||
"use server";
|
||||
|
||||
import { revalidateTag, unstable_cache } from "next/cache";
|
||||
|
||||
import { NEXTJS_CACHE_TTL } from "@calcom/lib/constants";
|
||||
import { MembershipRepository } from "@calcom/lib/server/repository/membership";
|
||||
|
||||
const CACHE_TAGS = {
|
||||
HAS_TEAM_PLAN: "MembershipRepository.findFirstAcceptedMembershipByUserId",
|
||||
} as const;
|
||||
|
||||
export const getCachedHasTeamPlan = unstable_cache(
|
||||
async (userId: number) => {
|
||||
const hasTeamPlan = await MembershipRepository.findFirstAcceptedMembershipByUserId(userId);
|
||||
|
||||
return { hasTeamPlan: !!hasTeamPlan };
|
||||
},
|
||||
["getCachedHasTeamPlan"],
|
||||
{
|
||||
revalidate: NEXTJS_CACHE_TTL,
|
||||
tags: [CACHE_TAGS.HAS_TEAM_PLAN],
|
||||
}
|
||||
);
|
||||
|
||||
export const revalidateHasTeamPlan = async () => {
|
||||
revalidateTag(CACHE_TAGS.HAS_TEAM_PLAN);
|
||||
};
|
||||
@@ -0,0 +1,11 @@
|
||||
"use server";
|
||||
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
export async function revalidateSettingsProfile() {
|
||||
revalidatePath("/settings/my-account/profile");
|
||||
}
|
||||
|
||||
export async function revalidateSettingsCalendars() {
|
||||
revalidatePath("/settings/my-account/calendars");
|
||||
}
|
||||
Vendored
+26
@@ -0,0 +1,26 @@
|
||||
"use server";
|
||||
|
||||
import { revalidateTag } from "next/cache";
|
||||
|
||||
import { NEXTJS_CACHE_TTL } from "@calcom/lib/constants";
|
||||
import { TravelScheduleRepository } from "@calcom/lib/server/repository/travelSchedule";
|
||||
import { unstable_cache } from "@calcom/lib/unstable_cache";
|
||||
|
||||
const CACHE_TAGS = {
|
||||
TRAVEL_SCHEDULES: "TravelRepository.findTravelSchedulesByUserId",
|
||||
} as const;
|
||||
|
||||
export const getTravelSchedule = unstable_cache(
|
||||
async (userId: number) => {
|
||||
return await TravelScheduleRepository.findTravelSchedulesByUserId(userId);
|
||||
},
|
||||
["getTravelSchedule"],
|
||||
{
|
||||
revalidate: NEXTJS_CACHE_TTL,
|
||||
tags: [CACHE_TAGS.TRAVEL_SCHEDULES],
|
||||
}
|
||||
);
|
||||
|
||||
export const revalidateTravelSchedules = async () => {
|
||||
revalidateTag(CACHE_TAGS.TRAVEL_SCHEDULES);
|
||||
};
|
||||
Reference in new issue
Block a user