feat(SW-543): update requests
This commit is contained in:
@@ -14,6 +14,7 @@ fragment ContactFields on ContactFields {
|
||||
display_text
|
||||
contact_field
|
||||
footnote
|
||||
select_test
|
||||
}
|
||||
|
||||
fragment JoinLoyaltyContactSidebar_ContentPage on ContentPageSidebarJoinLoyaltyContact {
|
||||
|
||||
@@ -78,6 +78,7 @@ export type ContactFields = {
|
||||
display_text: string | null
|
||||
contact_field: string
|
||||
footnote: string | null
|
||||
selectTest: string
|
||||
}
|
||||
|
||||
export const validateCurrentHeaderConfigSchema = z
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
})
|
||||
),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { z } from "zod"
|
||||
import type { z } from "zod"
|
||||
|
||||
import { joinLoyaltyContactSidebarSchema } from "@/server/routers/contentstack/loyaltyPage/output"
|
||||
import { contactSchema } from "@/server/routers/contentstack/schemas/sidebar/joinLoyaltyContact"
|
||||
import type { joinLoyaltyContactSidebarSchema } from "@/server/routers/contentstack/loyaltyPage/output"
|
||||
import type { contactSchema } from "@/server/routers/contentstack/schemas/sidebar/joinLoyaltyContact"
|
||||
|
||||
export interface JoinLoyaltyContact
|
||||
extends z.output<typeof joinLoyaltyContactSidebarSchema> {}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { z } from "zod"
|
||||
import type { z } from "zod"
|
||||
|
||||
import {
|
||||
import type {
|
||||
alertSchema,
|
||||
siteConfigRefSchema,
|
||||
siteConfigSchema,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {
|
||||
import type {
|
||||
ContactConfig,
|
||||
ContactFieldGroups,
|
||||
} from "@/server/routers/contentstack/base/output"
|
||||
|
||||
Reference in New Issue
Block a user