feat(SW-66, SW-348): search functionality and ui
This commit is contained in:
@@ -1,64 +1,26 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { HotelBlocksTypenameEnum } from "@/types/components/hotelPage/enums"
|
||||
import { discriminatedUnionArray } from "@/lib/discriminatedUnion"
|
||||
|
||||
export const activityCardSchema = z.object({
|
||||
background_image: z.any(),
|
||||
cta_text: z.string(),
|
||||
heading: z.string(),
|
||||
open_in_new_tab: z.boolean(),
|
||||
scripted_title: z.string().optional(),
|
||||
body_text: z.string(),
|
||||
hotel_page_activities_content_pageConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.object({
|
||||
url: z.string(),
|
||||
web: z.object({
|
||||
original_url: z.string().optional(),
|
||||
}),
|
||||
system: z.object({
|
||||
locale: z.string(),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
import { activitiesCard } from "../schemas/blocks/activitiesCard"
|
||||
|
||||
const contentBlockActivity = z.object({
|
||||
__typename: z.literal(
|
||||
HotelBlocksTypenameEnum.HotelPageContentUpcomingActivitiesCard
|
||||
),
|
||||
upcoming_activities_card: activityCardSchema,
|
||||
})
|
||||
import { HotelPageEnum } from "@/types/enums/hotelPage"
|
||||
|
||||
const contentBlockItem = z.discriminatedUnion("__typename", [
|
||||
contentBlockActivity,
|
||||
const contentBlockActivities = z
|
||||
.object({
|
||||
__typename: z.literal(HotelPageEnum.ContentStack.blocks.ActivitiesCard),
|
||||
})
|
||||
.merge(activitiesCard)
|
||||
|
||||
export const contentBlock = z.discriminatedUnion("__typename", [
|
||||
contentBlockActivities,
|
||||
])
|
||||
|
||||
export const validateHotelPageSchema = z.object({
|
||||
hotel_page: z.object({
|
||||
hotel_page_id: z.string(),
|
||||
title: z.string(),
|
||||
url: z.string(),
|
||||
content: z.array(contentBlockItem).nullable(),
|
||||
}),
|
||||
})
|
||||
|
||||
export const hotelPageSchema = z.object({
|
||||
hotel_page: z.object({
|
||||
content: discriminatedUnionArray(contentBlock.options).nullable(),
|
||||
hotel_page_id: z.string(),
|
||||
title: z.string(),
|
||||
url: z.string(),
|
||||
}),
|
||||
})
|
||||
|
||||
// Will be extended once we introduce more functionality to our entries.
|
||||
export type HotelPageDataRaw = z.infer<typeof validateHotelPageSchema>
|
||||
|
||||
type HotelPageRaw = HotelPageDataRaw["hotel_page"]
|
||||
export type HotelPage = HotelPageRaw
|
||||
|
||||
export type ActivityCard = z.infer<typeof activityCardSchema>
|
||||
export type ContentBlockItem = z.infer<typeof contentBlockItem>
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
import { metrics } from "@opentelemetry/api"
|
||||
|
||||
import { GetHotelPage } from "@/lib/graphql/Query/HotelPage.graphql"
|
||||
import { GetHotelPage } from "@/lib/graphql/Query/HotelPage/HotelPage.graphql"
|
||||
import { request } from "@/lib/graphql/request"
|
||||
import { notFound } from "@/server/errors/trpc"
|
||||
import { contentstackExtendedProcedureUID, router } from "@/server/trpc"
|
||||
|
||||
import { generateTag } from "@/utils/generateTag"
|
||||
|
||||
import { HotelPage, HotelPageDataRaw, validateHotelPageSchema } from "./output"
|
||||
import { hotelPageSchema } from "./output"
|
||||
|
||||
import { GetHotelPageData } from "@/types/trpc/routers/contentstack/hotelPage"
|
||||
|
||||
// OpenTelemetry metrics
|
||||
const meter = metrics.getMeter("trpc.contentstack.hotelPage")
|
||||
@@ -31,7 +33,7 @@ export const hotelPageQueryRouter = router({
|
||||
query: { lang, uid },
|
||||
})
|
||||
)
|
||||
const response = await request<HotelPageDataRaw>(
|
||||
const response = await request<GetHotelPageData>(
|
||||
GetHotelPage,
|
||||
{
|
||||
locale: lang,
|
||||
@@ -62,7 +64,7 @@ export const hotelPageQueryRouter = router({
|
||||
throw notFoundError
|
||||
}
|
||||
|
||||
const validatedHotelPage = validateHotelPageSchema.safeParse(response.data)
|
||||
const validatedHotelPage = hotelPageSchema.safeParse(response.data)
|
||||
|
||||
if (!validatedHotelPage.success) {
|
||||
getHotelPageFailCounter.add(1, {
|
||||
@@ -81,9 +83,6 @@ export const hotelPageQueryRouter = router({
|
||||
return null
|
||||
}
|
||||
|
||||
const hotelPage = {
|
||||
...validatedHotelPage.data.hotel_page,
|
||||
} as HotelPage
|
||||
getHotelPageSuccessCounter.add(1, { lang, uid: `${uid}` })
|
||||
console.info(
|
||||
"contentstack.hotelPage success",
|
||||
@@ -91,6 +90,6 @@ export const hotelPageQueryRouter = router({
|
||||
query: { lang, uid },
|
||||
})
|
||||
)
|
||||
return hotelPage
|
||||
return validatedHotelPage.data.hotel_page
|
||||
}),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user