{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "notifications-02",
  "description": "Notifications that ask for a decision, such as a request to join or a refund, with a tab for the ones still waiting.",
  "registryDependencies": [
    "card",
    "button",
    "tabs",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/tag.json",
    "https://www.dashboardblocks.com/r/radix/notifications.json",
    "https://www.dashboardblocks.com/r/radix/status-label.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/notifications/notifications-02.tsx",
      "content": "'use client'\n\nimport {\n  BlockReady,\n  BlockStateProvider,\n  BlockStateRows,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  type AppNotification,\n  NotificationBell,\n  NotificationItem,\n  NotificationList,\n  NotificationsHeader,\n} from '@/registry/components/dashboardblocks/notifications'\nimport { StatusLabel } from '@/registry/components/dashboardblocks/status-label'\nimport { Tag } from '@/registry/components/dashboardblocks/tag'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport { formatNumber } from '@/registry/lib/dashboardblocks/format'\nimport { startTransition, useState } from 'react'\n\nimport { Button } from '@/components/ui/button'\nimport { Card, CardContent } from '@/components/ui/card'\nimport { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'\n\ntype Decision = 'approved' | 'declined'\n\ninterface ActionableNotification extends AppNotification {\n  request?: { approve: string; decline: string }\n}\n\ninterface Notifications2Props extends BlockStateProps {\n  /** Leave out, or pass none, to show the empty state. */\n  notifications?: ActionableNotification[]\n  /** Pass a fixed date, so times render the same on the server and in the browser. */\n  now: Date\n  onDecide?: (id: string, decision: Decision) => Promise<void>\n  title: string\n}\n\nconst exampleNow = new Date(Date.UTC(2026, 8, 26, 12))\nconst minutesAgo = (minutes: number) => new Date(exampleNow.getTime() - minutes * 60_000)\n\nconst exampleProps: Notifications2Props = {\n  notifications: [\n    {\n      at: minutesAgo(8),\n      icon: (\n        <IconPlaceholder\n          lucide='UserPlusIcon'\n          tabler='IconUserPlus'\n          hugeicons='UserAdd01Icon'\n          phosphor='UserPlusIcon'\n          remixicon='RiUserAddLine'\n        />\n      ),\n      id: '1',\n      read: false,\n      request: { approve: 'Approve', decline: 'Decline' },\n      title: (\n        <>\n          <span className='font-medium'>Priya Nair</span> asked to join Acme Store\n        </>\n      ),\n      tone: 'accent',\n    },\n    {\n      at: minutesAgo(55),\n      body: 'Item arrived damaged on order #0931.',\n      icon: (\n        <IconPlaceholder\n          lucide='CreditCardIcon'\n          tabler='IconCreditCard'\n          hugeicons='CreditCardIcon'\n          phosphor='CreditCardIcon'\n          remixicon='RiBankCardLine'\n        />\n      ),\n      id: '2',\n      read: false,\n      request: { approve: 'Refund', decline: 'Reject' },\n      title: 'Refund of $94.50 requested',\n      tone: 'warning',\n    },\n    {\n      at: minutesAgo(240),\n      body: '“Looks good, shipping it tomorrow.”',\n      icon: (\n        <IconPlaceholder\n          lucide='MessageSquareIcon'\n          tabler='IconMessage'\n          hugeicons='MessageIcon'\n          phosphor='ChatCircleIcon'\n          remixicon='RiChat1Line'\n        />\n      ),\n      id: '3',\n      read: true,\n      title: (\n        <>\n          <span className='font-medium'>Lena Fischer</span> replied to your comment\n        </>\n      ),\n      tone: 'info',\n    },\n  ],\n  now: exampleNow,\n  title: 'Dashboard',\n}\n\nasync function saveDecision() {\n  await new Promise((resolve) => setTimeout(resolve, 500))\n}\n\nconst Notifications2 = (props: Notifications2Props) => {\n  const {\n    notifications: loaded = [],\n    now,\n    onDecide = saveDecision,\n    errorMessage,\n    status,\n    title,\n  } = props\n  const [readIds, setReadIds] = useState<ReadonlySet<string>>(() => new Set())\n  const [decisions, setDecisions] = useState<Record<string, Decision>>({})\n  const [pending, setPending] = useState<string | null>(null)\n  const [tab, setTab] = useState<'all' | 'requests'>('all')\n  const state = getBlockState(status, loaded)\n  const notifications = loaded.map((notification) =>\n    readIds.has(notification.id) ? { ...notification, read: true } : notification,\n  )\n  const unread = state\n    ? 0\n    : notifications.filter((notification) => !notification.read).length\n  const requests = state\n    ? []\n    : notifications.filter(\n        (notification) => notification.request && !decisions[notification.id],\n      )\n\n  function markRead(id: string) {\n    setReadIds((current) => new Set(current).add(id))\n  }\n\n  async function decide(id: string, decision: Decision) {\n    setPending(id)\n    try {\n      await onDecide(id, decision)\n      startTransition(() => {\n        setDecisions((current) => ({ ...current, [id]: decision }))\n        markRead(id)\n      })\n    } finally {\n      startTransition(() => setPending(null))\n    }\n  }\n\n  function renderList(items: ActionableNotification[], empty: string) {\n    if (state) {\n      return (\n        <div className='px-4'>\n          <BlockStateRows rows={3} />\n        </div>\n      )\n    }\n    if (items.length === 0) {\n      return (\n        <p className='text-muted-foreground px-4 py-10 text-center text-sm'>{empty}</p>\n      )\n    }\n    return (\n      <NotificationList className='max-h-96 overflow-y-auto pe-2 [scrollbar-width:thin]'>\n        {items.map((notification) => {\n          const decision = decisions[notification.id]\n          const { request } = notification\n          return (\n            <NotificationItem\n              key={notification.id}\n              notification={notification}\n              now={now}\n              onOpen={() => markRead(notification.id)}\n              actions={\n                request &&\n                (decision ? (\n                  <p role='status'>\n                    <StatusLabel tone={decision === 'approved' ? 'good' : 'neutral'}>\n                      {decision === 'approved' ? 'Approved' : 'Declined'}\n                    </StatusLabel>\n                  </p>\n                ) : (\n                  <>\n                    <Button\n                      size='sm'\n                      variant='outline'\n                      disabled={pending === notification.id}\n                      onClick={() => void decide(notification.id, 'approved')}\n                    >\n                      {request.approve}\n                    </Button>\n                    <Button\n                      size='sm'\n                      variant='ghost'\n                      disabled={pending === notification.id}\n                      onClick={() => void decide(notification.id, 'declined')}\n                    >\n                      {request.decline}\n                    </Button>\n                  </>\n                ))\n              }\n            />\n          )\n        })}\n      </NotificationList>\n    )\n  }\n\n  return (\n    <BlockStateProvider errorMessage={errorMessage} state={state}>\n      <Card>\n        <CardContent>\n          <section className='@container flex items-center justify-between gap-3'>\n            <h2 className='font-semibold tracking-tight'>{title}</h2>\n            <NotificationBell unreadCount={unread}>\n              <NotificationsHeader\n                description={\n                  <BlockReady>\n                    {requests.length > 0\n                      ? `${requests.length} ${requests.length === 1 ? 'request is' : 'requests are'} waiting on you.`\n                      : 'No requests waiting on you.'}\n                  </BlockReady>\n                }\n              />\n              <Tabs\n                value={tab}\n                onValueChange={(value) => setTab(value as 'all' | 'requests')}\n              >\n                <TabsList className='mx-4 mb-2'>\n                  <TabsTrigger value='all'>All</TabsTrigger>\n                  <TabsTrigger value='requests'>\n                    Requests\n                    {requests.length > 0 && <Tag>{formatNumber(requests.length)}</Tag>}\n                  </TabsTrigger>\n                </TabsList>\n                <TabsContent value='all' className='border-t'>\n                  {renderList(notifications, 'You’re all caught up.')}\n                </TabsContent>\n                <TabsContent value='requests' className='border-t'>\n                  {renderList(requests, 'No requests waiting for you.')}\n                </TabsContent>\n              </Tabs>\n            </NotificationBell>\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport {\n  Notifications2,\n  exampleProps as notifications2ExampleProps,\n  type Notifications2Props,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/notifications/notifications-02.tsx"
    }
  ],
  "meta": {
    "shows": "Notifications that ask for a decision, such as a request to join or a refund, with a tab for the ones still waiting.",
    "size": "half",
    "usedWith": [
      "notifications-03",
      "activity-feed-01"
    ],
    "component": "Notifications2",
    "props": "{ notifications?: { request?: { approve: string; decline: string }; at: Date; body?: string; href?: string; icon: ReactNode; id: string; read: boolean; title: ReactNode; tone?: \"success\" | \"warning\" | \"danger\" | \"info\" | \"neutral\" | \"accent\" }[]; now: Date; onDecide?: (id: string, decision: \"approved\" | \"declined\") => Promise<void>; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
