feat: separate current and "new" web in route groups
This commit is contained in:
57
app/[lang]/(live)/content-page/page.tsx
Normal file
57
app/[lang]/(live)/content-page/page.tsx
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
import { notFound } from "next/navigation"
|
||||||
|
|
||||||
|
import { request } from "@/lib/request"
|
||||||
|
import { GetCurrentBlockPage } from "@/lib/graphql/Query/CurrentBlockPage.graphql"
|
||||||
|
|
||||||
|
import ContentPageComponent from "@/components/Current/ContentPage"
|
||||||
|
|
||||||
|
import type { PageArgs, LangParams, UriParams } from "@/types/params"
|
||||||
|
import type { GetCurrentBlockPageData } from "@/types/requests/currentBlockPage"
|
||||||
|
import Tracking from "../../Tracking"
|
||||||
|
|
||||||
|
export default async function ContentPage({
|
||||||
|
params,
|
||||||
|
searchParams,
|
||||||
|
}: PageArgs<LangParams, UriParams>) {
|
||||||
|
try {
|
||||||
|
if (!searchParams.uri) {
|
||||||
|
throw new Error("Bad URI")
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await request<GetCurrentBlockPageData>(
|
||||||
|
GetCurrentBlockPage,
|
||||||
|
{
|
||||||
|
locale: params.lang,
|
||||||
|
url: searchParams.uri,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!response.data?.all_current_blocks_page?.total) {
|
||||||
|
console.log("#### DATA ####")
|
||||||
|
console.log(response.data)
|
||||||
|
console.log("SearchParams URI: ", searchParams.uri)
|
||||||
|
throw new Error("Not found")
|
||||||
|
}
|
||||||
|
const pageData = response.data.all_current_blocks_page.items[0]
|
||||||
|
const trackingData = {
|
||||||
|
pageName: pageData.title,
|
||||||
|
pageType: pageData.__typename,
|
||||||
|
publishedDate: pageData.system.updated_at,
|
||||||
|
createdDate: pageData.system.created_at,
|
||||||
|
pageId: pageData.system.uid,
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<ContentPageComponent
|
||||||
|
data={response.data}
|
||||||
|
uri={searchParams.uri}
|
||||||
|
lang={params.lang}
|
||||||
|
/>
|
||||||
|
<Tracking pageData={trackingData} />
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
} catch (err) {
|
||||||
|
return notFound()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,4 @@
|
|||||||
import "../../core.css"
|
|
||||||
import "../../scandic.css"
|
|
||||||
|
|
||||||
import Footer from "@/components/Current/Footer"
|
|
||||||
import LangPopup from "@/components/Current/LangPopup"
|
|
||||||
import Script from "next/script"
|
import Script from "next/script"
|
||||||
import SkipToMainContent from "@/components/SkipToMainContent"
|
|
||||||
|
|
||||||
import type { Metadata } from "next"
|
import type { Metadata } from "next"
|
||||||
import type { LangParams, LayoutArgs } from "@/types/params"
|
import type { LangParams, LayoutArgs } from "@/types/params"
|
||||||
@@ -33,42 +27,10 @@ export default function RootLayout({
|
|||||||
id="Cookiebot"
|
id="Cookiebot"
|
||||||
src="https://consent.cookiebot.com/uc.js"
|
src="https://consent.cookiebot.com/uc.js"
|
||||||
/>
|
/>
|
||||||
{/* <Script
|
|
||||||
data-cookieconsent="ignore"
|
|
||||||
src="/Static/dist/js/head.js?85c84c9e24ae8da3e7af"
|
|
||||||
/> */}
|
|
||||||
<Script
|
|
||||||
data-cookieconsent="ignore"
|
|
||||||
src="/Static/dist/js/inline.js?00133e5a37de35c51a5d"
|
|
||||||
/>
|
|
||||||
<Script
|
|
||||||
data-cookieconsent="ignore"
|
|
||||||
src="/Static/dist/js/main.js?89d0030e1a04b3b46d0b"
|
|
||||||
/>
|
|
||||||
<Script
|
|
||||||
data-cookieconsent="ignore"
|
|
||||||
src="/Static/dist/js/ng/polyfills.js?1705409330990"
|
|
||||||
/>
|
|
||||||
<Script
|
|
||||||
data-cookieconsent="ignore"
|
|
||||||
src="/Static/dist/js/ng/runtime.js?1705409330990"
|
|
||||||
/>
|
|
||||||
<Script
|
|
||||||
data-cookieconsent="ignore"
|
|
||||||
src="/Static/dist/js/ng/main.js?1705409330990"
|
|
||||||
/>
|
|
||||||
{/* <Script
|
|
||||||
data-cookieconsent="ignore"
|
|
||||||
src="/Static/dist/js/main-ng.js?336b801d6b38eff10884"
|
|
||||||
strategy="lazyOnload"
|
|
||||||
/> */}
|
|
||||||
<AdobeScript />
|
<AdobeScript />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<LangPopup lang={params.lang} />
|
|
||||||
<SkipToMainContent lang={params.lang} />
|
|
||||||
{children}
|
{children}
|
||||||
<Footer lang={params.lang} />
|
|
||||||
<Script id="page-tracking">{`
|
<Script id="page-tracking">{`
|
||||||
typeof _satellite !== "undefined" && _satellite.pageBottom();
|
typeof _satellite !== "undefined" && _satellite.pageBottom();
|
||||||
`}</Script>
|
`}</Script>
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ import { request } from "@/lib/request"
|
|||||||
import { GetCurrentBlockPage } from "@/lib/graphql/Query/CurrentBlockPage.graphql"
|
import { GetCurrentBlockPage } from "@/lib/graphql/Query/CurrentBlockPage.graphql"
|
||||||
|
|
||||||
import ContentPage from "@/components/Current/ContentPage"
|
import ContentPage from "@/components/Current/ContentPage"
|
||||||
|
import Tracking from "../../Tracking"
|
||||||
|
|
||||||
import type { PageArgs, LangParams, UriParams } from "@/types/params"
|
import type { PageArgs, LangParams, UriParams } from "@/types/params"
|
||||||
import type { GetCurrentBlockPageData } from "@/types/requests/currentBlockPage"
|
import type { GetCurrentBlockPageData } from "@/types/requests/currentBlockPage"
|
||||||
import Tracking from "../../Tracking"
|
|
||||||
|
|
||||||
export default async function CurrentContentPage({
|
export default async function CurrentContentPage({
|
||||||
params,
|
params,
|
||||||
79
app/[lang]/(live-current)/layout.tsx
Normal file
79
app/[lang]/(live-current)/layout.tsx
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
/* eslint-disable @next/next/no-css-tags */
|
||||||
|
|
||||||
|
import Footer from "@/components/Current/Footer"
|
||||||
|
import LangPopup from "@/components/Current/LangPopup"
|
||||||
|
import Script from "next/script"
|
||||||
|
import SkipToMainContent from "@/components/SkipToMainContent"
|
||||||
|
import AdobeScript from "../AdobeScript"
|
||||||
|
|
||||||
|
import type { Metadata } from "next"
|
||||||
|
import type { LangParams, LayoutArgs } from "@/types/params"
|
||||||
|
|
||||||
|
export const metadata: Metadata = {
|
||||||
|
description: "New web",
|
||||||
|
title: "Scandic Hotels New Web",
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function RootLayout({
|
||||||
|
children,
|
||||||
|
params,
|
||||||
|
}: React.PropsWithChildren<LayoutArgs<LangParams>>) {
|
||||||
|
return (
|
||||||
|
<html lang={params.lang}>
|
||||||
|
<head>
|
||||||
|
<link rel="stylesheet" href="/Static/css/core.css"/>
|
||||||
|
<link rel="stylesheet" href="/Static/css/scandic.css"/>
|
||||||
|
<Script
|
||||||
|
data-cookieconsent="ignore"
|
||||||
|
src="/Static/dist/js/cookie-bot.js?1705409331007"
|
||||||
|
/>
|
||||||
|
<Script
|
||||||
|
data-blockingmode="auto"
|
||||||
|
data-cbid="6d539de8-3e67-4f0f-a0df-8cef9070f712"
|
||||||
|
data-culture="@cultureCode"
|
||||||
|
id="Cookiebot"
|
||||||
|
src="https://consent.cookiebot.com/uc.js"
|
||||||
|
/>
|
||||||
|
{/* <Script
|
||||||
|
data-cookieconsent="ignore"
|
||||||
|
src="/Static/dist/js/head.js?85c84c9e24ae8da3e7af"
|
||||||
|
/> */}
|
||||||
|
<Script
|
||||||
|
data-cookieconsent="ignore"
|
||||||
|
src="/Static/dist/js/inline.js?00133e5a37de35c51a5d"
|
||||||
|
/>
|
||||||
|
<Script
|
||||||
|
data-cookieconsent="ignore"
|
||||||
|
src="/Static/dist/js/main.js?89d0030e1a04b3b46d0b"
|
||||||
|
/>
|
||||||
|
<Script
|
||||||
|
data-cookieconsent="ignore"
|
||||||
|
src="/Static/dist/js/ng/polyfills.js?1705409330990"
|
||||||
|
/>
|
||||||
|
<Script
|
||||||
|
data-cookieconsent="ignore"
|
||||||
|
src="/Static/dist/js/ng/runtime.js?1705409330990"
|
||||||
|
/>
|
||||||
|
<Script
|
||||||
|
data-cookieconsent="ignore"
|
||||||
|
src="/Static/dist/js/ng/main.js?1705409330990"
|
||||||
|
/>
|
||||||
|
{/* <Script
|
||||||
|
data-cookieconsent="ignore"
|
||||||
|
src="/Static/dist/js/main-ng.js?336b801d6b38eff10884"
|
||||||
|
strategy="lazyOnload"
|
||||||
|
/> */}
|
||||||
|
<AdobeScript />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<LangPopup lang={params.lang} />
|
||||||
|
<SkipToMainContent lang={params.lang} />
|
||||||
|
{children}
|
||||||
|
<Footer lang={params.lang} />
|
||||||
|
<Script id="page-tracking">{`
|
||||||
|
typeof _satellite !== "undefined" && _satellite.pageBottom();
|
||||||
|
`}</Script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
)
|
||||||
|
}
|
||||||
8
app/[lang]/(live-current)/not-found.tsx
Normal file
8
app/[lang]/(live-current)/not-found.tsx
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
export default function NotFound() {
|
||||||
|
return (
|
||||||
|
<main>
|
||||||
|
<h2>Not Found</h2>
|
||||||
|
<p>Could not find requested resource</p>
|
||||||
|
</main>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -21,34 +21,9 @@ export default function RootLayout({
|
|||||||
}: React.PropsWithChildren<LayoutArgs<LangParams>>) {
|
}: React.PropsWithChildren<LayoutArgs<LangParams>>) {
|
||||||
return (
|
return (
|
||||||
<html lang={params.lang}>
|
<html lang={params.lang}>
|
||||||
<head>
|
|
||||||
<Script
|
|
||||||
data-cookieconsent="ignore"
|
|
||||||
src="/Static/dist/js/inline.js?00133e5a37de35c51a5d"
|
|
||||||
/>
|
|
||||||
<Script
|
|
||||||
data-cookieconsent="ignore"
|
|
||||||
src="/Static/dist/js/main.js?89d0030e1a04b3b46d0b"
|
|
||||||
/>
|
|
||||||
<Script
|
|
||||||
data-cookieconsent="ignore"
|
|
||||||
src="/Static/dist/js/ng/polyfills.js?1705409330990"
|
|
||||||
/>
|
|
||||||
<Script
|
|
||||||
data-cookieconsent="ignore"
|
|
||||||
src="/Static/dist/js/ng/runtime.js?1705409330990"
|
|
||||||
/>
|
|
||||||
<Script
|
|
||||||
data-cookieconsent="ignore"
|
|
||||||
src="/Static/dist/js/ng/main.js?1705409330990"
|
|
||||||
/>
|
|
||||||
</head>
|
|
||||||
<body>
|
<body>
|
||||||
<InitLivePreview />
|
<InitLivePreview />
|
||||||
<LangPopup lang={params.lang} />
|
|
||||||
<SkipToMainContent lang={params.lang} />
|
|
||||||
{children}
|
{children}
|
||||||
<Footer lang={params.lang} />
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import ContentstackLivePreview from "@contentstack/live-preview-utils"
|
|||||||
import LoadingSpinner from "@/components/Current/LoadingSpinner"
|
import LoadingSpinner from "@/components/Current/LoadingSpinner"
|
||||||
import ContentPage from "@/components/Current/ContentPage"
|
import ContentPage from "@/components/Current/ContentPage"
|
||||||
|
|
||||||
export default async function CurrentContentPage({
|
export default async function PreviewPage({
|
||||||
params,
|
params,
|
||||||
searchParams,
|
searchParams,
|
||||||
}: PageArgs<LangParams, PreviewParams>) {
|
}: PageArgs<LangParams, PreviewParams>) {
|
||||||
|
|||||||
9
app/[lang]/(preview-current)/error.tsx
Normal file
9
app/[lang]/(preview-current)/error.tsx
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
export default function Error({ error }: { error: Error }) {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h2>Something went wrong!</h2>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
56
app/[lang]/(preview-current)/layout.tsx
Normal file
56
app/[lang]/(preview-current)/layout.tsx
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
/* eslint-disable @next/next/no-css-tags */
|
||||||
|
|
||||||
|
import Footer from "@/components/Current/Footer";
|
||||||
|
import LangPopup from "@/components/Current/LangPopup";
|
||||||
|
import Script from "next/script";
|
||||||
|
import SkipToMainContent from "@/components/SkipToMainContent";
|
||||||
|
import InitLivePreview from "@/components/Current/LivePreview";
|
||||||
|
|
||||||
|
import type { Metadata } from "next";
|
||||||
|
import type { LangParams, LayoutArgs } from "@/types/params";
|
||||||
|
|
||||||
|
export const metadata: Metadata = {
|
||||||
|
description: "New web",
|
||||||
|
title: "Scandic Hotels New Web",
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function RootLayout({
|
||||||
|
children,
|
||||||
|
params,
|
||||||
|
}: React.PropsWithChildren<LayoutArgs<LangParams>>) {
|
||||||
|
return (
|
||||||
|
<html lang={params.lang}>
|
||||||
|
<head>
|
||||||
|
<link rel="stylesheet" href="/Static/css/core.css"/>
|
||||||
|
<link rel="stylesheet" href="/Static/css/scandic.css"/>
|
||||||
|
<Script
|
||||||
|
data-cookieconsent="ignore"
|
||||||
|
src="/Static/dist/js/inline.js?00133e5a37de35c51a5d"
|
||||||
|
/>
|
||||||
|
<Script
|
||||||
|
data-cookieconsent="ignore"
|
||||||
|
src="/Static/dist/js/main.js?89d0030e1a04b3b46d0b"
|
||||||
|
/>
|
||||||
|
<Script
|
||||||
|
data-cookieconsent="ignore"
|
||||||
|
src="/Static/dist/js/ng/polyfills.js?1705409330990"
|
||||||
|
/>
|
||||||
|
<Script
|
||||||
|
data-cookieconsent="ignore"
|
||||||
|
src="/Static/dist/js/ng/runtime.js?1705409330990"
|
||||||
|
/>
|
||||||
|
<Script
|
||||||
|
data-cookieconsent="ignore"
|
||||||
|
src="/Static/dist/js/ng/main.js?1705409330990"
|
||||||
|
/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<InitLivePreview />
|
||||||
|
<LangPopup lang={params.lang} />
|
||||||
|
<SkipToMainContent lang={params.lang} />
|
||||||
|
{children}
|
||||||
|
<Footer lang={params.lang} />
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
)
|
||||||
|
}
|
||||||
8
app/[lang]/(preview-current)/not-found.tsx
Normal file
8
app/[lang]/(preview-current)/not-found.tsx
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
export default function NotFound() {
|
||||||
|
return (
|
||||||
|
<main>
|
||||||
|
<h2>Not Found</h2>
|
||||||
|
<p>Could not find requested resource</p>
|
||||||
|
</main>
|
||||||
|
)
|
||||||
|
}
|
||||||
45
app/[lang]/(preview-current)/preview-current/page.tsx
Normal file
45
app/[lang]/(preview-current)/preview-current/page.tsx
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import { previewRequest } from "@/lib/previewRequest"
|
||||||
|
import { GetCurrentBlockPage } from "@/lib/graphql/Query/CurrentBlockPage.graphql"
|
||||||
|
|
||||||
|
import type { PageArgs, LangParams, PreviewParams } from "@/types/params"
|
||||||
|
import type { GetCurrentBlockPageData } from "@/types/requests/currentBlockPage"
|
||||||
|
import ContentstackLivePreview from "@contentstack/live-preview-utils"
|
||||||
|
import LoadingSpinner from "@/components/Current/LoadingSpinner"
|
||||||
|
import ContentPage from "@/components/Current/ContentPage"
|
||||||
|
|
||||||
|
export default async function CurrentPreviewPage({
|
||||||
|
params,
|
||||||
|
searchParams,
|
||||||
|
}: PageArgs<LangParams, PreviewParams>) {
|
||||||
|
try {
|
||||||
|
ContentstackLivePreview.setConfigFromParams(searchParams)
|
||||||
|
|
||||||
|
if (!searchParams.uri || !searchParams.live_preview) {
|
||||||
|
return <LoadingSpinner />
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await previewRequest<GetCurrentBlockPageData>(
|
||||||
|
GetCurrentBlockPage,
|
||||||
|
{ locale: params.lang, url: searchParams.uri }
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!response.data?.all_current_blocks_page?.total) {
|
||||||
|
console.log("#### DATA ####")
|
||||||
|
console.log(response.data)
|
||||||
|
console.log("SearchParams URI: ", searchParams.uri)
|
||||||
|
throw new Error("Not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ContentPage
|
||||||
|
data={response.data}
|
||||||
|
uri={searchParams.uri}
|
||||||
|
lang={params.lang}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
} catch (error) {
|
||||||
|
// TODO: throw 500
|
||||||
|
console.error(error)
|
||||||
|
throw new Error("Something went wrong")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -39,7 +39,10 @@ export async function middleware(request: NextRequest) {
|
|||||||
searchParams.set("uri", pathNameWithoutLocale.replace("/preview", ""))
|
searchParams.set("uri", pathNameWithoutLocale.replace("/preview", ""))
|
||||||
|
|
||||||
return NextResponse.rewrite(
|
return NextResponse.rewrite(
|
||||||
new URL(`/${locale}/preview?${searchParams.toString()}`, request.url)
|
new URL(
|
||||||
|
`/${locale}/preview-current?${searchParams.toString()}`,
|
||||||
|
request.url
|
||||||
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user