From a7aefcded1a43343be484c230a2cb9a8e22b214c Mon Sep 17 00:00:00 2001 From: Fredrik Thorsson Date: Thu, 19 Dec 2024 14:32:41 +0100 Subject: [PATCH] feat(SW-543): update requests --- .../Sidebar/JoinLoyaltyContact.graphql | 1 + server/routers/contentstack/base/output.ts | 1 + server/routers/contentstack/base/query.ts | 10 +-- .../routers/contentstack/contentPage/query.ts | 61 +++++++++++-------- .../routers/contentstack/loyaltyPage/query.ts | 19 ++++-- .../schemas/sidebar/joinLoyaltyContact.ts | 2 + types/trpc/routers/contentstack/sidebar.ts | 6 +- types/trpc/routers/contentstack/siteConfig.ts | 4 +- utils/contactConfig.ts | 2 +- 9 files changed, 64 insertions(+), 42 deletions(-) diff --git a/lib/graphql/Fragments/Sidebar/JoinLoyaltyContact.graphql b/lib/graphql/Fragments/Sidebar/JoinLoyaltyContact.graphql index cb9886b91..8b87aa0fa 100644 --- a/lib/graphql/Fragments/Sidebar/JoinLoyaltyContact.graphql +++ b/lib/graphql/Fragments/Sidebar/JoinLoyaltyContact.graphql @@ -14,6 +14,7 @@ fragment ContactFields on ContactFields { display_text contact_field footnote + select_test } fragment JoinLoyaltyContactSidebar_ContentPage on ContentPageSidebarJoinLoyaltyContact { diff --git a/server/routers/contentstack/base/output.ts b/server/routers/contentstack/base/output.ts index a976a01a4..7ff1880b2 100644 --- a/server/routers/contentstack/base/output.ts +++ b/server/routers/contentstack/base/output.ts @@ -78,6 +78,7 @@ export type ContactFields = { display_text: string | null contact_field: string footnote: string | null + selectTest: string } export const validateCurrentHeaderConfigSchema = z diff --git a/server/routers/contentstack/base/query.ts b/server/routers/contentstack/base/query.ts index 8cdb9b0b9..e021786e1 100644 --- a/server/routers/contentstack/base/query.ts +++ b/server/routers/contentstack/base/query.ts @@ -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", diff --git a/server/routers/contentstack/contentPage/query.ts b/server/routers/contentstack/contentPage/query.ts index 02c7419d7..4898a1ac0 100644 --- a/server/routers/contentstack/contentPage/query.ts +++ b/server/routers/contentstack/contentPage/query.ts @@ -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([ - { - document: GetContentPage, - variables: { locale: lang, uid }, - options: { - cache: "force-cache", - next: { - tags, + const [contentPageRequest, contactConfig] = await Promise.all([ + batchRequest([ + { + 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, } }), }) diff --git a/server/routers/contentstack/loyaltyPage/query.ts b/server/routers/contentstack/loyaltyPage/query.ts index f1f4edeec..67dd85c72 100644 --- a/server/routers/contentstack/loyaltyPage/query.ts +++ b/server/routers/contentstack/loyaltyPage/query.ts @@ -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( - GetLoyaltyPage, - variables, - { + const [response, contactConfig] = await Promise.all([ + request(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, } }), }) diff --git a/server/routers/contentstack/schemas/sidebar/joinLoyaltyContact.ts b/server/routers/contentstack/schemas/sidebar/joinLoyaltyContact.ts index ebee0023f..b4eebd278 100644 --- a/server/routers/contentstack/schemas/sidebar/joinLoyaltyContact.ts +++ b/server/routers/contentstack/schemas/sidebar/joinLoyaltyContact.ts @@ -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, } }) ), diff --git a/types/trpc/routers/contentstack/sidebar.ts b/types/trpc/routers/contentstack/sidebar.ts index b0998fb95..813f10d88 100644 --- a/types/trpc/routers/contentstack/sidebar.ts +++ b/types/trpc/routers/contentstack/sidebar.ts @@ -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 {} diff --git a/types/trpc/routers/contentstack/siteConfig.ts b/types/trpc/routers/contentstack/siteConfig.ts index 51ca2a6d8..2d7acc074 100644 --- a/types/trpc/routers/contentstack/siteConfig.ts +++ b/types/trpc/routers/contentstack/siteConfig.ts @@ -1,6 +1,6 @@ -import { z } from "zod" +import type { z } from "zod" -import { +import type { alertSchema, siteConfigRefSchema, siteConfigSchema, diff --git a/utils/contactConfig.ts b/utils/contactConfig.ts index fadf5b2b4..82930a03a 100644 --- a/utils/contactConfig.ts +++ b/utils/contactConfig.ts @@ -1,4 +1,4 @@ -import { +import type { ContactConfig, ContactFieldGroups, } from "@/server/routers/contentstack/base/output"