Merged in feat/sw-3197-add-url-to-path (pull request #2577)
feat(SW-3197): Add required middleware and url to path in partner-sas * Add url to path and required middleware Approved-by: Matilda Landström
This commit is contained in:
27
apps/partner-sas/app/[lang]/ClientComponent.tsx
Normal file
27
apps/partner-sas/app/[lang]/ClientComponent.tsx
Normal file
@@ -0,0 +1,27 @@
|
||||
/* eslint-disable formatjs/no-literal-string-in-jsx */
|
||||
"use client"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { Lang } from "@scandic-hotels/common/constants/language"
|
||||
import { trpc } from "@scandic-hotels/trpc/client"
|
||||
|
||||
export function ClientComponent() {
|
||||
const intl = useIntl()
|
||||
const { data, isLoading } = trpc.autocomplete.destinations.useQuery({
|
||||
lang: Lang.en,
|
||||
includeTypes: ["hotels"],
|
||||
query: "Malmö",
|
||||
})
|
||||
|
||||
return (
|
||||
<div>
|
||||
<p>client component</p>
|
||||
<p>Data: {JSON.stringify(data?.hits?.hotels[0]?.name)}</p>
|
||||
<p>Is loading: {isLoading ? "Yes" : "No"}</p>
|
||||
<p>Translated text: </p>
|
||||
{intl.formatMessage({
|
||||
defaultMessage: "All-day breakfast",
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
56
apps/partner-sas/app/[lang]/layout.tsx
Normal file
56
apps/partner-sas/app/[lang]/layout.tsx
Normal file
@@ -0,0 +1,56 @@
|
||||
import "@scandic-hotels/design-system/style.css"
|
||||
import "@scandic-hotels/design-system/fonts.css"
|
||||
import "@/public/_static/css/design-system-new-deprecated.css"
|
||||
|
||||
import { Lang } from "@scandic-hotels/common/constants/language"
|
||||
import { TrpcProvider } from "@scandic-hotels/trpc/Provider"
|
||||
|
||||
import { getMessages } from "@/i18n"
|
||||
import ClientIntlProvider from "@/i18n/Provider"
|
||||
import { setLang } from "@/i18n/serverContext"
|
||||
|
||||
import type { Metadata } from "next"
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Create Next App",
|
||||
description: "Generated by create next app",
|
||||
}
|
||||
|
||||
type LangParams = {
|
||||
lang: Lang
|
||||
}
|
||||
|
||||
type RootLayoutProps = {
|
||||
children: React.ReactNode
|
||||
params: Promise<LangParams>
|
||||
}
|
||||
|
||||
export default async function RootLayout(props: RootLayoutProps) {
|
||||
const params = await props.params
|
||||
|
||||
const { children } = props
|
||||
|
||||
setLang(params.lang)
|
||||
const messages = await getMessages(params.lang)
|
||||
|
||||
return (
|
||||
<html lang="en">
|
||||
<head>
|
||||
{/* eslint-disable-next-line @next/next/no-css-tags */}
|
||||
<link rel="stylesheet" href="/_static/css/core.css" />
|
||||
{/* eslint-disable-next-line @next/next/no-css-tags */}
|
||||
<link rel="stylesheet" href="/_static/css/scandic.css" />
|
||||
</head>
|
||||
<body className="scandic">
|
||||
<ClientIntlProvider
|
||||
defaultLocale={Lang.en}
|
||||
locale={params.lang}
|
||||
messages={messages}
|
||||
>
|
||||
{/* TODO handle onError */}
|
||||
<TrpcProvider>{children}</TrpcProvider>
|
||||
</ClientIntlProvider>
|
||||
</body>
|
||||
</html>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
export default function NotFoundPage() {
|
||||
// eslint-disable-next-line formatjs/no-literal-string-in-jsx
|
||||
return <div>Not found, forgot lang in url?</div>
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
.layout {
|
||||
font-family: var(--typography-Body-Regular-fontFamily);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import styles from "./page.module.css"
|
||||
|
||||
import type { Lang } from "@scandic-hotels/common/constants/language"
|
||||
|
||||
export default async function MiddlewareError(props: {
|
||||
params: Promise<{ lang: Lang; status: string }>
|
||||
}) {
|
||||
const params = await props.params
|
||||
|
||||
return (
|
||||
// eslint-disable-next-line formatjs/no-literal-string-in-jsx
|
||||
<div className={styles.layout}>
|
||||
Middleware error {params.lang} {params.status}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
4
apps/partner-sas/app/[lang]/not-found.tsx
Normal file
4
apps/partner-sas/app/[lang]/not-found.tsx
Normal file
@@ -0,0 +1,4 @@
|
||||
export default function NotFoundPage() {
|
||||
// eslint-disable-next-line formatjs/no-literal-string-in-jsx
|
||||
return <div>Not Found, missing lang in url?</div>
|
||||
}
|
||||
4
apps/partner-sas/app/[lang]/page.module.css
Normal file
4
apps/partner-sas/app/[lang]/page.module.css
Normal file
@@ -0,0 +1,4 @@
|
||||
.page {
|
||||
padding-left: 200px;
|
||||
padding-top: 200px;
|
||||
}
|
||||
44
apps/partner-sas/app/[lang]/page.tsx
Normal file
44
apps/partner-sas/app/[lang]/page.tsx
Normal file
@@ -0,0 +1,44 @@
|
||||
import { Temp } from "@scandic-hotels/booking-flow/test-entry"
|
||||
import { Lang } from "@scandic-hotels/common/constants/language"
|
||||
import { Typography } from "@scandic-hotels/design-system/Typography"
|
||||
|
||||
import { serverClient } from "@/lib/trpc"
|
||||
|
||||
import { getIntl } from "@/i18n"
|
||||
|
||||
import { ClientComponent } from "./ClientComponent"
|
||||
|
||||
import styles from "./page.module.css"
|
||||
|
||||
export default async function Home() {
|
||||
const intl = await getIntl()
|
||||
const caller = await serverClient()
|
||||
const destinations = await caller.autocomplete.destinations({
|
||||
lang: Lang.en,
|
||||
includeTypes: ["hotels"],
|
||||
query: "Göteborg",
|
||||
})
|
||||
const hotel = destinations.hits.hotels[0].name
|
||||
|
||||
return (
|
||||
<div className={styles.page}>
|
||||
<main>
|
||||
<Typography variant="Title/Decorative/lg">
|
||||
{/* eslint-disable-next-line formatjs/no-literal-string-in-jsx */}
|
||||
<p>hello world with data: {hotel}</p>
|
||||
</Typography>
|
||||
<Typography>
|
||||
<p>{intl.formatMessage({ defaultMessage: "Map of the city" })}</p>
|
||||
</Typography>
|
||||
<hr />
|
||||
<ClientComponent />
|
||||
<hr />
|
||||
<Typography>
|
||||
{/* eslint-disable-next-line formatjs/no-literal-string-in-jsx */}
|
||||
<p>from booking-flow package:</p>
|
||||
</Typography>
|
||||
<Temp />
|
||||
</main>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user