Merged in feat/SW-1442-destination-overview-page (pull request #1188)
feat(SW-1442): added destination overview page * feat(SW-1442): added destination overview page Approved-by: Fredrik Thorsson Approved-by: Matilda Landström
This commit is contained in:
@@ -10,11 +10,12 @@ const bookingWidgetToggleSchema = z
|
||||
|
||||
export const validateBookingWidgetToggleSchema = z.object({
|
||||
account_page: bookingWidgetToggleSchema,
|
||||
loyalty_page: bookingWidgetToggleSchema,
|
||||
collection_page: bookingWidgetToggleSchema,
|
||||
content_page: bookingWidgetToggleSchema,
|
||||
hotel_page: bookingWidgetToggleSchema,
|
||||
current_blocks_page: bookingWidgetToggleSchema,
|
||||
destination_overview_page: bookingWidgetToggleSchema,
|
||||
hotel_page: bookingWidgetToggleSchema,
|
||||
loyalty_page: bookingWidgetToggleSchema,
|
||||
})
|
||||
|
||||
export type ValidateBookingWidgetToggleType = z.infer<
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
GetCollectionPageSettings,
|
||||
GetContentPageSettings,
|
||||
GetCurrentBlocksPageSettings,
|
||||
GetDestinationOverviewPageSettings,
|
||||
GetHotelPageSettings,
|
||||
GetLoyaltyPageSettings,
|
||||
} from "@/lib/graphql/Query/BookingWidgetToggle.graphql"
|
||||
@@ -50,6 +51,9 @@ export const bookingwidgetQueryRouter = router({
|
||||
case PageContentTypeEnum.contentPage:
|
||||
GetPageSettings = GetContentPageSettings
|
||||
break
|
||||
case PageContentTypeEnum.destinationOverviewPage:
|
||||
GetPageSettings = GetDestinationOverviewPageSettings
|
||||
break
|
||||
case PageContentTypeEnum.hotelPage:
|
||||
GetPageSettings = GetHotelPageSettings
|
||||
break
|
||||
|
||||
@@ -13,6 +13,10 @@ import {
|
||||
GetContentPageBreadcrumbs,
|
||||
GetContentPageBreadcrumbsRefs,
|
||||
} from "@/lib/graphql/Query/Breadcrumbs/ContentPage.graphql"
|
||||
import {
|
||||
GetDestinationOverviewPageBreadcrumbs,
|
||||
GetDestinationOverviewPageBreadcrumbsRefs,
|
||||
} from "@/lib/graphql/Query/Breadcrumbs/DestinationOverviewPage.graphql"
|
||||
import {
|
||||
GetHotelPageBreadcrumbs,
|
||||
GetHotelPageBreadcrumbsRefs,
|
||||
@@ -203,6 +207,17 @@ export const breadcrumbsQueryRouter = router({
|
||||
},
|
||||
variables
|
||||
)
|
||||
case PageContentTypeEnum.destinationOverviewPage:
|
||||
return await getBreadcrumbs<{
|
||||
destination_overview_page: RawBreadcrumbsSchema
|
||||
}>(
|
||||
{
|
||||
dataKey: "destination_overview_page",
|
||||
refQuery: GetDestinationOverviewPageBreadcrumbsRefs,
|
||||
query: GetDestinationOverviewPageBreadcrumbs,
|
||||
},
|
||||
variables
|
||||
)
|
||||
case PageContentTypeEnum.hotelPage:
|
||||
return await getBreadcrumbs<{
|
||||
hotel_page: RawBreadcrumbsSchema
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import { mergeRouters } from "@/server/trpc"
|
||||
|
||||
import { destinationOverviewPageQueryRouter } from "./query"
|
||||
|
||||
export const destinationOverviewPageRouter = mergeRouters(
|
||||
destinationOverviewPageQueryRouter
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { systemSchema } from "../schemas/system"
|
||||
|
||||
export const destinationOverviewPageSchema = z.object({
|
||||
destination_overview_page: z.object({
|
||||
title: z.string(),
|
||||
system: systemSchema.merge(
|
||||
z.object({
|
||||
created_at: z.string(),
|
||||
updated_at: z.string(),
|
||||
})
|
||||
),
|
||||
}),
|
||||
trackingProps: z.object({
|
||||
url: z.string(),
|
||||
}),
|
||||
})
|
||||
|
||||
/** REFS */
|
||||
export const destinationOverviewPageRefsSchema = z.object({
|
||||
destination_overview_page: z.object({
|
||||
system: systemSchema,
|
||||
}),
|
||||
})
|
||||
190
server/routers/contentstack/destinationOverviewPage/query.ts
Normal file
190
server/routers/contentstack/destinationOverviewPage/query.ts
Normal file
@@ -0,0 +1,190 @@
|
||||
import {
|
||||
GetDestinationOverviewPage,
|
||||
GetDestinationOverviewPageRefs,
|
||||
} from "@/lib/graphql/Query/DestinationOverviewPage/DestinationOverviewPage.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 {
|
||||
destinationOverviewPageRefsSchema,
|
||||
destinationOverviewPageSchema,
|
||||
} from "./output"
|
||||
import {
|
||||
getDestinationOverviewPageCounter,
|
||||
getDestinationOverviewPageFailCounter,
|
||||
getDestinationOverviewPageRefsCounter,
|
||||
getDestinationOverviewPageRefsFailCounter,
|
||||
getDestinationOverviewPageRefsSuccessCounter,
|
||||
getDestinationOverviewPageSuccessCounter,
|
||||
} from "./telemetry"
|
||||
|
||||
import {
|
||||
TrackingChannelEnum,
|
||||
type TrackingSDKPageData,
|
||||
} from "@/types/components/tracking"
|
||||
import type {
|
||||
GetDestinationOverviewPageData,
|
||||
GetDestinationOverviewPageRefsSchema,
|
||||
} from "@/types/trpc/routers/contentstack/destinationOverviewPage"
|
||||
|
||||
export const destinationOverviewPageQueryRouter = router({
|
||||
get: contentstackExtendedProcedureUID.query(async ({ ctx }) => {
|
||||
const { lang, uid } = ctx
|
||||
|
||||
getDestinationOverviewPageRefsCounter.add(1, { lang, uid: `${uid}` })
|
||||
console.info(
|
||||
"contentstack.destinationOverviewPage.refs start",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
})
|
||||
)
|
||||
const refsResponse = await request<GetDestinationOverviewPageRefsSchema>(
|
||||
GetDestinationOverviewPageRefs,
|
||||
{
|
||||
locale: lang,
|
||||
uid,
|
||||
},
|
||||
{
|
||||
cache: "force-cache",
|
||||
next: {
|
||||
tags: [generateTag(lang, uid)],
|
||||
},
|
||||
}
|
||||
)
|
||||
if (!refsResponse.data) {
|
||||
const notFoundError = notFound(refsResponse)
|
||||
getDestinationOverviewPageRefsFailCounter.add(1, {
|
||||
lang,
|
||||
uid,
|
||||
error_type: "not_found",
|
||||
error: JSON.stringify({ code: notFoundError.code }),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.destinationOverviewPage.refs not found error",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: { code: notFoundError.code },
|
||||
})
|
||||
)
|
||||
throw notFoundError
|
||||
}
|
||||
|
||||
const validatedRefsData = destinationOverviewPageRefsSchema.safeParse(
|
||||
refsResponse.data
|
||||
)
|
||||
|
||||
if (!validatedRefsData.success) {
|
||||
getDestinationOverviewPageRefsFailCounter.add(1, {
|
||||
lang,
|
||||
uid,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedRefsData.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.destinationOverviewPage.refs validation error",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: validatedRefsData.error,
|
||||
})
|
||||
)
|
||||
return null
|
||||
}
|
||||
|
||||
getDestinationOverviewPageRefsSuccessCounter.add(1, { lang, uid: `${uid}` })
|
||||
console.info(
|
||||
"contentstack.destinationOverviewPage.refs success",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
})
|
||||
)
|
||||
|
||||
getDestinationOverviewPageCounter.add(1, { lang, uid: `${uid}` })
|
||||
console.info(
|
||||
"contentstack.destinationOverviewPage start",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
})
|
||||
)
|
||||
const response = await request<GetDestinationOverviewPageData>(
|
||||
GetDestinationOverviewPage,
|
||||
{
|
||||
locale: lang,
|
||||
uid,
|
||||
},
|
||||
{
|
||||
cache: "force-cache",
|
||||
next: {
|
||||
tags: [generateTag(lang, uid)],
|
||||
},
|
||||
}
|
||||
)
|
||||
if (!response.data) {
|
||||
const notFoundError = notFound(response)
|
||||
getDestinationOverviewPageFailCounter.add(1, {
|
||||
lang,
|
||||
uid: `${uid}`,
|
||||
error_type: "not_found",
|
||||
error: JSON.stringify({ code: notFoundError.code }),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.destinationOverviewPage not found error",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: { code: notFoundError.code },
|
||||
})
|
||||
)
|
||||
throw notFoundError
|
||||
}
|
||||
|
||||
const destinationOverviewPage = destinationOverviewPageSchema.safeParse(
|
||||
response.data
|
||||
)
|
||||
|
||||
if (!destinationOverviewPage.success) {
|
||||
getDestinationOverviewPageFailCounter.add(1, {
|
||||
lang,
|
||||
uid: `${uid}`,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(destinationOverviewPage.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.destinationOverviewPage validation error",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: destinationOverviewPage.error,
|
||||
})
|
||||
)
|
||||
return null
|
||||
}
|
||||
|
||||
getDestinationOverviewPageSuccessCounter.add(1, { lang, uid: `${uid}` })
|
||||
console.info(
|
||||
"contentstack.destinationOverviewPage success",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
})
|
||||
)
|
||||
|
||||
const system = destinationOverviewPage.data.destination_overview_page.system
|
||||
const tracking: TrackingSDKPageData = {
|
||||
pageId: system.uid,
|
||||
domainLanguage: lang,
|
||||
publishDate: system.updated_at,
|
||||
createDate: system.created_at,
|
||||
channel: TrackingChannelEnum["destination-overview-page"],
|
||||
pageType: "staticcontentpage",
|
||||
pageName: destinationOverviewPage.data.trackingProps.url,
|
||||
siteSections: destinationOverviewPage.data.trackingProps.url,
|
||||
siteVersion: "new-web",
|
||||
}
|
||||
|
||||
return {
|
||||
destinationOverviewPage:
|
||||
destinationOverviewPage.data.destination_overview_page,
|
||||
tracking,
|
||||
}
|
||||
}),
|
||||
})
|
||||
@@ -0,0 +1,23 @@
|
||||
import { metrics } from "@opentelemetry/api"
|
||||
|
||||
const meter = metrics.getMeter("trpc.contentstack.destinationOverviewPage")
|
||||
|
||||
export const getDestinationOverviewPageRefsCounter = meter.createCounter(
|
||||
"trpc.contentstack.destinationOverviewPage.get"
|
||||
)
|
||||
export const getDestinationOverviewPageRefsFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.destinationOverviewPage.get-fail"
|
||||
)
|
||||
export const getDestinationOverviewPageRefsSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.destinationOverviewPage.get-success"
|
||||
)
|
||||
|
||||
export const getDestinationOverviewPageCounter = meter.createCounter(
|
||||
"trpc.contentstack.destinationOverviewPage.get"
|
||||
)
|
||||
export const getDestinationOverviewPageSuccessCounter = meter.createCounter(
|
||||
"trpc.contentstack.destinationOverviewPage.get-success"
|
||||
)
|
||||
export const getDestinationOverviewPageFailCounter = meter.createCounter(
|
||||
"trpc.contentstack.destinationOverviewPage.get-fail"
|
||||
)
|
||||
@@ -6,6 +6,7 @@ import { bookingwidgetRouter } from "./bookingwidget"
|
||||
import { breadcrumbsRouter } from "./breadcrumbs"
|
||||
import { collectionPageRouter } from "./collectionPage"
|
||||
import { contentPageRouter } from "./contentPage"
|
||||
import { destinationOverviewPageRouter } from "./destinationOverviewPage"
|
||||
import { hotelPageRouter } from "./hotelPage"
|
||||
import { languageSwitcherRouter } from "./languageSwitcher"
|
||||
import { loyaltyLevelRouter } from "./loyaltyLevel"
|
||||
@@ -24,6 +25,7 @@ export const contentstackRouter = router({
|
||||
loyaltyPage: loyaltyPageRouter,
|
||||
collectionPage: collectionPageRouter,
|
||||
contentPage: contentPageRouter,
|
||||
destinationOverviewPage: destinationOverviewPageRouter,
|
||||
myPages: myPagesRouter,
|
||||
metadata: metadataRouter,
|
||||
rewards: rewardRouter,
|
||||
|
||||
@@ -19,6 +19,10 @@ import {
|
||||
GetDaDeEnUrlsCurrentBlocksPage,
|
||||
GetFiNoSvUrlsCurrentBlocksPage,
|
||||
} from "@/lib/graphql/Query/Current/LanguageSwitcher.graphql"
|
||||
import {
|
||||
GetDaDeEnUrlsDestinationOverviewPage,
|
||||
GetFiNoSvUrlsDestinationOverviewPage,
|
||||
} from "@/lib/graphql/Query/DestinationOverviewPage/DestinationOverviewPage.graphql"
|
||||
import {
|
||||
GetDaDeEnUrlsHotelPage,
|
||||
GetFiNoSvUrlsHotelPage,
|
||||
@@ -96,6 +100,10 @@ async function getLanguageSwitcher(options: LanguageSwitcherVariables) {
|
||||
daDeEnDocument = GetDaDeEnUrlsCollectionPage
|
||||
fiNoSvDocument = GetFiNoSvUrlsCollectionPage
|
||||
break
|
||||
case PageContentTypeEnum.destinationOverviewPage:
|
||||
daDeEnDocument = GetDaDeEnUrlsDestinationOverviewPage
|
||||
fiNoSvDocument = GetFiNoSvUrlsDestinationOverviewPage
|
||||
break
|
||||
default:
|
||||
console.error(`type: [${options.contentType}]`)
|
||||
console.error(`Trying to get a content type that is not supported`)
|
||||
|
||||
@@ -4,6 +4,7 @@ import { cache } from "react"
|
||||
import { GetAccountPageMetadata } from "@/lib/graphql/Query/AccountPage/Metadata.graphql"
|
||||
import { GetCollectionPageMetadata } from "@/lib/graphql/Query/CollectionPage/Metadata.graphql"
|
||||
import { GetContentPageMetadata } from "@/lib/graphql/Query/ContentPage/Metadata.graphql"
|
||||
import { GetDestinationOverviewPageMetadata } from "@/lib/graphql/Query/DestinationOverviewPage/Metadata.graphql"
|
||||
import { GetHotelPageMetadata } from "@/lib/graphql/Query/HotelPage/Metadata.graphql"
|
||||
import { GetLoyaltyPageMetadata } from "@/lib/graphql/Query/LoyaltyPage/Metadata.graphql"
|
||||
import { request } from "@/lib/graphql/request"
|
||||
@@ -136,6 +137,13 @@ export const metadataQueryRouter = router({
|
||||
content_page: RawMetadataSchema
|
||||
}>(GetContentPageMetadata, variables)
|
||||
return getTransformedMetadata(contentPageResponse.content_page)
|
||||
case PageContentTypeEnum.destinationOverviewPage:
|
||||
const destinationOverviewPageResponse = await fetchMetadata<{
|
||||
destination_overview_page: RawMetadataSchema
|
||||
}>(GetDestinationOverviewPageMetadata, variables)
|
||||
return getTransformedMetadata(
|
||||
destinationOverviewPageResponse.destination_overview_page
|
||||
)
|
||||
case PageContentTypeEnum.loyaltyPage:
|
||||
const loyaltyPageResponse = await fetchMetadata<{
|
||||
loyalty_page: RawMetadataSchema
|
||||
|
||||
Reference in New Issue
Block a user