import { useEffect, useRef, useState, type ReactNode } from "react"; import { splitErrorText } from "./error-reference"; /** * One line of error text from `userErrorText`. An unexpected failure's * "Reference: ." becomes a small "Copy details" instead of printed text, * and a raw "API 409:" prefix never shows. Anything that is not a string * renders as is. */ export function ErrorText({ children }: { children?: ReactNode }) { if (typeof children !== "string") return <>{children}; const { text, reference } = splitErrorText(children); if (!reference) return <>{text}; return ( <> {text} ); } function CopyDetails({ details }: { details: string }) { const [copied, setCopied] = useState(false); const timer = useRef | null>(null); useEffect( () => () => { if (timer.current) clearTimeout(timer.current); }, [], ); return ( ); }