# Notification preferences

What reaches you, and where: one row per kind of event, one column per channel. A cell the service requires (an approval that waits on you, by email) is locked on and says why; a channel that isn't connected is locked off and says how to connect it.

- Registry name: `notification-preferences` (`@candor/notification-preferences`)
- 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-preferences

## Install

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

Run `npx candor-ui@latest init` once first (https://candor.themethodic.com/get-started.md). Without the CLI: `npx shadcn@latest add @candor/notification-preferences`.
It brings in: locale, locked, terms, utils.

## Example

```tsx
"use client"

import * as React from "react"
import { NotificationPreferences, type NoticePrefs } from "@/components/notification-preferences"

export default function Example() {
  const [prefs, setPrefs] = React.useState<NoticePrefs>({
    approval: { app: true, email: true },
    finished: { app: true },
    failed: { app: true, email: true },
  })
  return (
    <NotificationPreferences
      className="max-w-2xl"
      events={[
        { id: "approval", label: "An approval waits on me" },
        { id: "finished", label: "A run I started finishes" },
        { id: "failed", label: "A run I started fails", detail: "Including migrations that stop part way" },
      ]}
      channels={["app", "email", "slack"]}
      value={prefs}
      onChange={(e, c, on) => setPrefs((p) => ({ ...p, [e]: { ...p[e], [c]: on } }))}
      locked={{
        approval: { email: "Approvals that wait on you always email, so none expire unseen.", slack: "Connect Slack in Settings › Channels first." },
        finished: { slack: "Connect Slack in Settings › Channels first." },
        failed: { slack: "Connect Slack in Settings › Channels first." },
      }}
    />
  )
}
```

## <NotificationPreferences>

Props:

- `events: NoticeEvent[]`: The kinds of event, one row each.
- `channels: NoticeChannel[]`: The channels, one column each.
- `value: NoticePrefs`: Which cells are on, by event id and channel; a missing cell is off.
- `onChange: (eventId: string, channel: NoticeChannel, on: boolean) => void`: Called with the event id, channel and new state when a cell is toggled.
- `locked?: Record<string, Partial<Record<NoticeChannel, string | undefined>>> | undefined` (default `{}`): Reasons a cell can't be changed, by event id and channel.
- `className?: string | undefined`

## Strings (`notificationPreferences`)

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

- `label`: Notification preferences
- `tellMeWhen`: Tell me when…
- `inProduct`: In {product}
- `email`: Email
- `cell`: {event}: {channel}

## Types

### NoticeChannel

```ts
"app" | "email" | "slack"
```

### NoticeEvent

```ts
{ id: string; label: string; detail?: string | undefined }
```

### NoticePrefs

```ts
Record<string, Partial<Record<NoticeChannel, boolean>>>
```

## 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`.
