fix(SW-294): code cleanup
This commit is contained in:
@@ -5,8 +5,8 @@ import TextCols from "@/components/Blocks/TextCols"
|
|||||||
import UspGrid from "@/components/Blocks/UspGrid"
|
import UspGrid from "@/components/Blocks/UspGrid"
|
||||||
import JsonToHtml from "@/components/JsonToHtml"
|
import JsonToHtml from "@/components/JsonToHtml"
|
||||||
|
|
||||||
import Table from "./Table"
|
|
||||||
import AccordionSection from "./Accordion"
|
import AccordionSection from "./Accordion"
|
||||||
|
import Table from "./Table"
|
||||||
|
|
||||||
import type { BlocksProps } from "@/types/components/blocks"
|
import type { BlocksProps } from "@/types/components/blocks"
|
||||||
import { BlocksEnums } from "@/types/enums/blocks"
|
import { BlocksEnums } from "@/types/enums/blocks"
|
||||||
@@ -67,11 +67,10 @@ export default function Blocks({ blocks }: BlocksProps) {
|
|||||||
case BlocksEnums.block.UspGrid:
|
case BlocksEnums.block.UspGrid:
|
||||||
return <UspGrid usp_grid={block.usp_grid} />
|
return <UspGrid usp_grid={block.usp_grid} />
|
||||||
case BlocksEnums.block.Accordion:
|
case BlocksEnums.block.Accordion:
|
||||||
console.log("Bub", block.accordion.faq)
|
|
||||||
return (
|
return (
|
||||||
<AccordionSection
|
<AccordionSection
|
||||||
accordion={block.accordion.faq}
|
accordion={block.accordion.faq}
|
||||||
title={block.title}
|
title={block.accordion.title}
|
||||||
key={`${block.typename}-${idx}`}
|
key={`${block.typename}-${idx}`}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import { getLang } from "@/i18n/serverContext"
|
|||||||
import styles from "./amenitiesList.module.css"
|
import styles from "./amenitiesList.module.css"
|
||||||
|
|
||||||
import type { AmenitiesListProps } from "@/types/components/hotelPage/amenities"
|
import type { AmenitiesListProps } from "@/types/components/hotelPage/amenities"
|
||||||
import type { HotelData } from "@/types/hotel"
|
|
||||||
|
|
||||||
export default async function AmenitiesList({
|
export default async function AmenitiesList({
|
||||||
detailedFacilities,
|
detailedFacilities,
|
||||||
|
|||||||
@@ -21,7 +21,10 @@ fragment AccordionBlock on Accordion {
|
|||||||
edges {
|
edges {
|
||||||
node {
|
node {
|
||||||
__typename
|
__typename
|
||||||
|
...AccountPageLink
|
||||||
...ContentPageLink
|
...ContentPageLink
|
||||||
|
...HotelPageLink
|
||||||
|
...LoyaltyPageLink
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -65,7 +68,10 @@ fragment SpecificFaq on ContentPageBlocksAccordionBlockFaqSpecificFaq {
|
|||||||
edges {
|
edges {
|
||||||
node {
|
node {
|
||||||
__typename
|
__typename
|
||||||
|
...AccountPageLink
|
||||||
...ContentPageLink
|
...ContentPageLink
|
||||||
|
...HotelPageLink
|
||||||
|
...LoyaltyPageLink
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -104,7 +110,10 @@ fragment SpecificFaqRefs on ContentPageBlocksAccordionBlockFaqSpecificFaq {
|
|||||||
edges {
|
edges {
|
||||||
node {
|
node {
|
||||||
__typename
|
__typename
|
||||||
|
...AccountPageRef
|
||||||
...ContentPageRef
|
...ContentPageRef
|
||||||
|
...HotelPageRef
|
||||||
|
...LoyaltyPageRef
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,18 +24,21 @@ query GetHotelPage($locale: String!, $uid: String!) {
|
|||||||
specific_faq {
|
specific_faq {
|
||||||
__typename
|
__typename
|
||||||
questions {
|
questions {
|
||||||
|
question
|
||||||
answer {
|
answer {
|
||||||
json
|
json
|
||||||
embedded_itemsConnection {
|
embedded_itemsConnection {
|
||||||
edges {
|
edges {
|
||||||
node {
|
node {
|
||||||
__typename
|
__typename
|
||||||
|
...AccountPageLink
|
||||||
...ContentPageLink
|
...ContentPageLink
|
||||||
|
...HotelPageLink
|
||||||
|
...LoyaltyPageLink
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
question
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { z } from "zod"
|
|||||||
|
|
||||||
import { discriminatedUnionArray } from "@/lib/discriminatedUnion"
|
import { discriminatedUnionArray } from "@/lib/discriminatedUnion"
|
||||||
|
|
||||||
import { activitiesCard } from "../schemas/blocks/activitiesCard"
|
import { activitiesCardSchema } from "../schemas/blocks/activitiesCard"
|
||||||
import { accordionSchema } from "../schemas/blocks/faq"
|
import { accordionSchema } from "../schemas/blocks/faq"
|
||||||
|
|
||||||
import { HotelPageEnum } from "@/types/enums/hotelPage"
|
import { HotelPageEnum } from "@/types/enums/hotelPage"
|
||||||
@@ -11,7 +11,7 @@ const contentBlockActivities = z
|
|||||||
.object({
|
.object({
|
||||||
__typename: z.literal(HotelPageEnum.ContentStack.blocks.ActivitiesCard),
|
__typename: z.literal(HotelPageEnum.ContentStack.blocks.ActivitiesCard),
|
||||||
})
|
})
|
||||||
.merge(activitiesCard)
|
.merge(activitiesCardSchema)
|
||||||
|
|
||||||
export const contentBlock = z.discriminatedUnion("__typename", [
|
export const contentBlock = z.discriminatedUnion("__typename", [
|
||||||
contentBlockActivities,
|
contentBlockActivities,
|
||||||
|
|||||||
@@ -8,12 +8,13 @@ export const faqSchema = z.array(
|
|||||||
z.object({
|
z.object({
|
||||||
question: z.string(),
|
question: z.string(),
|
||||||
answer: z.object({
|
answer: z.object({
|
||||||
json: z.any(),
|
json: z.any(), // JSON
|
||||||
embedded_itemsConnection: z.object({
|
embedded_itemsConnection: z.object({
|
||||||
edges: z.array(
|
edges: z.array(
|
||||||
z.object({
|
z.object({
|
||||||
node: z
|
node: z
|
||||||
.discriminatedUnion("__typename", [
|
.discriminatedUnion("__typename", [
|
||||||
|
pageLinks.accountPageSchema,
|
||||||
pageLinks.contentPageSchema,
|
pageLinks.contentPageSchema,
|
||||||
pageLinks.hotelPageSchema,
|
pageLinks.hotelPageSchema,
|
||||||
pageLinks.loyaltyPageSchema,
|
pageLinks.loyaltyPageSchema,
|
||||||
@@ -44,9 +45,9 @@ export const accordionSchema = z.object({
|
|||||||
.literal(BlocksEnums.block.Accordion)
|
.literal(BlocksEnums.block.Accordion)
|
||||||
.optional()
|
.optional()
|
||||||
.default(BlocksEnums.block.Accordion),
|
.default(BlocksEnums.block.Accordion),
|
||||||
title: z.string().optional().default(""),
|
|
||||||
accordion: z
|
accordion: z
|
||||||
.object({
|
.object({
|
||||||
|
title: z.string().optional().default(""),
|
||||||
faq: z.array(
|
faq: z.array(
|
||||||
z.object({
|
z.object({
|
||||||
__typename: z.enum([
|
__typename: z.enum([
|
||||||
@@ -102,18 +103,7 @@ const actualRefs = z.discriminatedUnion("__typename", [
|
|||||||
pageLinks.loyaltyPageRefSchema,
|
pageLinks.loyaltyPageRefSchema,
|
||||||
])
|
])
|
||||||
|
|
||||||
export const accordionRefsSchema = z.object({
|
export const globalFaqConnectionRefs = z.object({
|
||||||
accordion: z
|
|
||||||
.object({
|
|
||||||
faq: z.array(
|
|
||||||
z.object({
|
|
||||||
__typename: z.enum([
|
|
||||||
AccordionEnum.ContentPageBlocksAccordionBlockFaqGlobalFaq,
|
|
||||||
AccordionEnum.ContentPageBlocksAccordionBlockFaqSpecificFaq,
|
|
||||||
]),
|
|
||||||
global_faq: z
|
|
||||||
.object({
|
|
||||||
global_faqConnection: z.object({
|
|
||||||
edges: z.array(
|
edges: z.array(
|
||||||
z.object({
|
z.object({
|
||||||
node: z.object({
|
node: z.object({
|
||||||
@@ -133,11 +123,9 @@ export const accordionRefsSchema = z.object({
|
|||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
.optional(),
|
|
||||||
specific_faq: z
|
export const specificFaqConnectionRefs = z.object({
|
||||||
.object({
|
|
||||||
questions: z.array(
|
questions: z.array(
|
||||||
z.object({
|
z.object({
|
||||||
answer: z.object({
|
answer: z.object({
|
||||||
@@ -152,7 +140,22 @@ export const accordionRefsSchema = z.object({
|
|||||||
})
|
})
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const accordionRefsSchema = z.object({
|
||||||
|
accordion: z
|
||||||
|
.object({
|
||||||
|
faq: z.array(
|
||||||
|
z.object({
|
||||||
|
__typename: z.enum([
|
||||||
|
AccordionEnum.ContentPageBlocksAccordionBlockFaqGlobalFaq,
|
||||||
|
AccordionEnum.ContentPageBlocksAccordionBlockFaqSpecificFaq,
|
||||||
|
]),
|
||||||
|
global_faq: z
|
||||||
|
.object({
|
||||||
|
global_faqConnection: globalFaqConnectionRefs,
|
||||||
|
})
|
||||||
.optional(),
|
.optional(),
|
||||||
|
specific_faq: specificFaqConnectionRefs.optional(),
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,50 +1,22 @@
|
|||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
import * as pageLinks from "@/server/routers/contentstack/schemas/pageLinks"
|
import {
|
||||||
|
faqSchema,
|
||||||
|
globalFaqConnectionRefs,
|
||||||
|
specificFaqConnectionRefs,
|
||||||
|
} from "./accordion"
|
||||||
|
|
||||||
import { HotelPageEnum } from "@/types/enums/hotelPage"
|
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
|
export const accordionSchema = z
|
||||||
.object({
|
.object({
|
||||||
__typename: z.enum([HotelPageEnum.ContentStack.blocks.Accordion]),
|
__typename: z
|
||||||
|
.literal(HotelPageEnum.ContentStack.blocks.Faq)
|
||||||
|
.optional()
|
||||||
|
.default(HotelPageEnum.ContentStack.blocks.Faq),
|
||||||
title: z.string().optional().default(""),
|
title: z.string().optional().default(""),
|
||||||
global_faqConnection: z
|
global_faqConnection: z
|
||||||
.object({
|
.object({
|
||||||
__typename: z.enum([AccordionEnum.HotelPageFaqGlobalFaqConnection]),
|
|
||||||
edges: z.array(
|
edges: z.array(
|
||||||
z.object({
|
z.object({
|
||||||
node: z.object({
|
node: z.object({
|
||||||
@@ -56,7 +28,6 @@ export const accordionSchema = z
|
|||||||
.optional(),
|
.optional(),
|
||||||
specific_faq: z
|
specific_faq: z
|
||||||
.object({
|
.object({
|
||||||
__typename: z.enum([AccordionEnum.GlobalAccordion]),
|
|
||||||
questions: faqSchema,
|
questions: faqSchema,
|
||||||
})
|
})
|
||||||
.optional(),
|
.optional(),
|
||||||
@@ -72,79 +43,28 @@ export const accordionSchema = z
|
|||||||
return { ...data, faq: array.flat(2) }
|
return { ...data, faq: array.flat(2) }
|
||||||
})
|
})
|
||||||
|
|
||||||
const actualRefs = z.discriminatedUnion("__typename", [
|
export const accordionRefsSchema = z
|
||||||
pageLinks.accountPageRefSchema,
|
|
||||||
pageLinks.contentPageRefSchema,
|
|
||||||
pageLinks.hotelPageRefSchema,
|
|
||||||
pageLinks.loyaltyPageRefSchema,
|
|
||||||
])
|
|
||||||
|
|
||||||
export const accordionRefsSchema = z.object({
|
|
||||||
global_faqConnection: z
|
|
||||||
.object({
|
.object({
|
||||||
edges: z.array(
|
global_faqConnection: globalFaqConnectionRefs.optional(),
|
||||||
z.object({
|
specific_faq: specificFaqConnectionRefs.optional(),
|
||||||
node: z.object({
|
|
||||||
questions: z.array(
|
|
||||||
z.object({
|
|
||||||
answer: z.object({
|
|
||||||
embedded_itemsConnection: z.object({
|
|
||||||
edges: z.array(
|
|
||||||
z.object({
|
|
||||||
node: actualRefs,
|
|
||||||
})
|
})
|
||||||
),
|
.transform((data) => {
|
||||||
}),
|
const array = []
|
||||||
}),
|
array.push(
|
||||||
})
|
data.global_faqConnection?.edges.flatMap(({ node: faqConnection }) => {
|
||||||
),
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
),
|
|
||||||
})
|
|
||||||
.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) =>
|
return faqConnection.questions.flatMap((question) =>
|
||||||
question.answer.embedded_itemsConnection.edges.flatMap(
|
question.answer.embedded_itemsConnection.edges.flatMap(
|
||||||
({ node }) => node.system
|
({ node }) => node.system
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}) || []
|
||||||
) || []
|
|
||||||
)
|
)
|
||||||
case AccordionEnum.ContentPageBlocksAccordionBlockFaqSpecificFaq:
|
array.push(
|
||||||
return (
|
data.specific_faq?.questions.flatMap((question) =>
|
||||||
faq.specific_faq?.questions.flatMap((question) =>
|
|
||||||
question.answer.embedded_itemsConnection.edges.flatMap(
|
question.answer.embedded_itemsConnection.edges.flatMap(
|
||||||
({ node }) => node.system
|
({ node }) => node.system
|
||||||
)
|
)
|
||||||
) || []
|
) || []
|
||||||
)
|
)
|
||||||
}
|
return { faq: array.flat(2) }
|
||||||
})
|
|
||||||
}),*/
|
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ async function getContentstackData(
|
|||||||
if (!response.data) {
|
if (!response.data) {
|
||||||
throw notFound(response)
|
throw notFound(response)
|
||||||
}
|
}
|
||||||
console.log("HEJ", response.data)
|
|
||||||
const hotelPageData = hotelPageSchema.safeParse(response.data)
|
const hotelPageData = hotelPageSchema.safeParse(response.data)
|
||||||
if (!hotelPageData.success) {
|
if (!hotelPageData.success) {
|
||||||
console.error(
|
console.error(
|
||||||
@@ -103,7 +103,6 @@ export const hotelQueryRouter = router({
|
|||||||
const { include } = input
|
const { include } = input
|
||||||
|
|
||||||
const contentstackData = await getContentstackData(lang, uid)
|
const contentstackData = await getContentstackData(lang, uid)
|
||||||
console.log("då", contentstackData)
|
|
||||||
const hotelId = contentstackData?.hotel_page_id
|
const hotelId = contentstackData?.hotel_page_id
|
||||||
|
|
||||||
if (!hotelId) {
|
if (!hotelId) {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
export namespace HotelPageEnum {
|
export namespace HotelPageEnum {
|
||||||
export namespace ContentStack {
|
export namespace ContentStack {
|
||||||
export const enum blocks {
|
export const enum blocks {
|
||||||
Accordion = "HotelPageFaq",
|
Faq = "HotelPageFaq",
|
||||||
ActivitiesCard = "HotelPageContentUpcomingActivitiesCard",
|
ActivitiesCard = "HotelPageContentUpcomingActivitiesCard",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ import {
|
|||||||
contentBlock,
|
contentBlock,
|
||||||
hotelPageSchema,
|
hotelPageSchema,
|
||||||
} from "@/server/routers/contentstack/hotelPage/output"
|
} from "@/server/routers/contentstack/hotelPage/output"
|
||||||
import { activitiesCard } from "@/server/routers/contentstack/schemas/blocks/activitiesCard"
|
import { activitiesCardSchema } from "@/server/routers/contentstack/schemas/blocks/activitiesCard"
|
||||||
|
|
||||||
// Will be extended once we introduce more functionality to our entries.
|
// Will be extended once we introduce more functionality to our entries.
|
||||||
export interface GetHotelPageData extends z.input<typeof hotelPageSchema> {}
|
export interface GetHotelPageData extends z.input<typeof hotelPageSchema> {}
|
||||||
export interface HotelPage extends z.output<typeof hotelPageSchema> {}
|
export interface HotelPage extends z.output<typeof hotelPageSchema> {}
|
||||||
|
|
||||||
export interface ActivitiesCard extends z.output<typeof activitiesCard> {}
|
export interface ActivitiesCard extends z.output<typeof activitiesCardSchema> {}
|
||||||
export type ActivityCard = ActivitiesCard["upcoming_activities_card"]
|
export type ActivityCard = ActivitiesCard["upcoming_activities_card"]
|
||||||
export interface ContentBlock extends z.output<typeof contentBlock> {}
|
export interface ContentBlock extends z.output<typeof contentBlock> {}
|
||||||
|
|||||||
Reference in New Issue
Block a user