"use client"; import { useState, useCallback } from "react"; import { DataProvider, ActionProvider, VisibilityProvider, useUIStream, Renderer, } from "@json-render/react"; import { componentRegistry } from "@/components/ui"; const INITIAL_DATA = { analytics: { revenue: 125000, growth: 0.15, customers: 1234, orders: 567, salesByRegion: [ { label: "US", value: 45000 }, { label: "EU", value: 35000 }, { label: "Asia", value: 28000 }, { label: "Other", value: 17000 }, ], recentTransactions: [ { id: "TXN001", customer: "Acme Corp", amount: 1500, status: "completed", date: "2024-01-15", }, { id: "TXN002", customer: "Globex Inc", amount: 2300, status: "pending", date: "2024-01-14", }, { id: "TXN003", customer: "Initech", amount: 890, status: "completed", date: "2024-01-13", }, { id: "TXN004", customer: "Umbrella Co", amount: 4200, status: "completed", date: "2024-01-12", }, ], }, form: { dateRange: "", region: "", }, }; const ACTION_HANDLERS = { export_report: () => alert("Exporting report..."), refresh_data: () => alert("Refreshing data..."), view_details: (params: Record) => alert(`Details: ${JSON.stringify(params)}`), apply_filter: () => alert("Applying filters..."), }; function DashboardContent() { const [prompt, setPrompt] = useState(""); const { tree, isStreaming, error, send, clear } = useUIStream({ api: "/api/generate", onError: (err) => console.error("Generation error:", err), }); const handleSubmit = useCallback( async (e: React.FormEvent) => { e.preventDefault(); if (!prompt.trim()) return; await send(prompt, { data: INITIAL_DATA }); }, [prompt, send], ); const examples = [ "Revenue dashboard with metrics and chart", "Recent transactions table", "Customer count with trend", ]; const hasElements = tree && Object.keys(tree.elements).length > 0; return (

Dashboard

Generate widgets from prompts. Constrained to your catalog.

setPrompt(e.target.value)} placeholder="Describe what you want..." disabled={isStreaming} style={{ flex: 1, padding: "12px 16px", background: "var(--card)", border: "1px solid var(--border)", borderRadius: "var(--radius)", color: "var(--foreground)", fontSize: 16, outline: "none", }} /> {hasElements && ( )}
{examples.map((ex) => ( ))}
{error && (
{error.message}
)}
{!hasElements && !isStreaming ? (

Enter a prompt to generate a widget

) : tree ? ( ) : null}
{hasElements && (
View JSON
            {JSON.stringify(tree, null, 2)}
          
)}
); } export default function DashboardPage() { return ( ); }