feat(SW-214): Setup connection to Contentstack
This commit is contained in:
69
lib/graphql/Fragments/Blocks/UspGrid.graphql
Normal file
69
lib/graphql/Fragments/Blocks/UspGrid.graphql
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
#import "../PageLink/AccountPageLink.graphql"
|
||||||
|
#import "../PageLink/ContentPageLink.graphql"
|
||||||
|
#import "../PageLink/HotelPageLink.graphql"
|
||||||
|
#import "../PageLink/LoyaltyPageLink.graphql"
|
||||||
|
|
||||||
|
#import "../AccountPage/Ref.graphql"
|
||||||
|
#import "../ContentPage/Ref.graphql"
|
||||||
|
#import "../HotelPage/Ref.graphql"
|
||||||
|
#import "../LoyaltyPage/Ref.graphql"
|
||||||
|
|
||||||
|
fragment UspGrid_ContentPage on ContentPageBlocksUspGrid {
|
||||||
|
__typename
|
||||||
|
usp_grid {
|
||||||
|
cardsConnection {
|
||||||
|
edges {
|
||||||
|
node {
|
||||||
|
... on UspGrid {
|
||||||
|
usp_card {
|
||||||
|
icon
|
||||||
|
text {
|
||||||
|
embedded_itemsConnection {
|
||||||
|
totalCount
|
||||||
|
edges {
|
||||||
|
node {
|
||||||
|
__typename
|
||||||
|
...AccountPageLink
|
||||||
|
...ContentPageLink
|
||||||
|
...HotelPageLink
|
||||||
|
...LoyaltyPageLink
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
json
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fragment UspGrid_ContentPageRefs on ContentPageBlocksUspGrid {
|
||||||
|
usp_grid {
|
||||||
|
cardsConnection {
|
||||||
|
edges {
|
||||||
|
node {
|
||||||
|
... on UspGrid {
|
||||||
|
usp_card {
|
||||||
|
text {
|
||||||
|
embedded_itemsConnection {
|
||||||
|
edges {
|
||||||
|
node {
|
||||||
|
__typename
|
||||||
|
...AccountPageRef
|
||||||
|
...ContentPageRef
|
||||||
|
...ImageContainerRef
|
||||||
|
...LoyaltyPageRef
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
78
server/routers/contentstack/schemas/blocks/uspGrid.ts
Normal file
78
server/routers/contentstack/schemas/blocks/uspGrid.ts
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
import { z } from "zod"
|
||||||
|
|
||||||
|
import * as pageLinks from "@/server/routers/contentstack/schemas/pageLinks"
|
||||||
|
|
||||||
|
import { BlocksEnums } from "@/types/enums/blocks"
|
||||||
|
import { UspGridEnum } from "@/types/enums/uspGrid"
|
||||||
|
|
||||||
|
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
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
|
||||||
|
const actualRefs = z.discriminatedUnion("__typename", [
|
||||||
|
pageLinks.accountPageRefSchema,
|
||||||
|
pageLinks.contentPageRefSchema,
|
||||||
|
pageLinks.hotelPageRefSchema,
|
||||||
|
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(
|
||||||
|
z.object({
|
||||||
|
node: z.discriminatedUnion("__typename", [
|
||||||
|
...actualRefs.options,
|
||||||
|
]),
|
||||||
|
})
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
),
|
||||||
|
})
|
||||||
|
.transform((data) => {
|
||||||
|
return data.usp_card.flat()
|
||||||
|
}),
|
||||||
|
})
|
||||||
5
types/enums/uspGrid.ts
Normal file
5
types/enums/uspGrid.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import { z } from "zod"
|
||||||
|
|
||||||
|
export namespace UspGridEnum {
|
||||||
|
export const uspIcons = z.enum(["Snowflake"])
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user