'use client'; import { useActionState, useState } from 'react'; import { createAlertAction } from '@/lib/account/actions'; import { idle } from '@/lib/auth/state'; import { Field, FormMessage, Select, SubmitButton, TextInput } from '@/components/account/form'; import { AssetPicker } from '@/components/account/asset-picker'; import { CATEGORIES, INDICES } from '@rareindex/taxonomy'; const TYPES: Array<{ v: string; l: string; targets: Array<'asset' | 'category' | 'index'>; threshold?: 'usd' | 'pct' }> = [ { v: 'price_below', l: 'RIV falls below a value', targets: ['asset'], threshold: 'usd' }, { v: 'price_above', l: 'RIV rises above a value', targets: ['asset'], threshold: 'usd' }, { v: 'new_listing', l: 'New listing appears', targets: ['asset'] }, { v: 'new_auction', l: 'New auction lot', targets: ['asset', 'category'] }, { v: 'auction_ending', l: 'Auction ending within 24h', targets: ['asset', 'category'] }, { v: 'auction_below_riv', l: 'Auction bid (with buyer premium) ≥ 10 % below RIV', targets: ['asset'] }, { v: 'record_sale', l: 'New record (all-time high) sale', targets: ['asset', 'category'] }, { v: 'unusual_volume', l: 'Unusual sales volume (% above 90-day average)', targets: ['asset', 'category'], threshold: 'pct' }, { v: 'market_move', l: 'Index / category moves more than %', targets: ['category', 'index'], threshold: 'pct' }, { v: 'rare_item', l: 'Rare item appears (Rare Radar)', targets: ['category'] }, { v: 'population_update', l: 'Grading population changes', targets: ['asset'] }, ]; export function AlertForm() { const [state, action] = useActionState(createAlertAction, idle); const [type, setType] = useState('price_below'); const def = TYPES.find((t) => t.v === type)!; const [target, setTarget] = useState<'asset' | 'category' | 'index'>(def.targets[0]!); const effTarget = def.targets.includes(target) ? target : def.targets[0]!; return (
{def.targets.length > 1 ? (
{def.targets.map((t) => ( ))}
) : null} {effTarget === 'asset' ? ( ) : effTarget === 'category' ? ( ) : ( )} {def.threshold ? ( ) : null}
Create alert ); }