Merged in feat/SW-3232-site-config-alerts (pull request #2671)
feat(SW-3232): update alert schema * feat(SW-3232): update alert schema Approved-by: Erik Tiekstra
This commit is contained in:
@@ -5,7 +5,7 @@ import { useIntl } from "react-intl"
|
||||
|
||||
import { BackToTopButton } from "@scandic-hotels/design-system/BackToTopButton"
|
||||
import { Typography } from "@scandic-hotels/design-system/Typography"
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alertType"
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alert"
|
||||
|
||||
import { useDestinationDataStore } from "@/stores/destination-data"
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import { useIntl } from "react-intl"
|
||||
import { useMediaQuery } from "usehooks-ts"
|
||||
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alertType"
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alert"
|
||||
|
||||
import Alert from "@/components/TempDesignSystem/Alert"
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import Body from "@scandic-hotels/design-system/Body"
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alertType"
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alert"
|
||||
|
||||
import { useDestinationDataStore } from "@/stores/destination-data"
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import { BackToTopButton } from "@scandic-hotels/design-system/BackToTopButton"
|
||||
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
|
||||
import { OldDSButton as Button } from "@scandic-hotels/design-system/OldDSButton"
|
||||
import { Typography } from "@scandic-hotels/design-system/Typography"
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alertType"
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alert"
|
||||
|
||||
import { useDestinationDataStore } from "@/stores/destination-data"
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import Footnote from "@scandic-hotels/design-system/Footnote"
|
||||
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
|
||||
import { OldDSButton as Button } from "@scandic-hotels/design-system/OldDSButton"
|
||||
import Subtitle from "@scandic-hotels/design-system/Subtitle"
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alertType"
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alert"
|
||||
|
||||
import { useDestinationDataStore } from "@/stores/destination-data"
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import { Divider } from "@scandic-hotels/design-system/Divider"
|
||||
import { IconButton } from "@scandic-hotels/design-system/IconButton"
|
||||
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
|
||||
import { Typography } from "@scandic-hotels/design-system/Typography"
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alertType"
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alert"
|
||||
|
||||
import { useHotelListingDataStore } from "@/stores/hotel-listing-data"
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import { notFound } from "next/navigation"
|
||||
|
||||
import { dt } from "@scandic-hotels/common/dt"
|
||||
import { Divider } from "@scandic-hotels/design-system/Divider"
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alertType"
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alert"
|
||||
|
||||
import { getBookingConfirmation } from "@/lib/trpc/memoizedRequests"
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import { useIntl } from "react-intl"
|
||||
import { selectRate } from "@scandic-hotels/common/constants/routes/hotelReservation"
|
||||
import useStickyPosition from "@scandic-hotels/common/hooks/useStickyPosition"
|
||||
import { BookingErrorCodeEnum } from "@scandic-hotels/trpc/enums/bookingErrorCode"
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alertType"
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alert"
|
||||
|
||||
import { useEnterDetailsStore } from "@/stores/enter-details"
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alertType"
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alert"
|
||||
|
||||
import Alert from "@/components/TempDesignSystem/Alert"
|
||||
import { getIntl } from "@/i18n"
|
||||
|
||||
@@ -7,7 +7,7 @@ import Checkbox from "@scandic-hotels/design-system/Form/Checkbox"
|
||||
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
|
||||
import Link from "@scandic-hotels/design-system/Link"
|
||||
import { Typography } from "@scandic-hotels/design-system/Typography"
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alertType"
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alert"
|
||||
|
||||
import { bookingTermsAndConditions, privacyPolicy } from "@/constants/webHrefs"
|
||||
import { useAddAncillaryStore } from "@/stores/my-stay/add-ancillary-flow"
|
||||
|
||||
@@ -5,7 +5,7 @@ import Body from "@scandic-hotels/design-system/Body"
|
||||
import { ErrorMessage } from "@scandic-hotels/design-system/Form/ErrorMessage"
|
||||
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
|
||||
import { Typography } from "@scandic-hotels/design-system/Typography"
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alertType"
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alert"
|
||||
|
||||
import { useAddAncillaryStore } from "@/stores/my-stay/add-ancillary-flow"
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alertType"
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alert"
|
||||
|
||||
import { useMyStayStore } from "@/stores/my-stay"
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alertType"
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alert"
|
||||
|
||||
import Modal from "@/components/HotelReservation/MyStay/Modal"
|
||||
import Alert from "@/components/TempDesignSystem/Alert"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alertType"
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alert"
|
||||
|
||||
import Modal from "@/components/HotelReservation/MyStay/Modal"
|
||||
import Alert from "@/components/TempDesignSystem/Alert"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alertType"
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alert"
|
||||
|
||||
import Modal from "@/components/HotelReservation/MyStay/Modal"
|
||||
import Alert from "@/components/TempDesignSystem/Alert"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alertType"
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alert"
|
||||
|
||||
import Alert from "@/components/TempDesignSystem/Alert"
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { alternativeHotels } from "@scandic-hotels/common/constants/routes/hotelReservation"
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alertType"
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alert"
|
||||
|
||||
import Alert from "@/components/TempDesignSystem/Alert"
|
||||
import { getIntl } from "@/i18n"
|
||||
|
||||
@@ -3,7 +3,7 @@ import { useIntl } from "react-intl"
|
||||
|
||||
import { alternativeHotels } from "@scandic-hotels/common/constants/routes/hotelReservation"
|
||||
import { AvailabilityEnum } from "@scandic-hotels/trpc/enums/selectHotel"
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alertType"
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alert"
|
||||
|
||||
import Alert from "@/components/TempDesignSystem/Alert"
|
||||
import { useSelectRateContext } from "@/contexts/SelectRate/SelectRateContext"
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import { TRPCClientError } from "@trpc/client"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alertType"
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alert"
|
||||
|
||||
import Alert from "@/components/TempDesignSystem/Alert"
|
||||
import { useSelectRateContext } from "@/contexts/SelectRate/SelectRateContext"
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import { useRouter, useSearchParams } from "next/navigation"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alertType"
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alert"
|
||||
|
||||
import { DTMC_SUCCESS_BANNER_KEY } from "@/constants/dtmc"
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import useStickyPosition from "@scandic-hotels/common/hooks/useStickyPosition"
|
||||
import { StickyElementNameEnum } from "@scandic-hotels/common/stores/sticky-position"
|
||||
import { debounce } from "@scandic-hotels/common/utils/debounce"
|
||||
import { trpc } from "@scandic-hotels/trpc/client"
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alertType"
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alert"
|
||||
|
||||
import Alert from "@/components/TempDesignSystem/Alert"
|
||||
import useLang from "@/hooks/useLang"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { AlertTypeEnum } from "@scandic-hotels/trpc/types/alertType"
|
||||
import type { AlertTypeEnum } from "@scandic-hotels/trpc/types/alert"
|
||||
import type { SidepeekContent } from "@scandic-hotels/trpc/types/siteConfig"
|
||||
import type { VariantProps } from "class-variance-authority"
|
||||
import type { AriaRole } from "react"
|
||||
|
||||
@@ -2,7 +2,7 @@ import {
|
||||
MaterialIcon,
|
||||
type MaterialIconSetIconProps,
|
||||
} from "@scandic-hotels/design-system/Icons/MaterialIcon"
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alertType"
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alert"
|
||||
|
||||
import type { JSX } from "react"
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { cva } from "class-variance-authority"
|
||||
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alertType"
|
||||
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alert"
|
||||
|
||||
import styles from "./alert.module.css"
|
||||
|
||||
|
||||
@@ -81,6 +81,7 @@ fragment Alert on Alert {
|
||||
json
|
||||
}
|
||||
}
|
||||
visible_on
|
||||
}
|
||||
|
||||
fragment AlertRef on Alert {
|
||||
@@ -130,4 +131,5 @@ fragment AlertRef on Alert {
|
||||
system {
|
||||
...System
|
||||
}
|
||||
visible_on
|
||||
}
|
||||
|
||||
@@ -6,11 +6,13 @@ query GetSiteConfig($locale: String!) {
|
||||
all_site_config(limit: 1, locale: $locale) {
|
||||
items {
|
||||
sitewide_alert {
|
||||
booking_widget_disabled
|
||||
alertConnection {
|
||||
edges {
|
||||
node {
|
||||
...Alert
|
||||
alerts {
|
||||
booking_widget_disabled
|
||||
alertConnection {
|
||||
edges {
|
||||
node {
|
||||
...Alert
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,10 +25,12 @@ query GetSiteConfigRef($locale: String!) {
|
||||
all_site_config(limit: 1, locale: $locale) {
|
||||
items {
|
||||
sitewide_alert {
|
||||
alertConnection {
|
||||
edges {
|
||||
node {
|
||||
...AlertRef
|
||||
alerts {
|
||||
alertConnection {
|
||||
edges {
|
||||
node {
|
||||
...AlertRef
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Lang } from "@scandic-hotels/common/constants/language"
|
||||
import { logger } from "@scandic-hotels/common/logger"
|
||||
import { removeMultipleSlashes } from "@scandic-hotels/common/utils/url"
|
||||
|
||||
import { AlertTypeEnum } from "../../../types/alertType"
|
||||
import { AlertTypeEnum, AlertVisibleOnEnum } from "../../../types/alert"
|
||||
import { discriminatedUnion } from "../../../utils/discriminatedUnion"
|
||||
import {
|
||||
cardBlockRefsSchema,
|
||||
@@ -744,6 +744,7 @@ export const alertSchema = z
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
visible_on: z.array(z.string()).nullable().default([]),
|
||||
})
|
||||
.transform(
|
||||
({
|
||||
@@ -756,12 +757,14 @@ export const alertSchema = z
|
||||
has_sidepeek_button,
|
||||
sidepeek_button,
|
||||
sidepeek_content,
|
||||
visible_on,
|
||||
}) => {
|
||||
const hasLink = has_link && link.link
|
||||
return {
|
||||
type,
|
||||
text,
|
||||
heading,
|
||||
visible_on,
|
||||
phoneContact:
|
||||
phone_contact.display_text && phone_contact.phone_number
|
||||
? {
|
||||
@@ -792,16 +795,20 @@ export const siteConfigSchema = z
|
||||
.array(
|
||||
z.object({
|
||||
sitewide_alert: z.object({
|
||||
booking_widget_disabled: z.boolean(),
|
||||
alertConnection: z.object({
|
||||
edges: z
|
||||
.array(
|
||||
z.object({
|
||||
node: alertSchema,
|
||||
})
|
||||
)
|
||||
.max(1),
|
||||
}),
|
||||
alerts: z
|
||||
.array(
|
||||
z.object({
|
||||
booking_widget_disabled: z.boolean(),
|
||||
alertConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: alertSchema,
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
)
|
||||
.nullable(),
|
||||
}),
|
||||
})
|
||||
)
|
||||
@@ -818,9 +825,15 @@ export const siteConfigSchema = z
|
||||
|
||||
const { sitewide_alert } = data.all_site_config.items[0]
|
||||
|
||||
const sitewideAlertWeb = sitewide_alert.alerts?.find((alert) =>
|
||||
alert.alertConnection.edges[0]?.node.visible_on?.includes(
|
||||
AlertVisibleOnEnum.WEB
|
||||
)
|
||||
)
|
||||
|
||||
return {
|
||||
sitewideAlert: sitewide_alert.alertConnection.edges[0]?.node || null,
|
||||
bookingWidgetDisabled: sitewide_alert.booking_widget_disabled,
|
||||
sitewideAlert: sitewideAlertWeb?.alertConnection.edges[0]?.node || null,
|
||||
bookingWidgetDisabled: sitewideAlertWeb?.booking_widget_disabled,
|
||||
}
|
||||
})
|
||||
|
||||
@@ -846,15 +859,29 @@ const alertConnectionRefSchema = z.object({
|
||||
}),
|
||||
})
|
||||
),
|
||||
visible_on: z.array(z.string()).nullable().default([]),
|
||||
})
|
||||
|
||||
export const siteConfigRefSchema = z.object({
|
||||
all_site_config: z.object({
|
||||
items: z.array(
|
||||
z.object({
|
||||
sitewide_alert: z.object({
|
||||
alertConnection: alertConnectionRefSchema,
|
||||
}),
|
||||
sitewide_alert: z
|
||||
.object({
|
||||
alerts: z
|
||||
.array(
|
||||
z.object({
|
||||
alertConnection: alertConnectionRefSchema,
|
||||
})
|
||||
)
|
||||
.nullable(),
|
||||
})
|
||||
.transform((data) => {
|
||||
const sitewideAlertWeb = data.alerts?.find((alert) =>
|
||||
alert.alertConnection.visible_on?.includes(AlertVisibleOnEnum.WEB)
|
||||
)
|
||||
return { alert: sitewideAlertWeb || null }
|
||||
}),
|
||||
system: systemSchema,
|
||||
})
|
||||
),
|
||||
|
||||
@@ -82,9 +82,9 @@ export function getSiteConfigConnections(refs: GetSiteConfigRefData) {
|
||||
const siteConfigData = refs.all_site_config.items[0]
|
||||
const connections: System["system"][] = []
|
||||
|
||||
if (!siteConfigData) return connections
|
||||
if (!siteConfigData.sitewide_alert.alert) return connections
|
||||
|
||||
const alertConnection = siteConfigData.sitewide_alert.alertConnection
|
||||
const alertConnection = siteConfigData.sitewide_alert.alert.alertConnection
|
||||
|
||||
alertConnection.edges.forEach(({ node }) => {
|
||||
connections.push(node.system)
|
||||
|
||||
@@ -3,7 +3,7 @@ import { z } from "zod"
|
||||
import { dt } from "@scandic-hotels/common/dt"
|
||||
import { nullableStringValidator } from "@scandic-hotels/common/utils/zod/stringValidator"
|
||||
|
||||
import { AlertTypeEnum } from "../../../../types/alertType"
|
||||
import { AlertTypeEnum } from "../../../../types/alert"
|
||||
|
||||
const specialAlertSchema = z.object({
|
||||
description: nullableStringValidator,
|
||||
|
||||
@@ -4,3 +4,8 @@ export enum AlertTypeEnum {
|
||||
Alarm = "alarm",
|
||||
Success = "success",
|
||||
}
|
||||
|
||||
export const AlertVisibleOnEnum = {
|
||||
WEB: "WEB",
|
||||
APP: "APP",
|
||||
} as const
|
||||
Reference in New Issue
Block a user