# Notification routing

Choose where alerts go and test how routine and priority messages behave during quiet hours.

[View Notification routing on CyberSpec](https://www.cyberspec.dev/sink/notification-rules)

## Installation

Use a React 19 project with shadcn configured. Render the installed components inside the Cyber root, and import your global stylesheet in the app entry point.

```sh
bunx --bun shadcn@latest add https://www.cyberspec.dev/r/notification-rules.json
```

## Usage

```tsx
import { Cyber } from "@/components/ui/cyber"
import Recipe from "@/components/recipes/notification-rules"

export default function App() {
  return (
    <Cyber>
      <Recipe />
    </Cyber>
  )
}
```

## Source

```tsx
"use client"

import { useState } from "react"
import { Badge } from "@/components/ui/badge"
import { Checkbox, CheckboxGroup } from "@/components/ui/checkbox"
import { Select } from "@/components/ui/select"
import { Switch } from "@/components/ui/switch"
import "./recipe-layout.css"

const events = [
  { value: "handoff", label: "Handoff reminder", priority: false },
  { value: "closure", label: "Station closure", priority: true },
]

export default function NotificationRules() {
  const [destinations, setDestinations] = useState<string[]>(["Desk"])
  const [quiet, setQuiet] = useState(true)
  const [eventId, setEventId] = useState("handoff")
  const event = events.find(item => item.value === eventId)!
  const held = quiet && !event.priority
  let outcome = `Delivered to ${destinations.join(" and ")}.`
  if (!destinations.length) outcome = "No destinations selected."
  else if (held) outcome = "Held until quiet hours end."

  return (
    <div className="sink-stack">
      <CheckboxGroup label="Alert destinations" value={destinations} onValueChange={setDestinations}>
        <Checkbox value="Desk" label="Desk" />
        <Checkbox value="Wrist relay" label="Wrist relay" />
      </CheckboxGroup>
      <Switch label="Quiet hours" checked={quiet} onCheckedChange={setQuiet} />
      <Select label="Test notification" value={eventId} options={events}
        onValueChange={value => { if (value) setEventId(value) }} />
      <div className="sink-row" role="status">
        <Badge tone={event.priority ? "flag" : "mute"}>{event.priority ? "Priority" : "Routine"}</Badge>
        <span>{outcome}</span>
      </div>
    </div>
  )
}
```

## Components in this recipe

- [Checkbox](https://www.cyberspec.dev/components/sidebar/checkbox.md) — A cut box that fills and marks when checked, with an indeterminate state.
- [Switch](https://www.cyberspec.dev/components/sidebar/switch.md) — A block that slides across a cut track and lights, with its state printed beside it.
- [Select](https://www.cyberspec.dev/components/sidebar/select.md) — A labelled trigger that opens a list of options to choose from.
- [Badge](https://www.cyberspec.dev/components/sidebar/badge.md) — A small cut label in seven tones, with count and status variants.

## Resources

- [All kitchen sink recipes](https://www.cyberspec.dev/sink.md)
- [Recipe source on GitHub](https://github.com/agnelnieves/cyberspec/blob/main/registry/cyber/recipes/notification-rules.tsx)
- [Recipe layout stylesheet](https://github.com/agnelnieves/cyberspec/blob/main/registry/cyber/recipes/recipe-layout.css)
- [Shadcn registry item](https://www.cyberspec.dev/r/notification-rules.json)
