feat(SW-543): update requests

This commit is contained in:
Fredrik Thorsson
2024-12-19 14:32:41 +01:00
parent c976d187be
commit a7aefcded1
9 changed files with 64 additions and 42 deletions

View File

@@ -78,6 +78,7 @@ export type ContactFields = {
display_text: string | null
contact_field: string
footnote: string | null
selectTest: string
}
export const validateCurrentHeaderConfigSchema = z

View File

@@ -1,6 +1,5 @@
import { cache } from "react"
import { Lang } from "@/constants/languages"
import { GetContactConfig } from "@/lib/graphql/Query/ContactConfig.graphql"
import {
GetCurrentFooter,
@@ -30,9 +29,9 @@ import {
import { langInput } from "./input"
import {
type ContactConfigData,
CurrentFooterDataRaw,
CurrentFooterRefDataRaw,
CurrentHeaderRefDataRaw,
type CurrentFooterDataRaw,
type CurrentFooterRefDataRaw,
type CurrentHeaderRefDataRaw,
type GetCurrentHeaderData,
headerRefsSchema,
headerSchema,
@@ -94,8 +93,9 @@ import type {
GetSiteConfigData,
GetSiteConfigRefData,
} from "@/types/trpc/routers/contentstack/siteConfig"
import type { Lang } from "@/constants/languages"
const getContactConfig = cache(async (lang: Lang) => {
export const getContactConfig = cache(async (lang: Lang) => {
getContactConfigCounter.add(1, { lang })
console.info(
"contentstack.contactConfig start",

View File

@@ -6,6 +6,7 @@ import {
} from "@/lib/graphql/Query/ContentPage/ContentPage.graphql"
import { contentstackExtendedProcedureUID, router } from "@/server/trpc"
import { getContactConfig } from "../base/query"
import { contentPageSchema } from "./output"
import {
createChannel,
@@ -39,41 +40,46 @@ export const contentPageQueryRouter = router({
})
)
const contentPageRequest = await batchRequest<GetContentPageSchema>([
{
document: GetContentPage,
variables: { locale: lang, uid },
options: {
cache: "force-cache",
next: {
tags,
const [contentPageRequest, contactConfig] = await Promise.all([
batchRequest<GetContentPageSchema>([
{
document: GetContentPage,
variables: { locale: lang, uid },
options: {
cache: "force-cache",
next: {
tags,
},
},
},
},
{
document: GetContentPageBlocksBatch1,
variables: { locale: lang, uid },
options: {
cache: "force-cache",
next: {
tags,
{
document: GetContentPageBlocksBatch1,
variables: { locale: lang, uid },
options: {
cache: "force-cache",
next: {
tags,
},
},
},
},
{
document: GetContentPageBlocksBatch2,
variables: { locale: lang, uid },
options: {
cache: "force-cache",
next: {
tags,
{
document: GetContentPageBlocksBatch2,
variables: { locale: lang, uid },
options: {
cache: "force-cache",
next: {
tags,
},
},
},
},
]),
getContactConfig(lang),
])
console.log("Content page log", contentPageRequest, contactConfig)
const contentPage = contentPageSchema.safeParse(contentPageRequest.data)
if (!contentPage.success) {
console.error(
@@ -95,9 +101,14 @@ export const contentPageQueryRouter = router({
siteVersion: "new-web",
}
const footnote = contactConfig?.phone.footnote
? contactConfig.phone.footnote
: null
return {
contentPage: contentPage.data.content_page,
tracking,
footnote,
}
}),
})

View File

@@ -14,6 +14,7 @@ import {
generateTagsFromSystem,
} from "@/utils/generateTag"
import { getContactConfig } from "../base/query"
import { loyaltyPageRefsSchema, loyaltyPageSchema } from "./output"
import { getConnections } from "./utils"
@@ -129,14 +130,13 @@ export const loyaltyPageQueryRouter = router({
query: metricsVariables,
})
)
const response = await request<GetLoyaltyPageSchema>(
GetLoyaltyPage,
variables,
{
const [response, contactConfig] = await Promise.all([
request<GetLoyaltyPageSchema>(GetLoyaltyPage, variables, {
cache: "force-cache",
next: { tags },
}
)
}),
getContactConfig(lang),
])
if (!response.data) {
const notFoundError = notFound(response)
@@ -172,6 +172,8 @@ export const loyaltyPageQueryRouter = router({
return null
}
console.log("Loyalty page log: ", response, contactConfig)
const loyaltyPage = validatedLoyaltyPage.data.loyalty_page
const loyaltyTrackingData: TrackingSDKPageData = {
@@ -191,10 +193,15 @@ export const loyaltyPageQueryRouter = router({
JSON.stringify({ query: metricsVariables })
)
const footnote = contactConfig?.phone.footnote
? contactConfig.phone.footnote
: null
// Assert LoyaltyPage type to get correct typings for RTE fields
return {
loyaltyPage,
tracking: loyaltyTrackingData,
footnote,
}
}),
})

View File

@@ -23,6 +23,7 @@ export const contactSchema = z.object({
contact_field: z.string(),
display_text: z.string().optional().nullable().default(null),
footnote: z.string().optional().nullable().default(null),
select_test: z.string(),
}),
})
.transform((data) => {
@@ -32,6 +33,7 @@ export const contactSchema = z.object({
contact_field: data.contact.contact_field,
display_text: data.contact.display_text,
footnote: data.contact.footnote,
selectTest: data.contact.select_test,
}
})
),