import { useMemo, useState } from 'react' import { Bell, Layers, Folder, Eye, Pencil, Check, X, Loader2 } from 'lucide-react' import { cn } from '@/lib/utils' import { Button } from '@/components/ui/button' import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover' import { usePendingSharesQuery, useAcceptShareMutation, useDeclineShareMutation, } from '../../hooks/useSharingQueries' import { toast } from '../ToastContainer' import type { PendingShare } from '../../services/api' import { Avatar } from './Avatar' /** Share invite notification bell. Sits in the LeftSidebar user * section — polls /sharing/pending every 60s and shows a red-orange * count badge when there are pending invites. Click opens a popover * listing each invite with Accept / Decline inline. */ export function NotificationBell() { const [open, setOpen] = useState(false) const { data } = usePendingSharesQuery() const acceptMutation = useAcceptShareMutation() const declineMutation = useDeclineShareMutation() const invites = useMemo(() => { if (!data) return [] as Array return [ ...data.heaps.map((h) => ({ ...h, kind: 'heap' as const })), ...data.folders.map((f) => ({ ...f, kind: 'folder' as const })), ] }, [data]) const count = invites.length const isMutating = acceptMutation.isPending || declineMutation.isPending const handleAccept = (invite: PendingShare & { kind: 'heap' | 'folder' }) => { acceptMutation.mutate( { kind: invite.kind, targetId: invite.target_id }, { onSuccess: () => { toast.success(`Joined ${invite.target_name}`) }, }, ) } const handleDecline = (invite: PendingShare & { kind: 'heap' | 'folder' }) => { declineMutation.mutate({ kind: invite.kind, targetId: invite.target_id }) } return (
Pending invites
{count > 0 && ( {count} )}
{count === 0 ? (
No pending invites.
) : (
    {invites.map((invite) => { const TypeIcon = invite.kind === 'heap' ? Layers : Folder return (
  • {invite.owner_display_name || invite.owner_username} shared {invite.target_name}
    {invite.permission === 'write' ? ( <> Can edit ) : ( <> Can view )}
  • ) })}
)}
) }