Merged in feature/refactor-lang (pull request #387)

feat: SW-238 Avoid prop drilling of lang

Approved-by: Michael Zetterberg
This commit is contained in:
Niclas Edenvin
2024-08-14 11:00:20 +00:00
parent 35128dbf44
commit e67212bd94
94 changed files with 378 additions and 322 deletions

View File

@@ -4,6 +4,7 @@ import { serverClient } from "@/lib/trpc/server"
import AccountPage from "@/components/ContentType/Webviews/AccountPage"
import LoyaltyPage from "@/components/ContentType/Webviews/LoyaltyPage"
import { getLang, setLang } from "@/i18n/serverContext"
import {
ContentTypeWebviewParams,
@@ -15,6 +16,7 @@ import {
export default async function ContentTypePage({
params,
}: PageArgs<LangParams & ContentTypeWebviewParams & UIDParams, {}>) {
setLang(params.lang)
const user = await serverClient().user.get()
if (!user) {
@@ -26,15 +28,15 @@ export default async function ContentTypePage({
case "unauthorized": // fall through
case "forbidden": // fall through
case "token_expired":
redirect(`/${params.lang}/webview/refresh`)
redirect(`/${getLang()}/webview/refresh`)
}
}
switch (params.contentType) {
case "loyalty-page":
return <LoyaltyPage lang={params.lang} />
return <LoyaltyPage />
case "account-page":
return <AccountPage lang={params.lang} />
return <AccountPage />
default:
const type: never = params.contentType
console.error(`Unsupported content type given: ${type}`)

View File

@@ -8,6 +8,7 @@ import TrpcProvider from "@/lib/trpc/Provider"
import AdobeSDKScript from "@/components/Current/AdobeSDKScript"
import { getIntl } from "@/i18n"
import ServerIntlProvider from "@/i18n/Provider"
import { getLang, setLang } from "@/i18n/serverContext"
import styles from "./layout.module.css"
@@ -23,9 +24,11 @@ export default async function RootLayout({
children,
params,
}: React.PropsWithChildren<LayoutArgs<LangParams>>) {
setLang(params.lang)
const { defaultLocale, locale, messages } = await getIntl()
return (
<html lang={params.lang}>
<html lang={getLang()}>
<head>
<AdobeSDKScript />
<Script id="ensure-adobeDataLayer">{`
@@ -34,7 +37,7 @@ export default async function RootLayout({
</head>
<body className={styles.layout}>
<ServerIntlProvider intl={{ defaultLocale, locale, messages }}>
<TrpcProvider lang={params.lang}>{children}</TrpcProvider>
<TrpcProvider>{children}</TrpcProvider>
</ServerIntlProvider>
</body>
</html>

View File

@@ -1,8 +1,13 @@
import LoadingSpinner from "@/components/LoadingSpinner"
import { setLang } from "@/i18n/serverContext"
import styles from "./page.module.css"
export default function Refresh() {
import { LangParams, PageArgs } from "@/types/params"
export default function Refresh({ params }: PageArgs<LangParams>) {
setLang(params.lang)
return (
<div className={styles.container}>
<LoadingSpinner />