feat(SW-497): Added global alerts query and typings

This commit is contained in:
Erik Tiekstra
2024-09-30 13:11:27 +02:00
parent fb68759720
commit 78569fcb21
7 changed files with 297 additions and 89 deletions

View File

@@ -15,6 +15,7 @@ import { removeMultipleSlashes } from "@/utils/url"
import { systemSchema } from "../schemas/system"
import { Image } from "@/types/image"
import { GlobalAlertType } from "@/types/trpc/routers/contentstack/siteConfiguration"
// Help me write this zod schema based on the type ContactConfig
export const validateContactConfigSchema = z.object({
@@ -39,10 +40,12 @@ export const validateContactConfigSchema = z.object({
phone: z.object({
number: z.string().nullable(),
name: z.string().nullable(),
footnote: z.string().nullable(),
}),
phone_loyalty: z.object({
number: z.string().nullable(),
name: z.string().nullable(),
footnote: z.string().nullable(),
}),
visiting_address: z.object({
zip: z.string().nullable(),
@@ -660,3 +663,53 @@ export const headerSchema = z
},
}
})
export const globalAlertSchema = z.object({
type: z.nativeEnum(GlobalAlertType),
text: z.string(),
heading: z.string(),
phone_contact: z.object({
display_text: z.string(),
phone_number: z.string(),
footnote: z.string(),
}),
})
export const siteConfigurationSchema = z
.object({
all_site_configuration: z.object({
items: z
.array(
z.object({
sitewide_alert: z.object({
booking_widget_disabled: z.boolean(),
alertConnection: z.object({
edges: z
.array(
z.object({
node: globalAlertSchema,
})
)
.max(1),
}),
}),
})
)
.max(1),
}),
})
.transform((data) => {
if (!data.all_site_configuration.items.length) {
return {
globalAlert: null,
bookingWidgetDisabled: false,
}
}
const { sitewide_alert } = data.all_site_configuration.items[0]
return {
globalAlert: sitewide_alert.alertConnection.edges[0]?.node || null,
bookingWidgetDisabled: sitewide_alert.booking_widget_disabled,
}
})