diff --git a/components/ContentType/HotelPage/index.tsx b/components/ContentType/HotelPage/index.tsx
index f5ba696d9..e651145bc 100644
--- a/components/ContentType/HotelPage/index.tsx
+++ b/components/ContentType/HotelPage/index.tsx
@@ -48,7 +48,7 @@ export default async function HotelPage() {
activitiesCard,
pointsOfInterest,
facilities,
- //accordion,
+ faq,
} = hotelData
const topThreePois = pointsOfInterest.slice(0, 3)
@@ -82,7 +82,7 @@ export default async function HotelPage() {
- {/*accordion && */}
+ {faq && }
{googleMapsApiKey ? (
<>
diff --git a/lib/graphql/Query/HotelPage/HotelPage.graphql b/lib/graphql/Query/HotelPage/HotelPage.graphql
index 6d6acabb0..981d60086 100644
--- a/lib/graphql/Query/HotelPage/HotelPage.graphql
+++ b/lib/graphql/Query/HotelPage/HotelPage.graphql
@@ -11,7 +11,8 @@ query GetHotelPage($locale: String!, $uid: String!) {
faq {
__typename
title
- global_hotel_faqConnection {
+ global_faqConnection {
+ __typename
edges {
node {
... on Accordion {
@@ -25,17 +26,7 @@ query GetHotelPage($locale: String!, $uid: String!) {
edges {
node {
__typename
- ... on ContentPage {
- __typename
- title
- url
- system {
- ...System
- }
- web {
- original_url
- }
- }
+ ...ContentPageLink
}
}
}
@@ -45,7 +36,8 @@ query GetHotelPage($locale: String!, $uid: String!) {
}
}
}
- hotel_specific_faq {
+ specific_faq {
+ __typename
questions {
answer {
json
@@ -53,6 +45,7 @@ query GetHotelPage($locale: String!, $uid: String!) {
edges {
node {
__typename
+ ...ContentPageLink
}
}
}
diff --git a/server/routers/contentstack/hotelPage/output.ts b/server/routers/contentstack/hotelPage/output.ts
index adafb21b7..47e1c3d4d 100644
--- a/server/routers/contentstack/hotelPage/output.ts
+++ b/server/routers/contentstack/hotelPage/output.ts
@@ -2,8 +2,8 @@ import { z } from "zod"
import { discriminatedUnionArray } from "@/lib/discriminatedUnion"
-import { accordionSchema } from "../schemas/blocks/accordion"
import { activitiesCard } from "../schemas/blocks/activitiesCard"
+import { accordionSchema } from "../schemas/blocks/faq"
import { HotelPageEnum } from "@/types/enums/hotelPage"
@@ -17,16 +17,10 @@ export const contentBlock = z.discriminatedUnion("__typename", [
contentBlockActivities,
])
-export const hotelPageAccordion = z
- .object({
- __typename: z.literal(HotelPageEnum.ContentStack.blocks.Accordion),
- })
- .merge(accordionSchema)
-
export const hotelPageSchema = z.object({
hotel_page: z.object({
content: discriminatedUnionArray(contentBlock.options).nullable(),
- faq: hotelPageAccordion,
+ faq: accordionSchema,
hotel_page_id: z.string(),
title: z.string(),
url: z.string(),
diff --git a/server/routers/contentstack/schemas/blocks/faq.ts b/server/routers/contentstack/schemas/blocks/faq.ts
new file mode 100644
index 000000000..e0c8adfd9
--- /dev/null
+++ b/server/routers/contentstack/schemas/blocks/faq.ts
@@ -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 // 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
+ )
+ ) || []
+ )
+ }
+ })
+ }),*/
+})
diff --git a/server/routers/hotels/query.ts b/server/routers/hotels/query.ts
index ee9f1f8a4..5773a3092 100644
--- a/server/routers/hotels/query.ts
+++ b/server/routers/hotels/query.ts
@@ -101,7 +101,7 @@ export const hotelQueryRouter = router({
.query(async ({ ctx, input }) => {
const { lang, uid } = ctx
const { include } = input
- console.log("då")
+
const contentstackData = await getContentstackData(lang, uid)
console.log("då", contentstackData)
const hotelId = contentstackData?.hotel_page_id
@@ -232,6 +232,7 @@ export const hotelQueryRouter = router({
roomCategories,
activitiesCard: activities?.upcoming_activities_card,
facilities,
+ faq: contentstackData?.faq,
}
}),
availability: router({