-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
+110
−57
Closed
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 2b8e944
Merge branch 'calcom:main' into main
retrogtx eb090a1
Merge branch 'calcom:main' into main
retrogtx 7bfe71f
Merge branch 'calcom:main' into main
retrogtx 6b8b832
Merge branch 'calcom:main' into main
retrogtx 00942e6
Merge branch 'calcom:main' into main
retrogtx d6dda16
Merge branch 'calcom:main' into main
retrogtx 0c43f23
Merge branch 'calcom:main' into main
retrogtx 5374610
Merge branch 'calcom:main' into main
retrogtx c3e016d
Merge branch 'calcom:main' into main
retrogtx 3612d5a
Merge branch 'calcom:main' into main
retrogtx 1147eb4
Merge branch 'calcom:main' into main
retrogtx e79dd41
Merge branch 'calcom:main' into main
retrogtx f10db66
Merge branch 'calcom:main' into main
retrogtx 9ccfe56
Merge branch 'calcom:main' into main
retrogtx 1deb555
Merge branch 'calcom:main' into main
retrogtx 9b7a291
Merge branch 'calcom:main' into main
retrogtx 61a3892
Merge branch 'calcom:main' into main
retrogtx 83cd391
Merge branch 'calcom:main' into main
retrogtx 8b4b249
Merge branch 'calcom:main' into main
retrogtx f558326
feat: Enhance organization settings page with server-side session han…
retrogtx b8740bd
refactor: Optimize data fetching in organization settings page
retrogtx ceea74d
refactor: use util createRouterCaller as benny suggested
retrogtx 4ed1f60
add skeleton and loading state
retrogtx d933f26
refactor: Consolidate organization settings page structure and remove…
retrogtx 5ba8d46
refactor: Remove Suspense loading wrapper from organization settings …
retrogtx cdbc6df
fix: Update redirection path when no organisation is found
retrogtx 3c5332d
add back Suspense loading wrapper in SettingsHeader
retrogtx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( | ||
|
@@ -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"); | ||
retrogtx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
const isAdminOrOwner = checkAdminOrOwner(session.user.org?.role); | ||
retrogtx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const localeProp = user?.locale ?? "en"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
return ( | ||
<SettingsHeader title={t("general")} description={t("general_description")} borderInShellHeader={true}> | ||
<LegacyPage /> | ||
<LegacyPage currentOrg={currentOrg} isAdminOrOwner={isAdminOrOwner} localeProp={localeProp} /> | ||
</SettingsHeader> | ||
); | ||
}; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
|
@@ -45,43 +42,22 @@ interface GeneralViewProps { | |
localeProp: string; | ||
} | ||
|
||
const OrgGeneralView = () => { | ||
interface OrgGeneralViewProps { | ||
currentOrg: NonNullable<RouterOutputs["viewer"]["organizations"]["listCurrent"]>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
); | ||
}; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.