"use client"; import Shell from "@/components/Shell"; import { apiFetch, getCsrfFromCookie } from "@/lib/api"; import Link from "next/link"; import { useEffect, useState } from "react"; type Dashboard = { id: number; name: string; is_shared: boolean }; export default function DashboardsPage() { const [items, setItems] = useState([]); const [name, setName] = useState("Main"); const [err, setErr] = useState(null); async function load() { setErr(null); try { const data = await apiFetch("/api/dashboards"); setItems(data); } catch (e: any) { setErr(e.message || "error"); } } useEffect(() => { load(); }, []); async function create() { setErr(null); try { const csrf = getCsrfFromCookie(); await apiFetch("/api/dashboards", { method: "POST", headers: { "X-CSRF-Token": csrf || "" }, body: JSON.stringify({ name, is_shared: false }) }); await load(); } catch (e: any) { setErr(e.message || "error"); } } return (
Dashboards
Twoje dashboardy
setName(e.target.value)} />
{err &&
{err}
}
{items.map(d => (
{d.name}
id: {d.id}
))}
); }