11import { CustomI18nProvider } from "app/CustomI18nProvider" ;
22import { withAppDirSsr } from "app/WithAppDirSsr" ;
3- import type { PageProps , SearchParams } from "app/_types" ;
3+ import type { PageProps , Params , SearchParams } from "app/_types" ;
44import { generateMeetingMetadata } from "app/_utils" ;
55import { cookies , headers } from "next/headers" ;
66
@@ -15,20 +15,34 @@ import { getServerSideProps } from "@lib/team/[slug]/[type]/getServerSideProps";
1515import LegacyPage from "~/team/type-view" ;
1616import type { PageProps as LegacyPageProps } from "~/team/type-view" ;
1717
18- import CachedTeamBooker , { generateMetadata as generateCachedMetadata } from "./pageWithCachedData" ;
18+ import CachedTeamBooker , {
19+ generateMetadata as generateCachedMetadata ,
20+ getOrgContext ,
21+ } from "./pageWithCachedData" ;
22+ import { getTeamId } from "./queries" ;
23+
24+ async function isCachedTeamBookingEnabled ( params : Params , searchParams : SearchParams ) : Promise < boolean > {
25+ if ( searchParams . experimentalTeamBookingPageCache !== "true" ) return false ;
26+
27+ const { teamSlug, currentOrgDomain, isValidOrgDomain } = await getOrgContext ( params ) ;
28+ const orgSlug = isValidOrgDomain ? currentOrgDomain : null ;
29+ const teamId = await getTeamId ( teamSlug , orgSlug ) ;
30+
31+ if ( ! teamId ) return false ;
1932
20- async function isCachedTeamBookingEnabled ( searchParams : SearchParams ) : Promise < boolean > {
2133 const featuresRepository = new FeaturesRepository ( prisma ) ;
22- const isGloballyEnabled = await featuresRepository . checkIfFeatureIsEnabledGlobally (
34+ const isTeamFeatureEnabled = await featuresRepository . checkIfTeamHasFeature (
35+ teamId ,
2336 "team-booking-page-cache"
2437 ) ;
25- return isGloballyEnabled && searchParams . experimentalTeamBookingPageCache === "true" ;
38+ return isTeamFeatureEnabled ;
2639}
2740
2841export const generateMetadata = async ( { params, searchParams } : PageProps ) => {
29- if ( await isCachedTeamBookingEnabled ( await searchParams ) ) {
42+ if ( await isCachedTeamBookingEnabled ( await params , await searchParams ) ) {
3043 return await generateCachedMetadata ( { params, searchParams } ) ;
3144 }
45+
3246 const legacyCtx = buildLegacyCtx ( await headers ( ) , await cookies ( ) , await params , await searchParams ) ;
3347 const props = await getData ( legacyCtx ) ;
3448 const { booking, isSEOIndexable, eventData, isBrandingHidden } = props ;
@@ -68,7 +82,7 @@ export const generateMetadata = async ({ params, searchParams }: PageProps) => {
6882const getData = withAppDirSsr < LegacyPageProps > ( getServerSideProps ) ;
6983
7084const ServerPage = async ( { params, searchParams } : PageProps ) => {
71- if ( await isCachedTeamBookingEnabled ( await searchParams ) ) {
85+ if ( await isCachedTeamBookingEnabled ( await params , await searchParams ) ) {
7286 return await CachedTeamBooker ( { params, searchParams } ) ;
7387 }
7488
0 commit comments