feat(SW-214): Implement usp component
This commit is contained in:
@@ -5,41 +5,57 @@ import * as pageLinks from "@/server/routers/contentstack/schemas/pageLinks"
|
||||
import { BlocksEnums } from "@/types/enums/blocks"
|
||||
import { UspGridEnum } from "@/types/enums/uspGrid"
|
||||
|
||||
const uspCardSchema = z.object({
|
||||
icon: UspGridEnum.uspIcons,
|
||||
text: z.object({
|
||||
json: z.any(), // JSON
|
||||
embedded_itemsConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z
|
||||
.discriminatedUnion("__typename", [
|
||||
pageLinks.accountPageSchema,
|
||||
pageLinks.contentPageSchema,
|
||||
pageLinks.hotelPageSchema,
|
||||
pageLinks.loyaltyPageSchema,
|
||||
])
|
||||
.transform((data) => {
|
||||
const link = pageLinks.transform(data)
|
||||
if (link) {
|
||||
return link
|
||||
}
|
||||
return data
|
||||
}),
|
||||
})
|
||||
),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
|
||||
export const uspGridSchema = z.object({
|
||||
typename: z
|
||||
.literal(BlocksEnums.block.UspGrid)
|
||||
.optional()
|
||||
.default(BlocksEnums.block.UspGrid),
|
||||
usp_grid: z.object({
|
||||
usp_card: z.array(
|
||||
z.object({
|
||||
icon: UspGridEnum.uspIcons,
|
||||
text: z.object({
|
||||
json: z.any(), // JSON
|
||||
embedded_itemsConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z
|
||||
.discriminatedUnion("__typename", [
|
||||
pageLinks.accountPageSchema,
|
||||
pageLinks.contentPageSchema,
|
||||
pageLinks.hotelPageSchema,
|
||||
pageLinks.loyaltyPageSchema,
|
||||
])
|
||||
.transform((data) => {
|
||||
const link = pageLinks.transform(data)
|
||||
if (link) {
|
||||
return link
|
||||
}
|
||||
return data
|
||||
}),
|
||||
})
|
||||
),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
),
|
||||
}),
|
||||
usp_grid: z
|
||||
.object({
|
||||
cardsConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.object({
|
||||
usp_card: z.array(uspCardSchema),
|
||||
}),
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
.transform((data) => {
|
||||
return {
|
||||
usp_card: data.cardsConnection.edges.flatMap(
|
||||
(edge) => edge.node.usp_card
|
||||
),
|
||||
}
|
||||
}),
|
||||
})
|
||||
|
||||
const actualRefs = z.discriminatedUnion("__typename", [
|
||||
@@ -49,30 +65,40 @@ const actualRefs = z.discriminatedUnion("__typename", [
|
||||
pageLinks.loyaltyPageRefSchema,
|
||||
])
|
||||
|
||||
type Refs = {
|
||||
node: z.TypeOf<typeof actualRefs>
|
||||
}
|
||||
|
||||
export const uspGridRefsSchema = z.object({
|
||||
usp_grid: z
|
||||
.object({
|
||||
usp_card: z.array(
|
||||
z.object({
|
||||
text: z.object({
|
||||
embedded_itemsConnection: z.object({
|
||||
edges: z.array(
|
||||
cardsConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.object({
|
||||
usp_card: z.array(
|
||||
z.object({
|
||||
node: z.discriminatedUnion("__typename", [
|
||||
...actualRefs.options,
|
||||
]),
|
||||
text: z.object({
|
||||
embedded_itemsConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.discriminatedUnion("__typename", [
|
||||
...actualRefs.options,
|
||||
]),
|
||||
})
|
||||
),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
),
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
.transform((data) => {
|
||||
return data.usp_card.flat()
|
||||
return data.cardsConnection.edges.flatMap(({ node }) =>
|
||||
node.usp_card.flatMap((card) =>
|
||||
card.text.embedded_itemsConnection.edges.map(
|
||||
({ node }) => node.system
|
||||
)
|
||||
)
|
||||
)
|
||||
}),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user