feat: separate current and "new" web in route groups

This commit is contained in:
Christel Westerberg
2024-02-20 09:14:42 +01:00
parent 10b52112af
commit 4e4b6f1bd6
14 changed files with 268 additions and 66 deletions

View 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")
}
}