forked from nuotsu/sanitypress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnnouncement.tsx
40 lines (34 loc) · 972 Bytes
/
Announcement.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { PortableText, groq } from 'next-sanity'
import CTA from '@/ui/CTA'
import { fetchSanity } from '@/lib/sanity/fetch'
export default async function Announcement() {
const announcements = await fetchSanity<Sanity.Announcement[]>(
groq`*[_type == 'site'][0].announcements[]->{
...,
cta{
...,
internal->{ _type, title, metadata }
}
}`,
{
tags: ['announcements'],
revalidate: 30,
},
)
if (!announcements) return null
const active = announcements.find(({ start, end }) => {
return (
(!start || new Date(start) < new Date()) &&
(!end || new Date(end) > new Date())
)
})
if (!active) return null
return (
<aside className="flex items-center justify-center gap-x-4 bg-ink p-2 text-center text-canvas max-md:text-sm md:gap-x-6">
<div className="anim-fade-to-r text-balance">
<PortableText value={active.content} />
</div>
<CTA className="link anim-fade-to-l shrink-0" link={active.cta} />
</aside>
)
}