Files
web/apps/scandic-web/app/[lang]/(live)/(protected)/my-pages/layout.tsx
Chuma Mcphoy (We Ahead) 2b9bc8c3ce Merged in feat/LOY-497-Flag-Profiling-Consent (pull request #3292)
refactor(LOY-497): hide profiling consent behind feature flag

* refactor(LOY-497): hide profiling consent behind feature flag

* chore(LOY-497): up to date consent readme


Approved-by: Matilda Landström
2025-12-05 05:47:11 +00:00

105 lines
3.1 KiB
TypeScript

import { TrackingSDK } from "@scandic-hotels/tracking/TrackingSDK"
import { getEurobonusMembership } from "@scandic-hotels/trpc/routers/user/helpers"
import { env } from "@/env/server"
import {
getProfileSafely,
getProfilingConsent,
} from "@/lib/trpc/memoizedRequests"
import ProfilingConsentAlert from "@/components/MyPages/ProfilingConsent/Alert"
import { ProfilingConsentAlertProvider } from "@/components/MyPages/ProfilingConsent/Alert/AlertContext"
import ProfilingConsentModal from "@/components/MyPages/ProfilingConsent/Modal"
import { userHasConsent } from "@/components/MyPages/ProfilingConsent/utils"
import { SASLevelUpgradeCheck } from "@/components/MyPages/SASLevelUpgradeCheck"
import Surprises from "@/components/MyPages/Surprises"
import { getLang } from "@/i18n/serverContext"
import { ModalTracking } from "@/utils/tracking/profilingConsent"
import styles from "./layout.module.css"
type MyPagesLayoutProps = React.PropsWithChildren<{
breadcrumbs: React.ReactNode
}>
export default async function MyPagesLayout(props: MyPagesLayoutProps) {
if (env.ENABLE_PROFILE_CONSENT) {
return <MyPagesLayoutWithConsent {...props} />
}
return <MyPagesLayoutBase {...props} />
}
async function MyPagesLayoutWithConsent({
breadcrumbs,
children,
}: MyPagesLayoutProps) {
const profile = await getProfileSafely()
const eurobonusMembership = profile?.loyalty
? getEurobonusMembership(profile.loyalty)
: null
const memberKey =
profile?.membership?.membershipNumber || profile?.profileId || ""
const profilingConsentData = await getProfilingConsent()
const profilingConsent = profilingConsentData?.profiling_consent
const hasConsent = userHasConsent(profile?.profilingConsent)
const lang = await getLang()
const showConsentModal = memberKey && profilingConsent && !hasConsent
return (
<ProfilingConsentAlertProvider>
<div className={styles.container}>
<div className={styles.layout}>
{breadcrumbs}
<div className={styles.content}>
<ProfilingConsentAlert />
{children}
</div>
</div>
{eurobonusMembership && <SASLevelUpgradeCheck />}
<Surprises />
{showConsentModal && (
<>
<ProfilingConsentModal
memberKey={memberKey}
content={profilingConsent.modal}
iconIdentifier={profilingConsent.icon}
/>
<TrackingSDK
pageData={{ domainLanguage: lang, ...ModalTracking }}
/>
</>
)}
</div>
</ProfilingConsentAlertProvider>
)
}
async function MyPagesLayoutBase({
breadcrumbs,
children,
}: MyPagesLayoutProps) {
const profile = await getProfileSafely()
const eurobonusMembership = profile?.loyalty
? getEurobonusMembership(profile.loyalty)
: null
return (
<div className={styles.container}>
<div className={styles.layout}>
{breadcrumbs}
<div className={styles.content}>{children}</div>
</div>
{eurobonusMembership && <SASLevelUpgradeCheck />}
<Surprises />
</div>
)
}