"use client"; import { useState, useTransition } from "react"; import { exportiereCsv } from "@/app/zeiterfassung/actions"; import { Button } from "@/components/ui/Button"; import { Alert } from "@/components/ui/Alert"; export function CsvExportButton({ von, bis, fahrerId }: { von: string; bis: string; fahrerId?: string }) { const [fehler, setFehler] = useState(null); const [isPending, startTransition] = useTransition(); function handleClick() { startTransition(async () => { const ergebnis = await exportiereCsv({ von, bis }, fahrerId); if (!ergebnis.success) { setFehler(ergebnis.error); return; } const blob = new Blob([ergebnis.csv], { type: "text/csv;charset=utf-8;" }); const url = URL.createObjectURL(blob); const link = document.createElement("a"); link.href = url; link.download = `zeiterfassung_${von.slice(0, 10)}_${bis.slice(0, 10)}.csv`; link.click(); URL.revokeObjectURL(url); }); } return (
{fehler && (
{fehler}
)}
); }