"use client"; import { useActionState, useEffect, useState, useTransition } from "react"; import { addHoldingAction, deleteHoldingAction, depositAction, recordSaleAction, savePea, saveAccount, searchStocks, setCashAction, type FormResult, } from "@/app/actions"; import type { SearchHit } from "@/lib/market"; import type { PositionView } from "@/lib/portfolio"; import { eur, pct, price, shares as fmtShares, signedEur } from "@/lib/format"; import { Delta, Empty, inputCls, primaryBtn, secondaryBtn } from "./ui"; function Result({ r }: { r: FormResult }) { if (!r) return null; return

{r.message}

; } function Field({ label, hint, children }: { label: string; hint?: string; children: React.ReactNode }) { return ( ); } const num = (s: string) => Number(s.replace(",", ".").replace(/\s/g, "")); // --------------------------------------------------------------------------- export function AccountForm(props: { openedAt: string | null; monthly: number; day: number; auto: boolean; firstTime: boolean }) { const [state, action, pending] = useActionState(saveAccount, null); return (
{props.firstTime && ( )}
); } export function CashForms({ cash }: { cash: number }) { const [dep, depAction, depPending] = useActionState(depositAction, null); const [fix, fixAction, fixPending] = useActionState(setCashAction, null); return (
); } // --------------------------------------------------------------------------- export function AddHolding() { const [open, setOpen] = useState(false); const [query, setQuery] = useState(""); const [hits, setHits] = useState([]); const [picked, setPicked] = useState(null); const [qty, setQty] = useState(""); const [px, setPx] = useState(""); const [stop, setStop] = useState("7"); const [paid, setPaid] = useState(true); const [res, setRes] = useState(null); const [pending, start] = useTransition(); useEffect(() => { if (picked || query.trim().length < 2) return; const t = setTimeout(() => searchStocks(query).then(setHits).catch(() => setHits([])), 350); return () => clearTimeout(t); }, [query, picked]); if (!open) return ( ); return (

Ajouter une action détenue chez Trade Republic

{ setPicked(null); setQuery(e.target.value); if (e.target.value.trim().length < 2) setHits([]); }} /> {!picked && hits.length > 0 && (
    {hits.map((h) => (
  • ))}
)}
setQty(e.target.value)} placeholder="ex. 0,8421" /> setPx(e.target.value)} />
setStop(e.target.value)} />
); } export function RealPositions({ positions }: { positions: PositionView[] }) { if (!positions.length) return Aucune action détenue pour l'instant.; return (
    {positions.map((p) => ( ))}
); } function RealPosition({ p }: { p: PositionView }) { const [selling, setSelling] = useState(false); const [px, setPx] = useState(p.price?.toFixed(2) ?? ""); const [res, setRes] = useState(null); const [pending, start] = useTransition(); return (
  • {p.name}

    {fmtShares(p.shares)} × {price(p.entryPrice, p.currency)} → {p.price !== null ? price(p.price, p.currency) : "?"}

    {p.stopPrice &&

    Stop {price(p.stopPrice, p.currency)}

    }

    {eur(p.valueEur)}

    {signedEur(p.pnlOpenEur)} ({pct(p.pnlOpenPct)})
    {selling ? (
    setPx(e.target.value)} />
    ) : (
    )}
  • ); } // --------------------------------------------------------------------------- export function PeaForm(props: { has: boolean; symbol: string; amount: number; day: number; start: string; calibration: number | null }) { const [state, action, pending] = useActionState(savePea, null); const [has, setHas] = useState(props.has); return (
    {has && ( <>
    )} ); }