"use client"; import { Bell } from "lucide-react"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { useEffect, useRef, useState } from "react"; import { completeEmployeeNote } from "@/actions/employees"; import { useToast } from "@/components/ui/Toast"; import { NOTE_CATEGORY_STYLES } from "@/lib/colors"; import { fmtDate } from "@/lib/format"; import type { OpenNote } from "@/lib/notes"; // Click-outside mechanics borrowed from CountryPicker (useRef + mousedown // listener) — without its draft-text reset, which has no equivalent here. export function NotesBell({ notes }: { notes: OpenNote[] }) { const { showToast } = useToast(); const router = useRouter(); const [open, setOpen] = useState(false); const [completingId, setCompletingId] = useState(null); const containerRef = useRef(null); useEffect(() => { function onClickOutside(e: MouseEvent) { if (containerRef.current && !containerRef.current.contains(e.target as Node)) { setOpen(false); } } document.addEventListener("mousedown", onClickOutside); return () => document.removeEventListener("mousedown", onClickOutside); }, []); async function handleComplete(note: OpenNote) { setCompletingId(note.id); const result = await completeEmployeeNote({ note_id: note.id, employee_id: note.employee_id }); setCompletingId(null); if (result.success) { showToast("Notiz erledigt."); router.refresh(); } else { showToast(result.error ?? "Fehler beim Speichern.", "error"); } } return (
{open && (
Meine Notizen ({notes.length})
{notes.length === 0 ? (

Keine offenen Notizen.

) : (
    {notes.map((n) => (
  • {n.category} {n.employeeName} {fmtDate(n.created_at)}

    {n.note_text}

    {n.due_date &&

    🔔 fällig {fmtDate(n.due_date)}

    }
  • ))}
)}
)}
); }