From 4c99bb2b180b4ea60019518761606dccf265f75b Mon Sep 17 00:00:00 2001 From: Fredrik Thorsson Date: Fri, 20 Dec 2024 14:02:51 +0100 Subject: [PATCH] feat(SW-543): restore requests --- .../JoinLoyalty/Contact/ContactRow/index.tsx | 3 +- server/routers/contentstack/base/query.ts | 2 +- .../routers/contentstack/contentPage/query.ts | 61 ++++++++----------- .../routers/contentstack/loyaltyPage/query.ts | 19 ++---- 4 files changed, 34 insertions(+), 51 deletions(-) diff --git a/components/Sidebar/JoinLoyalty/Contact/ContactRow/index.tsx b/components/Sidebar/JoinLoyalty/Contact/ContactRow/index.tsx index ea66239df..1713df1ba 100644 --- a/components/Sidebar/JoinLoyalty/Contact/ContactRow/index.tsx +++ b/components/Sidebar/JoinLoyalty/Contact/ContactRow/index.tsx @@ -17,6 +17,7 @@ export default async function ContactRow({ contact }: ContactRowProps) { } const val = getValueFromContactConfig(contact.contact_field, data) + const test = getValueFromContactConfig(contact.selectTest, data) if (!val) { return null @@ -51,7 +52,7 @@ export default async function ContactRow({ contact }: ContactRowProps) { {Icon ? : null} {val} - {contact.footnote} + {test} ) } diff --git a/server/routers/contentstack/base/query.ts b/server/routers/contentstack/base/query.ts index e021786e1..69c160e22 100644 --- a/server/routers/contentstack/base/query.ts +++ b/server/routers/contentstack/base/query.ts @@ -95,7 +95,7 @@ import type { } from "@/types/trpc/routers/contentstack/siteConfig" import type { Lang } from "@/constants/languages" -export const getContactConfig = cache(async (lang: Lang) => { +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 4898a1ac0..02c7419d7 100644 --- a/server/routers/contentstack/contentPage/query.ts +++ b/server/routers/contentstack/contentPage/query.ts @@ -6,7 +6,6 @@ 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, @@ -40,46 +39,41 @@ export const contentPageQueryRouter = router({ }) ) - const [contentPageRequest, contactConfig] = await Promise.all([ - batchRequest([ - { - document: GetContentPage, - variables: { locale: lang, uid }, - options: { - cache: "force-cache", - next: { - tags, - }, + const contentPageRequest = await 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( @@ -101,14 +95,9 @@ 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 67dd85c72..f1f4edeec 100644 --- a/server/routers/contentstack/loyaltyPage/query.ts +++ b/server/routers/contentstack/loyaltyPage/query.ts @@ -14,7 +14,6 @@ import { generateTagsFromSystem, } from "@/utils/generateTag" -import { getContactConfig } from "../base/query" import { loyaltyPageRefsSchema, loyaltyPageSchema } from "./output" import { getConnections } from "./utils" @@ -130,13 +129,14 @@ export const loyaltyPageQueryRouter = router({ query: metricsVariables, }) ) - const [response, contactConfig] = await Promise.all([ - request(GetLoyaltyPage, variables, { + const response = await request( + GetLoyaltyPage, + variables, + { cache: "force-cache", next: { tags }, - }), - getContactConfig(lang), - ]) + } + ) if (!response.data) { const notFoundError = notFound(response) @@ -172,8 +172,6 @@ export const loyaltyPageQueryRouter = router({ return null } - console.log("Loyalty page log: ", response, contactConfig) - const loyaltyPage = validatedLoyaltyPage.data.loyalty_page const loyaltyTrackingData: TrackingSDKPageData = { @@ -193,15 +191,10 @@ 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, } }), })