import Link from "next/link"; import { redirect } from "next/navigation"; import { getSession } from "../../lib/auth"; import { getDb, type RikxRonde } from "../../lib/db"; import { AppHeader } from "../AppHeader"; import { createRonde } from "./actions"; import { DeleteRondeButton } from "./DeleteRondeButton"; import { RONDE_ERRORS, RondeFields } from "./RondeFields"; const euro = new Intl.NumberFormat("nl-NL", { style: "currency", currency: "EUR" }); const getal = new Intl.NumberFormat("nl-NL", { maximumFractionDigits: 2 }); export default async function RondesPage({ searchParams, }: { searchParams: Promise<{ error?: string }>; }) { const session = await getSession(); if (!session) redirect("/login"); const { error } = await searchParams; const rondes = ( getDb() .prepare( `SELECT r.*, COUNT(p.id) AS project_count FROM rikx_rondes r LEFT JOIN projects p ON p.ronde_id = r.id GROUP BY r.id ORDER BY r.created_at DESC, r.id DESC` ) .all() as (RikxRonde & { project_count: number })[] ).map((r) => ({ ...r })); return (

Rikx rondes ({rondes.length})

{rondes.length === 0 ? (

Nog geen Rikx rondes aangemaakt.

) : (
{rondes.map((r) => ( ))}
Ronde label Rikx waarde Rikx prijs Projecten
{r.label} {r.rikx_waarde === null ? "—" : getal.format(r.rikx_waarde)} {r.rikx_prijs === null ? "—" : euro.format(r.rikx_prijs)} {r.project_count} Bewerken
)}

Nieuwe Rikx Ronde

{error && RONDE_ERRORS[error] && (

{RONDE_ERRORS[error]}

)}
); }