Files
web/packages/trpc/lib/routers/contentstack/schemas/alert.ts
Joakim Jäderberg 16cc26632e Merged in chore/refactor-trpc-booking-routes (pull request #3510)
feat(BOOK-750): refactor booking endpoints

* WIP

* wip

* wip

* parse dates in UTC

* wip

* no more errors

* Merge branch 'master' of bitbucket.org:scandic-swap/web into chore/refactor-trpc-booking-routes

* .

* cleanup

* import named z from zod

* fix(BOOK-750): updateBooking api endpoint expects dateOnly, we passed ISO date


Approved-by: Anton Gunnarsson
2026-02-02 14:28:14 +00:00

93 lines
2.3 KiB
TypeScript

import { z } from "zod"
import { AlertTypeEnum } from "@scandic-hotels/common/constants/alert"
import { linkAndTitleSchema } from "./linkConnection"
import { linkUnionSchema, transformPageLink } from "./pageLinks"
import { systemSchema } from "./system"
export const alertSchema = z.object({
type: z.nativeEnum(AlertTypeEnum),
text: z.string(),
heading: z.string(),
phone_contact: z.object({
display_text: z.string(),
phone_number: z.string().nullish(),
footnote: z.string().nullish(),
}),
has_link: z.boolean(),
link: linkAndTitleSchema,
has_sidepeek_button: z.boolean(),
sidepeek_button: z.object({
cta_text: z.string(),
}),
sidepeek_content: z.object({
heading: z.string(),
content: z.object({
json: z.any(),
embedded_itemsConnection: z.object({
edges: z.array(
z.object({
node: linkUnionSchema.transform((data) => {
const link = transformPageLink(data)
if (link) {
return link
}
return data
}),
})
),
}),
}),
}),
visible_on: z.array(z.string()).nullish().default([]),
system: systemSchema,
})
export const transformedAlertSchema =
alertSchema.transform(transformAlertSchema)
export function transformAlertSchema(data: typeof alertSchema._type) {
const {
type,
heading,
text,
phone_contact,
has_link,
link,
has_sidepeek_button,
sidepeek_button,
sidepeek_content,
visible_on,
system,
} = data
const hasLink = has_link && link.link
return {
type,
text,
heading,
visible_on,
phoneContact:
phone_contact.display_text && phone_contact.phone_number
? {
displayText: phone_contact.display_text,
phoneNumber: phone_contact.phone_number,
footnote: phone_contact.footnote,
}
: null,
hasSidepeekButton: !!has_sidepeek_button,
link: hasLink
? {
url: link.link.url,
title: link.title,
}
: null,
sidepeekButton: !hasLink && has_sidepeek_button ? sidepeek_button : null,
sidepeekContent: !hasLink && has_sidepeek_button ? sidepeek_content : null,
system,
}
}
export type Alert = z.output<typeof transformedAlertSchema>