# Notification center

Everything that happened while you were away, behind a bell. The count is unread notices only. Opening one marks it read; "Mark all read" clears the rest. Each notice names the one thing to do next; one whose action has an `href` is a link to it, so it can open in a new tab too.

- Registry name: `notification-center` (`@candor/notification-center`)
- Tier: Pro. Installing it needs a Pro, Premium or Team licence key: the person runs `npx candor-ui key <key>` themselves; never ask for the key in chat or write it to a file.
- Docs: https://candor.themethodic.com/docs/notification-center

## Install

```bash
npx candor-ui add notification-center
```

Run `npx candor-ui@latest init` once first (https://candor.themethodic.com/get-started.md). Without the CLI: `npx shadcn@latest add @candor/notification-center`.
It brings in: locale, popover, relative-time, team, utils.
npm packages: lucide-react@^1.67.0.

## Example

```tsx
"use client"

import * as React from "react"
import { NotificationCenter } from "@/components/notification-center"
import type { Notice } from "@/lib/team"

const minutesAgo = (m: number) => new Date(Date.now() - m * 60_000).toISOString()

const initial: Notice[] = [
  { id: "n1", kind: "approval-waiting", title: "Dev agent wants to run a migration on Production", detail: "Add region to orders", at: minutesAgo(3), read: false, action: { label: "Review" } },
  { id: "n2", kind: "guardrail-stopped", title: "A run was stopped at its budget", detail: "Backfill customers.region used its 30 minutes", at: minutesAgo(41), read: false, action: { label: "See the run" } },
  { id: "n3", kind: "run-finished", title: "Index on orders.customer_id is live on Staging", at: minutesAgo(180), read: true },
  { id: "n4", kind: "invite", title: "Priya invited you to the Payments workspace", at: minutesAgo(60 * 26), read: true, action: { label: "Accept" } },
]

export default function Example() {
  const [notices, setNotices] = React.useState(initial)
  return (
    <div className="flex justify-end">
      <NotificationCenter
        notices={notices}
        onOpen={(id) => setNotices((ns) => ns.map((n) => (n.id === id ? { ...n, read: true } : n)))}
        onMarkAllRead={() => setNotices((ns) => ns.map((n) => ({ ...n, read: true })))}
      />
    </div>
  )
}
```

## <NotificationCenter>

Props:

- `notices: Notice[]`: The notices, unread first and then newest; only unread ones count on the bell.
- `onOpen?: ((id: string) => void) | undefined`: Called with a notice's id when it's opened; the app marks it read. A notice with `action.href` also follows its link.
- `onMarkAllRead?: (() => void) | undefined`: Shows "Mark all read" while there are unread notices; called when it's pressed.
- `className?: string | undefined`

## Strings (`notificationCenter`)

The fixed words, English by default. Override any of them under `notificationCenter` in `<LocaleProvider strings={{ notificationCenter: { … } }}>`; the table is exported as `notificationCenterStrings`.

- `notifications`: Notifications
- `notificationsUnread`: Notifications, {count} unread
- `markAllRead`: Mark all read
- `allCaughtUp`: You’re all caught up.
- `unread`: Unread

## Rules for using Candor UI

- Components take plain typed data. Never pass model output as HTML or render it as a link; messages are typed blocks.
- A control that can't be used says why: wrap it in `<Locked reason="…">`, don't just disable it.
- Don't show a value you don't have: leave it out (it renders as —) rather than guess. An estimate is labelled as one.
- Nothing is pre-selected in a decision a person makes, and the agent is named from your app's data, never from model output.
- Your app's words go in `LocaleProvider` (fixed strings) and `TermsProvider` (nouns); entity kinds and agent roles in `EntityKindsProvider` and `AgentRolesProvider`.
