feat(SW-650): added sitewide alert to use sticky position hook

This commit is contained in:
Erik Tiekstra
2024-10-24 10:23:19 +02:00
parent 63dbbac014
commit fbdfeafcb5
7 changed files with 87 additions and 23 deletions

View File

@@ -0,0 +1,41 @@
"use client"
import { useRef } from "react"
import { StickyElementNameEnum } from "@/stores/sticky-position"
import Alert from "@/components/TempDesignSystem/Alert"
import useStickyPosition from "@/hooks/useStickyPosition"
import { SitewideAlertProps } from "./sitewideAlert"
import styles from "./sitewideAlert.module.css"
import { AlertTypeEnum } from "@/types/enums/alert"
export default function SiteWideAlertClient({ alert }: SitewideAlertProps) {
const alertRef = useRef(null)
useStickyPosition({
ref: alertRef,
name: StickyElementNameEnum.SITEWIDE_ALERT,
})
const isAlarm = alert.type === AlertTypeEnum.Alarm
return (
<div
ref={isAlarm ? alertRef : null}
className={`${styles.sitewideAlert} ${isAlarm ? styles.alarm : ""}`}
>
<Alert
variant="banner"
type={alert.type}
link={alert.link}
phoneContact={alert.phoneContact}
sidepeekCtaText={alert.sidepeekButton?.cta_text}
sidepeekContent={alert.sidepeekContent}
heading={alert.heading}
text={alert.text}
/>
</div>
)
}

View File

@@ -1,8 +1,6 @@
import { getSiteConfig } from "@/lib/trpc/memoizedRequests"
import Alert from "../TempDesignSystem/Alert"
import styles from "./sitewideAlert.module.css"
import SiteWideAlertClient from "./Client"
export function preload() {
void getSiteConfig()
@@ -15,19 +13,5 @@ export default async function SitewideAlert() {
return null
}
const { sitewideAlert } = siteConfig
return (
<div className={`${styles.sitewideAlert} ${styles[sitewideAlert.type]}`}>
<Alert
variant="banner"
type={sitewideAlert.type}
link={sitewideAlert.link}
phoneContact={sitewideAlert.phoneContact}
sidepeekCtaText={sitewideAlert.sidepeekButton?.cta_text}
sidepeekContent={sitewideAlert.sidepeekContent}
heading={sitewideAlert.heading}
text={sitewideAlert.text}
/>
</div>
)
return <SiteWideAlertClient alert={siteConfig.sitewideAlert} />
}

View File

@@ -0,0 +1,5 @@
import type { Alert } from "@/types/trpc/routers/contentstack/siteConfig"
export interface SitewideAlertProps {
alert: Alert
}