Skip to content

perf: server side render settings/organizations/general #20833

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

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
755a5c0
fix: trigger lingo.dev by removing duplicate value
retrogtx Apr 1, 2025
2b8e944
Merge branch 'calcom:main' into main
retrogtx Apr 1, 2025
eb090a1
Merge branch 'calcom:main' into main
retrogtx Apr 3, 2025
7bfe71f
Merge branch 'calcom:main' into main
retrogtx Apr 3, 2025
6b8b832
Merge branch 'calcom:main' into main
retrogtx Apr 3, 2025
00942e6
Merge branch 'calcom:main' into main
retrogtx Apr 3, 2025
d6dda16
Merge branch 'calcom:main' into main
retrogtx Apr 4, 2025
0c43f23
Merge branch 'calcom:main' into main
retrogtx Apr 4, 2025
5374610
Merge branch 'calcom:main' into main
retrogtx Apr 5, 2025
c3e016d
Merge branch 'calcom:main' into main
retrogtx Apr 7, 2025
3612d5a
Merge branch 'calcom:main' into main
retrogtx Apr 8, 2025
1147eb4
Merge branch 'calcom:main' into main
retrogtx Apr 9, 2025
e79dd41
Merge branch 'calcom:main' into main
retrogtx Apr 10, 2025
f10db66
Merge branch 'calcom:main' into main
retrogtx Apr 13, 2025
9ccfe56
Merge branch 'calcom:main' into main
retrogtx Apr 16, 2025
1deb555
Merge branch 'calcom:main' into main
retrogtx Apr 17, 2025
9b7a291
Merge branch 'calcom:main' into main
retrogtx Apr 17, 2025
61a3892
Merge branch 'calcom:main' into main
retrogtx Apr 22, 2025
83cd391
Merge branch 'calcom:main' into main
retrogtx Apr 22, 2025
8b4b249
Merge branch 'calcom:main' into main
retrogtx Apr 23, 2025
f558326
feat: Enhance organization settings page with server-side session han…
retrogtx Apr 23, 2025
b8740bd
refactor: Optimize data fetching in organization settings page
retrogtx Apr 23, 2025
ceea74d
refactor: use util createRouterCaller as benny suggested
retrogtx Apr 24, 2025
4ed1f60
add skeleton and loading state
retrogtx Apr 24, 2025
d933f26
refactor: Consolidate organization settings page structure and remove…
retrogtx Apr 25, 2025
5ba8d46
refactor: Remove Suspense loading wrapper from organization settings …
retrogtx Apr 25, 2025
cdbc6df
fix: Update redirection path when no organisation is found
retrogtx Apr 27, 2025
3c5332d
add back Suspense loading wrapper in SettingsHeader
retrogtx Apr 27, 2025
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,7 +1,15 @@
import { _generateMetadata, getTranslate } from "app/_utils";
import { headers, cookies } from "next/headers";
import { redirect } from "next/navigation";

import { checkAdminOrOwner } from "@calcom/features/auth/lib/checkAdminOrOwner";
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
import LegacyPage from "@calcom/features/ee/organizations/pages/settings/general";
import SettingsHeader from "@calcom/features/settings/appDir/SettingsHeader";
import { createContextInner } from "@calcom/trpc/server/createContext";
import { appRouter } from "@calcom/trpc/server/routers/_app";

import { buildLegacyRequest } from "@lib/buildLegacyCtx";

export const generateMetadata = async () =>
await _generateMetadata(
Expand All @@ -13,11 +21,31 @@ export const generateMetadata = async () =>
);

const Page = async () => {
const t = await getTranslate();
const req = buildLegacyRequest(await headers(), await cookies());
const [t, session] = await Promise.all([getTranslate(), getServerSession({ req })]);

if (!session?.user?.id) {
redirect("/auth/login");
}

const ctx = await createContextInner({ session, locale: session.user.locale ?? "en" });
const caller = appRouter.createCaller(ctx);

const [user, currentOrg] = await Promise.all([
caller.viewer.me.get(),
caller.viewer.organizations.listCurrent(),
]);

if (!currentOrg) {
redirect("/getting-started");
}

const isAdminOrOwner = checkAdminOrOwner(session.user.org?.role);
const localeProp = user?.locale ?? "en";
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't this available from session.user? please check that and if not, use getLocale function as I mentioned above


return (
<SettingsHeader title={t("general")} description={t("general_description")} borderInShellHeader={true}>
<LegacyPage />
<LegacyPage currentOrg={currentOrg} isAdminOrOwner={isAdminOrOwner} localeProp={localeProp} />
</SettingsHeader>
);
};
Expand Down
46 changes: 11 additions & 35 deletions packages/features/ee/organizations/pages/settings/general.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
"use client";

import { useSession } from "next-auth/react";
import { useRouter } from "next/navigation";
import { useEffect } from "react";
import { Controller, useForm } from "react-hook-form";

import { checkAdminOrOwner } from "@calcom/features/auth/lib/checkAdminOrOwner";
import { TimezoneSelect } from "@calcom/features/components/timezone-select";
import LicenseRequired from "@calcom/features/ee/common/components/LicenseRequired";
import SectionBottomActions from "@calcom/features/settings/SectionBottomActions";
Expand Down Expand Up @@ -45,43 +42,22 @@ interface GeneralViewProps {
localeProp: string;
}

const OrgGeneralView = () => {
interface OrgGeneralViewProps {
currentOrg: NonNullable<RouterOutputs["viewer"]["organizations"]["listCurrent"]>;
Copy link
Contributor

Choose a reason for hiding this comment

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

NonNullable - love it

isAdminOrOwner: boolean;
localeProp: string;
}

const OrgGeneralView = ({ currentOrg, isAdminOrOwner, localeProp }: OrgGeneralViewProps) => {
const { t } = useLocale();
const router = useRouter();
const session = useSession();
const isAdminOrOwner = checkAdminOrOwner(session.data?.user?.org?.role);

const {
data: currentOrg,
isPending,
error,
} = trpc.viewer.organizations.listCurrent.useQuery(undefined, {});
const { data: user } = trpc.viewer.me.get.useQuery();

useEffect(
function refactorMeWithoutEffect() {
if (error) {
router.replace("/enterprise");
}
},
[error]
);

if (isPending) return <SkeletonLoader />;
if (!currentOrg) {
return null;
}

return (
<LicenseRequired>
<GeneralView
currentOrg={currentOrg}
isAdminOrOwner={isAdminOrOwner}
localeProp={user?.locale ?? "en"}
/>

<LockEventTypeSwitch currentOrg={currentOrg} isAdminOrOwner={!!isAdminOrOwner} />
<NoSlotsNotificationSwitch currentOrg={currentOrg} isAdminOrOwner={!!isAdminOrOwner} />
<GeneralView currentOrg={currentOrg} isAdminOrOwner={isAdminOrOwner} localeProp={localeProp} />

<LockEventTypeSwitch currentOrg={currentOrg} isAdminOrOwner={isAdminOrOwner} />
<NoSlotsNotificationSwitch currentOrg={currentOrg} isAdminOrOwner={isAdminOrOwner} />
</LicenseRequired>
);
};
Expand Down
Loading