-
+
{_("Already a friend?")}
{_("Click here to log in")}
diff --git a/components/Loyalty/Sidebar/JoinLoyalty/joinLoyalty.module.css b/components/Loyalty/Sidebar/JoinLoyalty/joinLoyalty.module.css
index a2983576f..442cb4dc0 100644
--- a/components/Loyalty/Sidebar/JoinLoyalty/joinLoyalty.module.css
+++ b/components/Loyalty/Sidebar/JoinLoyalty/joinLoyalty.module.css
@@ -21,7 +21,7 @@
margin: 0;
}
-.logoutLink {
+.loginLink {
text-decoration: none;
color: var(--some-black-color, #2e2e2e);
font-size: 1.2rem;
diff --git a/components/Loyalty/Sidebar/index.tsx b/components/Loyalty/Sidebar/index.tsx
index 12cdc81f6..75fdcf92f 100644
--- a/components/Loyalty/Sidebar/index.tsx
+++ b/components/Loyalty/Sidebar/index.tsx
@@ -7,20 +7,26 @@ import styles from "./sidebar.module.css"
import { SidebarProps } from "@/types/components/loyalty/sidebar"
import { SidebarTypenameEnum } from "@/types/requests/loyaltyPage"
-export default function SidebarLoyalty({ block }: SidebarProps) {
- switch (block.__typename) {
- case SidebarTypenameEnum.LoyaltyPageSidebarContent:
- return (
-
- )
- case SidebarTypenameEnum.LoyaltyPageSidebarJoinLoyaltyContact:
- return
- default:
- return null
- }
+export default function SidebarLoyalty({ blocks }: SidebarProps) {
+ return (
+
+ )
}
diff --git a/components/Loyalty/Sidebar/sidebar.module.css b/components/Loyalty/Sidebar/sidebar.module.css
index 71e960078..b757da7a0 100644
--- a/components/Loyalty/Sidebar/sidebar.module.css
+++ b/components/Loyalty/Sidebar/sidebar.module.css
@@ -1,9 +1,5 @@
-.content {
- padding: 0 1.6rem;
-}
-
-@media screen and (min-width: 950px) {
+@media screen and (max-width: 950px) {
.content {
- padding: 0;
+ padding: 0 1.6rem;
}
}
diff --git a/components/TempDesignSystem/Card/index.tsx b/components/TempDesignSystem/Card/index.tsx
index 11523155c..afb352530 100644
--- a/components/TempDesignSystem/Card/index.tsx
+++ b/components/TempDesignSystem/Card/index.tsx
@@ -15,7 +15,7 @@ export default function Card({
openInNewTab = false,
}: CardProps) {
return (
-
+
{title ? (
{title}
@@ -33,6 +33,6 @@ export default function Card({
) : null}
-
+
)
}
diff --git a/lib/graphql/Query/LoyaltyPage.graphql b/lib/graphql/Query/LoyaltyPage.graphql
index 743df0539..b308e6680 100644
--- a/lib/graphql/Query/LoyaltyPage.graphql
+++ b/lib/graphql/Query/LoyaltyPage.graphql
@@ -7,8 +7,8 @@ query GetLoyaltyPage($locale: String!, $url: String!) {
all_loyalty_page(where: { url: $url, locale: $locale }) {
items {
blocks {
+ __typename
... on LoyaltyPageBlocksDynamicContent {
- __typename
dynamic_content {
title
subtitle
@@ -28,7 +28,6 @@ query GetLoyaltyPage($locale: String!, $url: String!) {
}
}
... on LoyaltyPageBlocksCardGrid {
- __typename
card_grid {
title
subtitle
@@ -51,7 +50,6 @@ query GetLoyaltyPage($locale: String!, $url: String!) {
}
}
... on LoyaltyPageBlocksContent {
- __typename
content {
content {
json
@@ -70,8 +68,8 @@ query GetLoyaltyPage($locale: String!, $url: String!) {
}
title
sidebar {
+ __typename
... on LoyaltyPageSidebarJoinLoyaltyContact {
- __typename
join_loyalty_contact {
title
preamble
@@ -87,7 +85,6 @@ query GetLoyaltyPage($locale: String!, $url: String!) {
}
}
... on LoyaltyPageSidebarContent {
- __typename
content {
content {
json
diff --git a/server/routers/contentstack/contactConfig/input.ts b/server/routers/contentstack/contactConfig/input.ts
new file mode 100644
index 000000000..b6be31232
--- /dev/null
+++ b/server/routers/contentstack/contactConfig/input.ts
@@ -0,0 +1,5 @@
+import { z } from "zod"
+
+import { Lang } from "@/constants/languages"
+
+export const getConfigInput = z.object({ lang: z.nativeEnum(Lang) })
diff --git a/server/routers/contentstack/contactConfig/output.ts b/server/routers/contentstack/contactConfig/output.ts
new file mode 100644
index 000000000..c42a19dc9
--- /dev/null
+++ b/server/routers/contentstack/contactConfig/output.ts
@@ -0,0 +1,60 @@
+import { z } from "zod"
+
+// Help me write this zod schema based on the type ContactConfig
+export const validateContactConfigSchema = z.object({
+ all_contact_config: z.object({
+ items: z.array(
+ z.object({
+ email: z.object({
+ name: z.string().nullable(),
+ address: z.string().nullable(),
+ }),
+ email_loyalty: z.object({
+ name: z.string().nullable(),
+ address: z.string().nullable(),
+ }),
+ mailing_address: z.object({
+ zip: z.string().nullable(),
+ street: z.string().nullable(),
+ name: z.string().nullable(),
+ city: z.string().nullable(),
+ country: z.string().nullable(),
+ }),
+ phone: z.object({
+ number: z.string().nullable(),
+ name: z.string().nullable(),
+ }),
+ phone_loyalty: z.object({
+ number: z.string().nullable(),
+ name: z.string().nullable(),
+ }),
+ visiting_address: z.object({
+ zip: z.string().nullable(),
+ country: z.string().nullable(),
+ city: z.string().nullable(),
+ street: z.string().nullable(),
+ }),
+ })
+ ),
+ }),
+})
+
+export enum ContactFieldGroupsEnum {
+ email = "email",
+ email_loyalty = "email_loyalty",
+ mailing_address = "mailing_address",
+ phone = "phone",
+ phone_loyalty = "phone_loyalty",
+ visiting_address = "visiting_address",
+}
+
+export type ContactFieldGroups = keyof typeof ContactFieldGroupsEnum
+
+export type ContactConfigData = z.infer
+
+export type ContactConfig = ContactConfigData["all_contact_config"]["items"][0]
+
+export type ContactFields = {
+ display_text?: string
+ contact_field: string
+}
diff --git a/server/routers/contentstack/contactConfig/query.ts b/server/routers/contentstack/contactConfig/query.ts
index 83d183c54..6985aee67 100644
--- a/server/routers/contentstack/contactConfig/query.ts
+++ b/server/routers/contentstack/contactConfig/query.ts
@@ -1,32 +1,34 @@
-import { z } from "zod"
-
+import { GetContactConfig } from "@/lib/graphql/Query/ContactConfig.graphql"
+import { request } from "@/lib/graphql/request"
import { badRequestError } from "@/server/errors/trpc"
import { publicProcedure, router } from "@/server/trpc"
-import { request } from "@/lib/graphql/request"
-import { Lang } from "@/constants/languages"
-import GetContactConfig from "@/lib/graphql/Query/ContactConfig.graphql"
-
-import type { GetContactConfigData } from "@/types/requests/contactConfig"
+import { getConfigInput } from "./input"
+import { type ContactConfigData, validateContactConfigSchema } from "./output"
export const contactConfigQueryRouter = router({
- get: publicProcedure
- .input(z.object({ lang: z.nativeEnum(Lang) }))
- .query(async ({ input }) => {
- const contactConfig = await request(
- GetContactConfig,
- {
- locale: input.lang,
- },
- {
- tags: [`contact-config-${input.lang}`],
- }
- )
+ get: publicProcedure.input(getConfigInput).query(async ({ input }) => {
+ try {
+ const contactConfig = await request(GetContactConfig, {
+ locale: input.lang,
+ })
- if (contactConfig.data && contactConfig.data.all_contact_config.total) {
- return contactConfig.data.all_contact_config.items[0]
+ if (!contactConfig.data) {
+ throw badRequestError()
}
+ const validatedContactConfigConfig =
+ validateContactConfigSchema.safeParse(contactConfig.data)
+
+ if (!validatedContactConfigConfig.success) {
+ console.error(validatedContactConfigConfig.error)
+ throw badRequestError()
+ }
+
+ return validatedContactConfigConfig.data.all_contact_config.items[0]
+ } catch (e) {
+ console.log(e)
throw badRequestError()
- }),
+ }
+ }),
})
diff --git a/server/routers/contentstack/index.ts b/server/routers/contentstack/index.ts
index 3f765813d..2841129f4 100644
--- a/server/routers/contentstack/index.ts
+++ b/server/routers/contentstack/index.ts
@@ -1,8 +1,8 @@
import { router } from "@/server/trpc"
import { breadcrumbsRouter } from "./breadcrumbs"
-import { loyaltyPageRouter } from "./loyaltyPage"
import { contactConfigRouter } from "./contactConfig"
+import { loyaltyPageRouter } from "./loyaltyPage"
export const contentstackRouter = router({
breadcrumbs: breadcrumbsRouter,
diff --git a/server/routers/contentstack/loyaltyPage/query.ts b/server/routers/contentstack/loyaltyPage/query.ts
index 0169f7b41..6a23f2a66 100644
--- a/server/routers/contentstack/loyaltyPage/query.ts
+++ b/server/routers/contentstack/loyaltyPage/query.ts
@@ -31,6 +31,7 @@ export const loyaltyPageQueryRouter = router({
)
if (!validatedLoyaltyPage.success) {
+ console.error(validatedLoyaltyPage.error)
throw badRequestError()
}
@@ -68,15 +69,13 @@ export const loyaltyPageQueryRouter = router({
cards: block.card_grid.cards.map((card) => {
return {
...card,
- link:
- card.referenceConnection.totalCount > 0
- ? {
- href: card.referenceConnection.edges[0].node
- .url,
- title:
- card.referenceConnection.edges[0].node.title,
- }
- : undefined,
+ link: card.referenceConnection.totalCount
+ ? {
+ href: card.referenceConnection.edges[0].node.url,
+ title:
+ card.referenceConnection.edges[0].node.title,
+ }
+ : undefined,
}
}),
},
@@ -86,17 +85,16 @@ export const loyaltyPageQueryRouter = router({
...block,
dynamic_content: {
...block.dynamic_content,
- link:
- block.dynamic_content.link.pageConnection.totalCount > 0
- ? {
- text: block.dynamic_content.link.text,
- href: block.dynamic_content.link.pageConnection
- .edges[0].node.url,
- title:
- block.dynamic_content.link.pageConnection.edges[0]
- .node.title,
- }
- : undefined,
+ link: block.dynamic_content.link.pageConnection.totalCount
+ ? {
+ text: block.dynamic_content.link.text,
+ href: block.dynamic_content.link.pageConnection
+ .edges[0].node.url,
+ title:
+ block.dynamic_content.link.pageConnection.edges[0]
+ .node.title,
+ }
+ : undefined,
},
}
case LoyaltyBlocksTypenameEnum.LoyaltyPageBlocksContent:
diff --git a/server/trpc.ts b/server/trpc.ts
index 428e38796..95d575418 100644
--- a/server/trpc.ts
+++ b/server/trpc.ts
@@ -1,11 +1,12 @@
import { initTRPC } from "@trpc/server"
import { env } from "@/env/server"
-import { transformer } from "./transformer"
-import { unauthorizedError } from "./errors/trpc"
-import type { Context } from "./context"
+import { unauthorizedError } from "./errors/trpc"
+import { transformer } from "./transformer"
+
import type { Meta } from "@/types/trpc/meta"
+import type { Context } from "./context"
const t = initTRPC.context().meta().create({ transformer })
diff --git a/types/components/loyalty/blocks.ts b/types/components/loyalty/blocks.ts
index b3fc03c85..2c73c8d58 100644
--- a/types/components/loyalty/blocks.ts
+++ b/types/components/loyalty/blocks.ts
@@ -1,7 +1,6 @@
import {
Block,
CardGrid,
- CardGridCard,
DynamicContent,
RteBlockContent,
} from "@/server/routers/contentstack/loyaltyPage/output"
@@ -18,8 +17,6 @@ export type DynamicComponentProps = {
component: DynamicContent["dynamic_content"]["component"]
}
-export type CardProps = { card: CardGridCard }
-
export type CardGridProps = Pick
export type Content = { content: RteBlockContent["content"]["content"] }
diff --git a/types/components/loyalty/sidebar.ts b/types/components/loyalty/sidebar.ts
index e1bdb1098..60ef2b99f 100644
--- a/types/components/loyalty/sidebar.ts
+++ b/types/components/loyalty/sidebar.ts
@@ -1,10 +1,11 @@
+import { ContactFields } from "@/server/routers/contentstack/contactConfig/output"
import {
JoinLoyaltyContact,
Sidebar,
} from "@/server/routers/contentstack/loyaltyPage/output"
export type SidebarProps = {
- block: Sidebar
+ blocks: Sidebar[]
}
export type JoinLoyaltyContactProps = {
@@ -14,3 +15,7 @@ export type JoinLoyaltyContactProps = {
export type ContactProps = {
contactBlock: JoinLoyaltyContact["join_loyalty_contact"]["contact"]
}
+
+export type ContactRowProps = {
+ contact: ContactFields
+}
diff --git a/types/requests/contactConfig.ts b/types/requests/contactConfig.ts
deleted file mode 100644
index d68090d16..000000000
--- a/types/requests/contactConfig.ts
+++ /dev/null
@@ -1,53 +0,0 @@
-import { AllRequestResponse } from "./utils/all"
-
-export type ContactConfig = {
- email: {
- name?: string
- address?: string
- }
- email_loyalty: {
- name?: string
- address?: string
- }
- mailing_address: {
- zip?: string
- street?: string
- name?: string
- city?: string
- country?: string
- }
- phone: {
- number?: string
- name?: string
- }
- phone_loyalty: {
- number?: string
- name?: string
- }
- visiting_address: {
- zip?: string
- country?: string
- city?: string
- street?: string
- }
-}
-
-export enum ContactFieldGroupsEnum {
- email = "email",
- email_loyalty = "email_loyalty",
- mailing_address = "mailing_address",
- phone = "phone",
- phone_loyalty = "phone_loyalty",
- visiting_address = "visiting_address",
-}
-
-export type ContactFieldGroups = keyof typeof ContactFieldGroupsEnum
-
-export type GetContactConfigData = {
- all_contact_config: AllRequestResponse
-}
-
-export type ContactFields = {
- display_text?: string
- contact_field: string
-}
diff --git a/types/requests/contentTypeUid.ts b/types/requests/contentTypeUid.ts
index e8f358d07..5caabfa08 100644
--- a/types/requests/contentTypeUid.ts
+++ b/types/requests/contentTypeUid.ts
@@ -1,11 +1,13 @@
-export type GetContentTypeUidType = {
- all_content_page: {
- total: number
- }
- all_loyalty_page: {
- total: number
- }
- all_current_blocks_page: {
- total: number
- }
-}
+import z from "zod"
+
+export const validateContentTypeUid = z.object({
+ all_content_page: z.object({
+ total: z.number(),
+ }),
+ all_loyalty_page: z.object({
+ total: z.number(),
+ }),
+ all_current_blocks_page: z.object({
+ total: z.number(),
+ }),
+})
diff --git a/utils/contactConfig.ts b/utils/contactConfig.ts
index 3eed6da76..7a888fe0a 100644
--- a/utils/contactConfig.ts
+++ b/utils/contactConfig.ts
@@ -1,7 +1,7 @@
import {
ContactConfig,
ContactFieldGroups,
-} from "@/types/requests/contactConfig"
+} from "@/server/routers/contentstack/contactConfig/output"
export function getValueFromContactConfig(
keyString: string,
@@ -16,4 +16,5 @@ export function getValueFromContactConfig(
return fieldGroup[key]
}
+ return undefined
}
diff --git a/utils/contentType.ts b/utils/contentType.ts
index 2d3668c90..af30d5815 100644
--- a/utils/contentType.ts
+++ b/utils/contentType.ts
@@ -1,10 +1,10 @@
-import { DocumentNode } from "graphql"
+import { DocumentNode, print } from "graphql"
import { Lang } from "@/constants/languages"
import { env } from "@/env/server"
-import GetContentTypeUid from "@/lib/graphql/Query/ContentTypeUid.graphql"
+import { GetContentTypeUid } from "@/lib/graphql/Query/ContentTypeUid.graphql"
-import type { GetContentTypeUidType } from "@/types/requests/contentTypeUid"
+import { validateContentTypeUid } from "@/types/requests/contentTypeUid"
export enum PageTypeEnum {
CurrentBlocksPage = "CurrentBlocksPage",
@@ -16,7 +16,6 @@ export async function getContentTypeByPathName(
pathNameWithoutLang: string,
lang = Lang.en
) {
- const print = (await import("graphql/language/printer")).print
const result = await fetch(env.CMS_URL, {
method: "POST",
headers: {
@@ -33,7 +32,17 @@ export async function getContentTypeByPathName(
})
const pageTypeData = await result.json()
- const pageType = pageTypeData.data as GetContentTypeUidType
+
+ const validatedContentTypeUid = validateContentTypeUid.safeParse(
+ pageTypeData.data
+ )
+
+ if (!validatedContentTypeUid.success) {
+ console.error(validatedContentTypeUid.error)
+ return null
+ }
+
+ const pageType = validatedContentTypeUid.data
if (pageType.all_content_page.total) {
return PageTypeEnum.ContentPage