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:
authored and GitHub committed 2025-07-24 22:36:40 +01:00
1 parent 6259b0b3cb
commit 6b9115dfde
32 files changed
+721 -524

No files matched your search

@@ -23,6 +23,7 @@ import {
DataTableSegment,
} from "@calcom/features/data-table";
import { useSegments } from "@calcom/features/data-table/hooks/useSegments";
import SettingsHeader from "@calcom/features/settings/appDir/SettingsHeader";
import ServerTrans from "@calcom/lib/components/ServerTrans";
import { getUserAvatarUrl } from "@calcom/lib/getAvatarUrl";
import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams";
@@ -39,7 +40,7 @@ import { Tooltip } from "@calcom/ui/components/tooltip";
import CreateNewOutOfOfficeEntryButton from "./CreateNewOutOfOfficeEntryButton";
import { CreateOrEditOutOfOfficeEntryModal } from "./CreateOrEditOutOfOfficeModal";
import type { BookingRedirectForm } from "./CreateOrEditOutOfOfficeModal";
import { OutOfOfficeTab } from "./OutOfOfficeToggleGroup";
import { OutOfOfficeTab, OutOfOfficeToggleGroup } from "./OutOfOfficeToggleGroup";
interface OutOfOfficeEntry {
id: number;
@@ -63,10 +64,22 @@ interface OutOfOfficeEntry {
}
export default function OutOfOfficeEntriesList() {
const { t } = useLocale();
return (
<DataTableProvider useSegments={useSegments}>
<OutOfOfficeEntriesListContent />
</DataTableProvider>
<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>
}>
<DataTableProvider useSegments={useSegments}>
<OutOfOfficeEntriesListContent />
</DataTableProvider>
</SettingsHeader>
);
}
@@ -121,6 +121,20 @@ export class MembershipRepository {
});
}
static async findFirstAcceptedMembershipByUserId(userId: number) {
return await prisma.membership.findFirst({
where: {
accepted: true,
userId,
team: {
slug: {
not: null,
},
},
},
});
}
static async createMany(data: IMembership[]) {
return await prisma.membership.createMany({
data: data.map((item) => ({
+3
View File
@@ -0,0 +1,3 @@
import { cache as unstable_cache } from "./unstable_cache";
export { unstable_cache };
@@ -0,0 +1,24 @@
/**
* This implementation is adapted from https://github.com/vercel/next.js/issues/51613#issuecomment-1892644565.
* It is a wrapper around `unstable_cache` that adds serialization and deserialization
*/
import { unstable_cache } from "next/cache";
import { parse, stringify } from "superjson";
export const cache = <T, P extends unknown[]>(
fn: (...params: P) => Promise<T>,
keys: Parameters<typeof unstable_cache>[1],
opts: Parameters<typeof unstable_cache>[2]
) => {
const wrap = async (params: unknown[]): Promise<string> => {
const result = await fn(...(params as P));
return stringify(result);
};
const cachedFn = unstable_cache(wrap, keys, opts);
return async (...params: P): Promise<T> => {
const result = await cachedFn(params);
return parse(result);
};
};
@@ -12,12 +12,6 @@ import { EmptyScreen } from "@calcom/ui/components/empty-screen";
import { SkeletonText, SkeletonContainer } from "@calcom/ui/components/skeleton";
import { showToast } from "@calcom/ui/components/toast";
type ConferencingAppsViewWebWrapperProps = {
title: string;
description: string;
add: string;
};
export type UpdateUsersDefaultConferencingAppParams = {
appSlug: string;
appLink?: string;
@@ -175,11 +169,17 @@ const useDisconnectIntegrationModalController = () => {
};
};
export const ConferencingAppsViewWebWrapper = ({
title,
description,
add,
}: ConferencingAppsViewWebWrapperProps) => {
const AddConferencingButton = () => {
const { t } = useLocale();
return (
<Button color="secondary" StartIcon="plus" href="/apps/categories/conferencing">
{t("add")}
</Button>
);
};
export const ConferencingAppsViewWebWrapper = () => {
const { t } = useLocale();
const utils = trpc.useUtils();
@@ -203,20 +203,12 @@ export const ConferencingAppsViewWebWrapper = ({
);
};
const AddConferencingButton = () => {
return (
<Button color="secondary" StartIcon="plus" href="/apps/categories/conferencing">
{add}
</Button>
);
};
const disconnectIntegrationModalCtrl = useDisconnectIntegrationModalController();
return (
<SettingsHeader
title={title}
description={description}
title={t("conferencing")}
description={t("conferencing_description")}
CTA={<AddConferencingButton />}
borderInShellHeader={true}>
<>
@@ -1,4 +1,5 @@
import { prisma } from "@calcom/prisma";
import { MembershipRepository } from "@calcom/lib/server/repository/membership";
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
type HasTeamPlanOptions = {
ctx: {
@@ -6,18 +7,11 @@ type HasTeamPlanOptions = {
};
};
export const hasTeamPlanHandler = async ({ ctx: { user } }: HasTeamPlanOptions) => {
const hasTeamPlan = await prisma.membership.findFirst({
where: {
accepted: true,
userId: user.id,
team: {
slug: {
not: null,
},
},
},
});
export const hasTeamPlanHandler = async ({ ctx }: HasTeamPlanOptions) => {
const userId = ctx.user.id;
const hasTeamPlan = await MembershipRepository.findFirstAcceptedMembershipByUserId(userId);
return { hasTeamPlan: !!hasTeamPlan };
};