Merged in feat/sw-2863-move-contentstack-router-to-trpc-package (pull request #2389)
feat(SW-2863): Move contentstack router to trpc package * Add exports to packages and lint rule to prevent relative imports * Add env to trpc package * Add eslint to trpc package * Apply lint rules * Use direct imports from trpc package * Add lint-staged config to trpc * Move lang enum to common * Restructure trpc package folder structure * WIP first step * update internal imports in trpc * Fix most errors in scandic-web Just 100 left... * Move Props type out of trpc * Fix CategorizedFilters types * Move more schemas in hotel router * Fix deps * fix getNonContentstackUrls * Fix import error * Fix entry error handling * Fix generateMetadata metrics * Fix alertType enum * Fix duplicated types * lint:fix * Merge branch 'master' into feat/sw-2863-move-contentstack-router-to-trpc-package * Fix broken imports * Merge branch 'master' into feat/sw-2863-move-contentstack-router-to-trpc-package Approved-by: Linus Flood
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { removeMultipleSlashes } from "@scandic-hotels/common/utils/url"
|
||||
|
||||
import { HotelPageEnum } from "../../../../types/hotelPageEnum"
|
||||
import { collectionPageRefSchema, contentPageRefSchema } from "../pageLinks"
|
||||
|
||||
export const spaPageSchema = z.object({
|
||||
typename: z
|
||||
.literal(HotelPageEnum.ContentStack.blocks.SpaPage)
|
||||
.optional()
|
||||
.default(HotelPageEnum.ContentStack.blocks.SpaPage),
|
||||
spa_page: z
|
||||
.object({
|
||||
button_cta: z.string(),
|
||||
pageConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.object({
|
||||
title: z.string(),
|
||||
url: z.string(),
|
||||
system: z.object({
|
||||
content_type_uid: z.string(),
|
||||
locale: z.string(),
|
||||
uid: z.string(),
|
||||
}),
|
||||
web: z.object({ original_url: z.string() }),
|
||||
}),
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
.transform((data) => {
|
||||
let url = ""
|
||||
if (data.pageConnection.edges.length) {
|
||||
const page = data.pageConnection.edges[0].node
|
||||
if (page.web.original_url) {
|
||||
url = page.web.original_url
|
||||
} else {
|
||||
url = removeMultipleSlashes(`/${page.system.locale}/${page.url}`)
|
||||
}
|
||||
}
|
||||
return {
|
||||
buttonCTA: data.button_cta,
|
||||
url: url,
|
||||
}
|
||||
}),
|
||||
})
|
||||
|
||||
export const spaPageRefSchema = z.object({
|
||||
spa_page: z
|
||||
.object({
|
||||
pageConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.discriminatedUnion("__typename", [
|
||||
contentPageRefSchema,
|
||||
collectionPageRefSchema,
|
||||
]),
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
.transform((data) => {
|
||||
return data.pageConnection.edges.flatMap(({ node }) => node.system) || []
|
||||
}),
|
||||
})
|
||||
Reference in New Issue
Block a user