import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import InputError from '@/components/InputError'; import { useForm } from '@inertiajs/react'; import { LoaderCircle } from 'lucide-react'; import { FormEventHandler, useState, useEffect } from 'react'; import ComponentTitle from '@/components/ui/ComponentTitle'; interface AssetFormData { symbol: string; full_name: string; [key: string]: string; } interface AssetSetupFormProps { onSuccess?: () => void; onCancel?: () => void; } export default function AssetSetupForm({ onSuccess, onCancel }: AssetSetupFormProps) { const { data, setData, post, processing, errors } = useForm({ symbol: '', full_name: '', }); // Load existing asset data on mount useEffect(() => { const fetchCurrentAsset = async () => { try { const response = await fetch('/assets/current'); if (response.ok) { const assetData = await response.json(); if (assetData.asset) { setData({ symbol: assetData.asset.symbol || '', full_name: assetData.asset.full_name || '', }); } } } catch (error) { console.error('Failed to fetch current asset:', error); } }; fetchCurrentAsset(); }, []); const [suggestions] = useState([ { symbol: 'VWCE', full_name: 'Vanguard FTSE All-World UCITS ETF' }, { symbol: 'VTI', full_name: 'Vanguard Total Stock Market ETF' }, { symbol: 'SPY', full_name: 'SPDR S&P 500 ETF Trust' }, { symbol: 'QQQ', full_name: 'Invesco QQQ Trust' }, { symbol: 'IWDA', full_name: 'iShares Core MSCI World UCITS ETF' }, ]); const submit: FormEventHandler = (e) => { e.preventDefault(); post(route('assets.set-current'), { onSuccess: () => { if (onSuccess) onSuccess(); }, }); }; const handleSuggestionClick = (suggestion: { symbol: string; full_name: string }) => { setData({ symbol: suggestion.symbol, full_name: suggestion.full_name, }); }; return (
SET ASSET

[SYSTEM] Specify the asset you want to track

{/* Quick suggestions */}
{suggestions.map((suggestion) => ( ))}
setData('symbol', e.target.value.toUpperCase())} className="bg-black border-red-500 text-red-400 focus:border-red-300 font-mono text-sm rounded-none border-2 focus:ring-0 focus:outline-none focus:shadow-[0_0_10px_rgba(239,68,68,0.5)] placeholder:text-red-400/40 transition-all" />

[REQUIRED] ticker symbol (e.g. VWCE, VTI, SPY)

setData('full_name', e.target.value)} className="bg-black border-red-500 text-red-400 focus:border-red-300 font-mono text-sm rounded-none border-2 focus:ring-0 focus:outline-none focus:shadow-[0_0_10px_rgba(239,68,68,0.5)] placeholder:text-red-400/40 transition-all" />

[OPTIONAL] human-readable asset name

{onCancel && ( )}
); }