import { useState, useEffect } from 'react' import { contentApi } from '@/api/admin' import { Megaphone, X } from 'lucide-react' const STORAGE_KEY = 'announcement_dismissed' export function AnnouncementBanner() { const [content, setContent] = useState(null) const [title, setTitle] = useState(null) const [updatedAt, setUpdatedAt] = useState(null) const [isLoading, setIsLoading] = useState(true) useEffect(() => { const loadAnnouncement = async () => { try { const data = await contentApi.getPublicContent('announcement') // Check if this announcement was already dismissed (by updated_at) const dismissedAt = localStorage.getItem(STORAGE_KEY) if (dismissedAt === data.updated_at) { setContent(null) } else { setContent(data.content) setTitle(data.title) setUpdatedAt(data.updated_at) } } catch { // No announcement or error - don't show setContent(null) } finally { setIsLoading(false) } } loadAnnouncement() }, []) const handleDismiss = () => { if (updatedAt) { // Store the updated_at to know which announcement was dismissed // When admin updates announcement, updated_at changes and banner shows again localStorage.setItem(STORAGE_KEY, updatedAt) setContent(null) } } if (isLoading || !content) { return null } return (
{/* Close button */} {/* Content */}
{title && (

{title}

)}
) }