| 1 | "use client"; |
| 2 | |
| 3 | import { useQuery } from |
| 4 | import { Bell } |
| 5 | import Link from "next/link |
| 6 | |
| 7 | import { Button } |
| 8 | import { apiClient, apiErrorMessage |
| 9 | |
| 10 | import { UNREAD_COUNT_KEY } |
| 11 | |
| 12 | export function NotificationBell() |
| 13 | const { data: |
| 14 | queryKey: UNREAD_COUNT_KEY, |
| 15 | refetchInterval: 60_000, |
| 16 | queryFn: async () |
| 17 | const { data, |
| 18 | "/api/notifications/unread-count", |
| 19 | ); |
| 20 | if (error) throw |
| 21 | return data.count |
| 22 | }, |
| 23 | }); |
| 24 | const label = |
| 25 | ? `Notifications, ${count} |
| 26 | : "Notifications, none unread"; |
| 27 | |
| 28 | return ( |
| 29 | <Button variant=" |
| 30 | <Link href=" |
| 31 | <Bell /> |
| 32 | {count > 0 |
| 33 | <span className="absolute -top-0.5 -right-0.5 flex h-4 min-w-4 items-center justify-center rounded-full bg-primary px-1 text-[10px] font-semibold text-primary-foreground tabular-nums |
| 34 | {count > 99 |
| 35 | </span> |
| 36 | )} |
| 37 | </Link> |
| 38 | </Button> |
| 39 | ); |
| 40 | } |