import type { Metadata } from 'next'; import Link from 'next/link'; import { requireUser } from '@/lib/auth/session'; import { listAlerts } from '@/lib/account/queries'; import { getDisplay } from '@/lib/account/display'; import { deleteAlertAction, toggleAlertAction } from '@/lib/account/actions'; import { PageHeader, btnDanger, btnGhost } from '@/components/account/page-header'; import { Card, CardHeader, EmptyState, Table, th, td, tdNum, Badge } from '@/components/ui/primitives'; import { fmtRelative } from '@/lib/format'; import { AlertForm } from './alert-form'; export const metadata: Metadata = { title: 'Alerts', robots: { index: false } }; const ALERT_LABELS: Record = { price_below: 'RIV falls below', price_above: 'RIV rises above', new_listing: 'New listing', new_auction: 'New auction lot', auction_ending: 'Auction ending soon', auction_below_riv: 'Auction bid below RIV (all-in)', record_sale: 'New record sale', unusual_volume: 'Unusual volume', market_move: 'Market move', rare_item: 'Rare item appears', population_update: 'Population update', }; export default async function AlertsPage() { const u = await requireUser('/alerts'); const d = await getDisplay(); const rows = await listAlerts(u.id); const prefs = (u.preferences ?? {}) as { emailAlerts?: boolean }; return ( <> {prefs.emailAlerts === false ? (

E-mail delivery is off in{' '} notification settings ; alerts will only appear in your inbox.

) : null}
{rows.length === 0 ? ( ) : ( {rows.map(({ alert: a, asset }) => ( ))}
Target Condition Threshold Channel Last triggered Count
{asset ? ( {asset.title} ) : ( {a.name ?? a.targetId} )}

{a.targetType}

{ALERT_LABELS[a.alertType] ?? a.alertType} {a.threshold !== null ? (a.alertType === 'market_move' || a.alertType === 'unusual_volume' ? `${a.threshold}%` : d.money(a.threshold)) : '—'} {a.channel} {a.lastTriggeredAt ? fmtRelative(a.lastTriggeredAt) : 'never'} {a.triggerCount}
)}
); }