feat: add tracking to account pages
This commit is contained in:
@@ -189,3 +189,17 @@ export const validateAccountPageRefsSchema = z.object({
|
||||
export type AccountPageRefsDataRaw = z.infer<
|
||||
typeof validateAccountPageRefsSchema
|
||||
>
|
||||
|
||||
//Tracking
|
||||
const validateAccountTrackingData = z.object({
|
||||
account_page: z.object({
|
||||
system: z.object({
|
||||
uid: z.string(),
|
||||
locale: z.string(),
|
||||
updated_at: z.string(),
|
||||
created_at: z.string(),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
|
||||
export type AccountPageTackingData = z.infer<typeof validateAccountTrackingData>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { Lang } from "@/constants/languages"
|
||||
import {
|
||||
GetAccountPage,
|
||||
GetAccountPageRefs,
|
||||
GetTrackingAccountPage,
|
||||
} from "@/lib/graphql/Query/AccountPage.graphql"
|
||||
import { request } from "@/lib/graphql/request"
|
||||
import { notFound } from "@/server/errors/trpc"
|
||||
@@ -17,12 +19,17 @@ import {
|
||||
type AccountPage,
|
||||
AccountPageDataRaw,
|
||||
AccountPageRefsDataRaw,
|
||||
AccountPageTackingData,
|
||||
validateAccountPageRefsSchema,
|
||||
validateAccountPageSchema,
|
||||
} from "./output"
|
||||
import { getConnections } from "./utils"
|
||||
|
||||
import { ContentEntries } from "@/types/components/myPages/myPage/enums"
|
||||
import {
|
||||
TrackingChannelEnum,
|
||||
TrackingSDKPageData,
|
||||
} from "@/types/components/tracking"
|
||||
import { Embeds } from "@/types/requests/embeds"
|
||||
import { Edges } from "@/types/requests/utils/edges"
|
||||
import { RTEDocument } from "@/types/rte/node"
|
||||
@@ -131,4 +138,29 @@ export const accountPageQueryRouter = router({
|
||||
|
||||
return accountPage
|
||||
}),
|
||||
tracking: contentstackExtendedProcedureUID.query(async ({ ctx }) => {
|
||||
const { lang, uid } = ctx
|
||||
|
||||
const response = await request<AccountPageTackingData>(
|
||||
GetTrackingAccountPage,
|
||||
{
|
||||
locale: lang,
|
||||
uid,
|
||||
}
|
||||
)
|
||||
|
||||
if (!response.data) {
|
||||
throw notFound(response)
|
||||
}
|
||||
|
||||
const accountTrackingData: TrackingSDKPageData = {
|
||||
pageId: response.data.account_page.system.uid,
|
||||
lang: response.data.account_page.system.locale as Lang,
|
||||
publishedDate: response.data.account_page.system.updated_at,
|
||||
createdDate: response.data.account_page.system.created_at,
|
||||
channel: TrackingChannelEnum["scandic-friends"],
|
||||
}
|
||||
|
||||
return accountTrackingData
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -417,3 +417,17 @@ export const validateLoyaltyPageRefsSchema = z.object({
|
||||
export type LoyaltyPageRefsDataRaw = z.infer<
|
||||
typeof validateLoyaltyPageRefsSchema
|
||||
>
|
||||
|
||||
//Tracking
|
||||
const validateLoyaltyTrackingData = z.object({
|
||||
loyalty_page: z.object({
|
||||
system: z.object({
|
||||
uid: z.string(),
|
||||
locale: z.string(),
|
||||
updated_at: z.string(),
|
||||
created_at: z.string(),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
|
||||
export type LoyaltyPageTackingData = z.infer<typeof validateLoyaltyTrackingData>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { Lang } from "@/constants/languages"
|
||||
import {
|
||||
GetLoyaltyPage,
|
||||
GetLoyaltyPageRefs,
|
||||
@@ -19,6 +20,7 @@ import { removeEmptyObjects } from "../../utils"
|
||||
import {
|
||||
LoyaltyPage,
|
||||
type LoyaltyPageRefsDataRaw,
|
||||
LoyaltyPageTackingData,
|
||||
validateLoyaltyPageRefsSchema,
|
||||
validateLoyaltyPageSchema,
|
||||
} from "./output"
|
||||
@@ -232,10 +234,13 @@ export const loyaltyPageQueryRouter = router({
|
||||
tracking: contentstackExtendedProcedureUID.query(async ({ ctx }) => {
|
||||
const { lang, uid } = ctx
|
||||
|
||||
const response = await request<any>(GetTrackingLoyaltyPage, {
|
||||
locale: lang,
|
||||
uid,
|
||||
})
|
||||
const response = await request<LoyaltyPageTackingData>(
|
||||
GetTrackingLoyaltyPage,
|
||||
{
|
||||
locale: lang,
|
||||
uid,
|
||||
}
|
||||
)
|
||||
|
||||
if (!response.data) {
|
||||
throw notFound(response)
|
||||
@@ -243,8 +248,8 @@ export const loyaltyPageQueryRouter = router({
|
||||
|
||||
const loyaltyTrackingData: TrackingSDKPageData = {
|
||||
pageId: response.data.loyalty_page.system.uid,
|
||||
lang: response.data.loyalty_page.system.locale,
|
||||
publishedDate: response.data.loyalty_page.system.published_at,
|
||||
lang: response.data.loyalty_page.system.locale as Lang,
|
||||
publishedDate: response.data.loyalty_page.system.updated_at,
|
||||
createdDate: response.data.loyalty_page.system.created_at,
|
||||
channel: TrackingChannelEnum["scandic-friends"],
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user