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,115 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { CampaignPageEnum } from "../../../types/campaignPage"
|
||||
import { discriminatedUnionArray } from "../../../utils/discriminatedUnion"
|
||||
import {
|
||||
campaignPageHotelListing,
|
||||
heroSchema,
|
||||
includedHotelsSchema,
|
||||
} from "../campaignPage/output"
|
||||
import {
|
||||
linkAndTitleSchema,
|
||||
linkConnectionRefs,
|
||||
} from "../schemas/linkConnection"
|
||||
import { systemSchema } from "../schemas/system"
|
||||
|
||||
const navigationLinksSchema = z
|
||||
.array(linkAndTitleSchema)
|
||||
.nullable()
|
||||
.transform((data) => {
|
||||
if (!data) {
|
||||
return null
|
||||
}
|
||||
|
||||
return data
|
||||
.filter((item) => !!item.link)
|
||||
.map((item) => ({
|
||||
url: item.link!.url,
|
||||
title: item.title || item.link!.title,
|
||||
}))
|
||||
})
|
||||
|
||||
export const blocksSchema = z.discriminatedUnion("__typename", [
|
||||
campaignPageHotelListing,
|
||||
])
|
||||
|
||||
const topCampaignSchema = z
|
||||
.object({
|
||||
heading: z.string(),
|
||||
hero: heroSchema,
|
||||
included_hotels: includedHotelsSchema,
|
||||
blocks: discriminatedUnionArray(blocksSchema.options),
|
||||
url: z.string(),
|
||||
})
|
||||
.transform((data) => {
|
||||
const { blocks, included_hotels, ...rest } = data
|
||||
const hotelListingBlock = blocks.find(
|
||||
(block) =>
|
||||
block.__typename === CampaignPageEnum.ContentStack.blocks.HotelListing
|
||||
)
|
||||
|
||||
return {
|
||||
...rest,
|
||||
hotel_listing: {
|
||||
heading: hotelListingBlock?.hotel_listing.heading || "",
|
||||
hotelIds: included_hotels,
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
export const campaignOverviewPageSchema = z.object({
|
||||
campaign_overview_page: z
|
||||
.object({
|
||||
title: z.string(),
|
||||
header: z.object({
|
||||
heading: z.string(),
|
||||
preamble: z.string(),
|
||||
navigation_links: navigationLinksSchema,
|
||||
}),
|
||||
top_campaignConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: topCampaignSchema,
|
||||
})
|
||||
),
|
||||
}),
|
||||
system: systemSchema.merge(
|
||||
z.object({
|
||||
created_at: z.string(),
|
||||
updated_at: z.string(),
|
||||
})
|
||||
),
|
||||
})
|
||||
.transform((data) => {
|
||||
const { top_campaignConnection, ...rest } = data
|
||||
return {
|
||||
...rest,
|
||||
topCampaign: top_campaignConnection.edges.map(({ node }) => node)[0],
|
||||
}
|
||||
}),
|
||||
trackingProps: z.object({
|
||||
url: z.string(),
|
||||
}),
|
||||
})
|
||||
|
||||
/** REFS */
|
||||
|
||||
const campaignOverviewPageHeaderRefs = z.object({
|
||||
navigation_links: z.array(linkConnectionRefs),
|
||||
})
|
||||
|
||||
export const campaignOverviewPageRefsSchema = z.object({
|
||||
campaign_overview_page: z.object({
|
||||
header: campaignOverviewPageHeaderRefs,
|
||||
top_campaignConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.object({
|
||||
system: systemSchema,
|
||||
}),
|
||||
})
|
||||
),
|
||||
}),
|
||||
system: systemSchema,
|
||||
}),
|
||||
})
|
||||
Reference in New Issue
Block a user