* feat(BOOK-755): Added alert block on Collection pages * feat(BOOK-755): Added alert block on Content pages * feat(BOOK-755): Added alert functionality for RTE Approved-by: Bianca Widstam
39 lines
991 B
TypeScript
39 lines
991 B
TypeScript
import * as Sentry from "@sentry/nextjs"
|
|
import { z } from "zod"
|
|
|
|
import { logger } from "@scandic-hotels/common/logger"
|
|
|
|
import { getValueFromContactConfig } from "../../../utils/contactConfig"
|
|
|
|
import type { Alert } from "../schemas/alert"
|
|
import type { ContactConfig } from "./output"
|
|
|
|
export function getAlertPhoneContactData(
|
|
alert: Alert,
|
|
contactConfig: ContactConfig
|
|
) {
|
|
if (alert.phoneContact) {
|
|
const { displayText, phoneNumber, footnote } = alert.phoneContact
|
|
|
|
return {
|
|
displayText,
|
|
phoneNumber: getValueFromContactConfig(phoneNumber, contactConfig),
|
|
footnote: footnote
|
|
? getValueFromContactConfig(footnote, contactConfig)
|
|
: null,
|
|
}
|
|
}
|
|
return null
|
|
}
|
|
|
|
export const safeUnion = <T extends z.ZodTypeAny>(schema: T) =>
|
|
z.preprocess((val) => {
|
|
try {
|
|
return schema.parse(val)
|
|
} catch (err) {
|
|
Sentry.captureException(err)
|
|
logger.warn("Invalid node in safeUnion", err)
|
|
return null
|
|
}
|
|
}, schema)
|