chore(SW-194): HotelPage Faq
This commit is contained in:
@@ -48,7 +48,7 @@ export default async function HotelPage() {
|
|||||||
activitiesCard,
|
activitiesCard,
|
||||||
pointsOfInterest,
|
pointsOfInterest,
|
||||||
facilities,
|
facilities,
|
||||||
//accordion,
|
faq,
|
||||||
} = hotelData
|
} = hotelData
|
||||||
|
|
||||||
const topThreePois = pointsOfInterest.slice(0, 3)
|
const topThreePois = pointsOfInterest.slice(0, 3)
|
||||||
@@ -82,7 +82,7 @@ export default async function HotelPage() {
|
|||||||
</div>
|
</div>
|
||||||
<Rooms rooms={roomCategories} />
|
<Rooms rooms={roomCategories} />
|
||||||
<Facilities facilities={facilities} activitiesCard={activitiesCard} />
|
<Facilities facilities={facilities} activitiesCard={activitiesCard} />
|
||||||
{/*accordion && <AccordionSection accordion={accordion} />*/}
|
{faq && <AccordionSection accordion={faq.faq} title={faq.title} />}
|
||||||
</main>
|
</main>
|
||||||
{googleMapsApiKey ? (
|
{googleMapsApiKey ? (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ query GetHotelPage($locale: String!, $uid: String!) {
|
|||||||
faq {
|
faq {
|
||||||
__typename
|
__typename
|
||||||
title
|
title
|
||||||
global_hotel_faqConnection {
|
global_faqConnection {
|
||||||
|
__typename
|
||||||
edges {
|
edges {
|
||||||
node {
|
node {
|
||||||
... on Accordion {
|
... on Accordion {
|
||||||
@@ -25,17 +26,7 @@ query GetHotelPage($locale: String!, $uid: String!) {
|
|||||||
edges {
|
edges {
|
||||||
node {
|
node {
|
||||||
__typename
|
__typename
|
||||||
... on ContentPage {
|
...ContentPageLink
|
||||||
__typename
|
|
||||||
title
|
|
||||||
url
|
|
||||||
system {
|
|
||||||
...System
|
|
||||||
}
|
|
||||||
web {
|
|
||||||
original_url
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -45,7 +36,8 @@ query GetHotelPage($locale: String!, $uid: String!) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hotel_specific_faq {
|
specific_faq {
|
||||||
|
__typename
|
||||||
questions {
|
questions {
|
||||||
answer {
|
answer {
|
||||||
json
|
json
|
||||||
@@ -53,6 +45,7 @@ query GetHotelPage($locale: String!, $uid: String!) {
|
|||||||
edges {
|
edges {
|
||||||
node {
|
node {
|
||||||
__typename
|
__typename
|
||||||
|
...ContentPageLink
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import { z } from "zod"
|
|||||||
|
|
||||||
import { discriminatedUnionArray } from "@/lib/discriminatedUnion"
|
import { discriminatedUnionArray } from "@/lib/discriminatedUnion"
|
||||||
|
|
||||||
import { accordionSchema } from "../schemas/blocks/accordion"
|
|
||||||
import { activitiesCard } from "../schemas/blocks/activitiesCard"
|
import { activitiesCard } from "../schemas/blocks/activitiesCard"
|
||||||
|
import { accordionSchema } from "../schemas/blocks/faq"
|
||||||
|
|
||||||
import { HotelPageEnum } from "@/types/enums/hotelPage"
|
import { HotelPageEnum } from "@/types/enums/hotelPage"
|
||||||
|
|
||||||
@@ -17,16 +17,10 @@ export const contentBlock = z.discriminatedUnion("__typename", [
|
|||||||
contentBlockActivities,
|
contentBlockActivities,
|
||||||
])
|
])
|
||||||
|
|
||||||
export const hotelPageAccordion = z
|
|
||||||
.object({
|
|
||||||
__typename: z.literal(HotelPageEnum.ContentStack.blocks.Accordion),
|
|
||||||
})
|
|
||||||
.merge(accordionSchema)
|
|
||||||
|
|
||||||
export const hotelPageSchema = z.object({
|
export const hotelPageSchema = z.object({
|
||||||
hotel_page: z.object({
|
hotel_page: z.object({
|
||||||
content: discriminatedUnionArray(contentBlock.options).nullable(),
|
content: discriminatedUnionArray(contentBlock.options).nullable(),
|
||||||
faq: hotelPageAccordion,
|
faq: accordionSchema,
|
||||||
hotel_page_id: z.string(),
|
hotel_page_id: z.string(),
|
||||||
title: z.string(),
|
title: z.string(),
|
||||||
url: z.string(),
|
url: z.string(),
|
||||||
|
|||||||
150
server/routers/contentstack/schemas/blocks/faq.ts
Normal file
150
server/routers/contentstack/schemas/blocks/faq.ts
Normal file
@@ -0,0 +1,150 @@
|
|||||||
|
import { z } from "zod"
|
||||||
|
|
||||||
|
import * as pageLinks from "@/server/routers/contentstack/schemas/pageLinks"
|
||||||
|
|
||||||
|
import { HotelPageEnum } from "@/types/enums/hotelPage"
|
||||||
|
|
||||||
|
export const faqSchema = z.array(
|
||||||
|
z.object({
|
||||||
|
answer: z.object({
|
||||||
|
json: z.any(),
|
||||||
|
embedded_itemsConnection: z.object({
|
||||||
|
edges: z.array(
|
||||||
|
z.object({
|
||||||
|
node: z
|
||||||
|
.discriminatedUnion("__typename", [
|
||||||
|
pageLinks.contentPageSchema,
|
||||||
|
pageLinks.hotelPageSchema,
|
||||||
|
pageLinks.loyaltyPageSchema,
|
||||||
|
])
|
||||||
|
.transform((data) => {
|
||||||
|
const link = pageLinks.transform(data)
|
||||||
|
if (link) {
|
||||||
|
return link
|
||||||
|
}
|
||||||
|
return data
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
question: z.string(),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
export type FAQtype = z.infer<typeof accordionSchema> // MOVE
|
||||||
|
|
||||||
|
enum AccordionEnum {
|
||||||
|
HotelPageFaqGlobalFaqConnection = "HotelPageFaqGlobalFaqConnection",
|
||||||
|
GlobalAccordion = "GlobalAccordion",
|
||||||
|
}
|
||||||
|
export const accordionSchema = z
|
||||||
|
.object({
|
||||||
|
__typename: z.enum([HotelPageEnum.ContentStack.blocks.Accordion]),
|
||||||
|
title: z.string().optional().default(""),
|
||||||
|
global_faqConnection: z
|
||||||
|
.object({
|
||||||
|
__typename: z.enum([AccordionEnum.HotelPageFaqGlobalFaqConnection]),
|
||||||
|
edges: z.array(
|
||||||
|
z.object({
|
||||||
|
node: z.object({
|
||||||
|
questions: faqSchema,
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
),
|
||||||
|
})
|
||||||
|
.optional(),
|
||||||
|
specific_faq: z
|
||||||
|
.object({
|
||||||
|
__typename: z.enum([AccordionEnum.GlobalAccordion]),
|
||||||
|
questions: faqSchema,
|
||||||
|
})
|
||||||
|
.optional(),
|
||||||
|
})
|
||||||
|
.transform((data) => {
|
||||||
|
const array = []
|
||||||
|
array.push(
|
||||||
|
data.global_faqConnection?.edges.flatMap(({ node: faqConnection }) => {
|
||||||
|
return faqConnection.questions
|
||||||
|
}) || []
|
||||||
|
)
|
||||||
|
array.push(data.specific_faq?.questions || [])
|
||||||
|
return { ...data, faq: array.flat(2) }
|
||||||
|
})
|
||||||
|
|
||||||
|
const actualRefs = z.discriminatedUnion("__typename", [
|
||||||
|
pageLinks.accountPageRefSchema,
|
||||||
|
pageLinks.contentPageRefSchema,
|
||||||
|
pageLinks.hotelPageRefSchema,
|
||||||
|
pageLinks.loyaltyPageRefSchema,
|
||||||
|
])
|
||||||
|
|
||||||
|
export const accordionRefsSchema = z.object({
|
||||||
|
global_faqConnection: z
|
||||||
|
.object({
|
||||||
|
edges: z.array(
|
||||||
|
z.object({
|
||||||
|
node: z.object({
|
||||||
|
questions: z.array(
|
||||||
|
z.object({
|
||||||
|
answer: z.object({
|
||||||
|
embedded_itemsConnection: z.object({
|
||||||
|
edges: z.array(
|
||||||
|
z.object({
|
||||||
|
node: actualRefs,
|
||||||
|
})
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
),
|
||||||
|
})
|
||||||
|
.optional(),
|
||||||
|
specific_faq: z
|
||||||
|
.object({
|
||||||
|
questions: z.array(
|
||||||
|
z.object({
|
||||||
|
answer: z.object({
|
||||||
|
embedded_itemsConnection: z.object({
|
||||||
|
edges: z.array(
|
||||||
|
z.object({
|
||||||
|
node: actualRefs,
|
||||||
|
})
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
),
|
||||||
|
})
|
||||||
|
.optional(),
|
||||||
|
|
||||||
|
/*.transform((data) => {
|
||||||
|
return data.faq.flatMap((faq) => {
|
||||||
|
switch (faq.__typename) {
|
||||||
|
case AccordionEnum.ContentPageBlocksAccordionBlockFaqGlobalFaq:
|
||||||
|
return (
|
||||||
|
faq.global_faq?.global_faqConnection.edges.flatMap(
|
||||||
|
({ node: faqConnection }) => {
|
||||||
|
return faqConnection.questions.flatMap((question) =>
|
||||||
|
question.answer.embedded_itemsConnection.edges.flatMap(
|
||||||
|
({ node }) => node.system
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
) || []
|
||||||
|
)
|
||||||
|
case AccordionEnum.ContentPageBlocksAccordionBlockFaqSpecificFaq:
|
||||||
|
return (
|
||||||
|
faq.specific_faq?.questions.flatMap((question) =>
|
||||||
|
question.answer.embedded_itemsConnection.edges.flatMap(
|
||||||
|
({ node }) => node.system
|
||||||
|
)
|
||||||
|
) || []
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}),*/
|
||||||
|
})
|
||||||
@@ -101,7 +101,7 @@ export const hotelQueryRouter = router({
|
|||||||
.query(async ({ ctx, input }) => {
|
.query(async ({ ctx, input }) => {
|
||||||
const { lang, uid } = ctx
|
const { lang, uid } = ctx
|
||||||
const { include } = input
|
const { include } = input
|
||||||
console.log("då")
|
|
||||||
const contentstackData = await getContentstackData(lang, uid)
|
const contentstackData = await getContentstackData(lang, uid)
|
||||||
console.log("då", contentstackData)
|
console.log("då", contentstackData)
|
||||||
const hotelId = contentstackData?.hotel_page_id
|
const hotelId = contentstackData?.hotel_page_id
|
||||||
@@ -232,6 +232,7 @@ export const hotelQueryRouter = router({
|
|||||||
roomCategories,
|
roomCategories,
|
||||||
activitiesCard: activities?.upcoming_activities_card,
|
activitiesCard: activities?.upcoming_activities_card,
|
||||||
facilities,
|
facilities,
|
||||||
|
faq: contentstackData?.faq,
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
availability: router({
|
availability: router({
|
||||||
|
|||||||
Reference in New Issue
Block a user