fix: add error feedback to PDF/CSV export mutations

Export mutations (annual report PDFs, colony/honey-batch CSV exports)
had no onError handler, so a failed download (network error, expired
session) silently did nothing with zero user feedback. Same silent-
failure class as the earlier onError sweep on entity-save mutations,
here applied to the 5 remaining export/download call sites.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
Nick SzaunigandClaude Sonnet 5 committed 2026-09-09 11:29:01 +02:00
1 parent b4caa2ad5a
commit 4ec1468eb4
5 files changed
+16 -2

No files matched your search

@@ -3,6 +3,7 @@
import Link from "next/link";
import { useParams } from "next/navigation";
import { useMutation, useQuery } from "@tanstack/react-query";
import { toast } from "sonner";
import { fetchApiary } from "@/lib/apiaries/api";
import { exportApiaryAnnualReportPdf } from "@/lib/export/api";
import { QrCodeDialog } from "@/components/qr-code-dialog";
@@ -22,6 +23,7 @@ export default function ApiaryDetailPage() {
const exportReportMutation = useMutation({
mutationFn: () => exportApiaryAnnualReportPdf(params.id, CURRENT_YEAR),
onError: () => toast.error("Jahresbericht konnte nicht exportiert werden"),
});
if (isLoading) {
@@ -2,6 +2,7 @@
import { useParams } from "next/navigation";
import { useMutation, useQuery } from "@tanstack/react-query";
import { toast } from "sonner";
import { fetchColony } from "@/lib/colonies/api";
import { exportColonyAnnualReportPdf } from "@/lib/export/api";
import { QrCodeDialog } from "@/components/qr-code-dialog";
@@ -27,6 +28,7 @@ export default function ColonyDetailPage() {
const exportReportMutation = useMutation({
mutationFn: () => exportColonyAnnualReportPdf(params.id, CURRENT_YEAR),
onError: () => toast.error("Jahresbericht konnte nicht exportiert werden"),
});
if (isLoading) {
@@ -4,6 +4,7 @@ import { useState } from "react";
import Link from "next/link";
import { Layers } from "lucide-react";
import { useMutation, useQuery } from "@tanstack/react-query";
import { toast } from "sonner";
import { fetchColonies } from "@/lib/colonies/api";
import { ColonyStatus } from "@/lib/colonies/types";
import { COLONY_CONDITION_LABELS, COLONY_STATUS_LABELS, COLONY_TYPE_LABELS } from "@/lib/colonies/labels";
@@ -35,7 +36,10 @@ export default function ColoniesPage() {
queryFn: () => fetchColonies({}),
});
const exportMutation = useMutation({ mutationFn: exportColoniesCsv });
const exportMutation = useMutation({
mutationFn: exportColoniesCsv,
onError: () => toast.error("CSV-Export konnte nicht heruntergeladen werden"),
});
const activeColonies = (colonies ?? []).filter((colony) => colony.deactivatedAt === null);
const historyColonies = (colonies ?? []).filter((colony) => colony.deactivatedAt !== null);
@@ -4,6 +4,7 @@ import Link from "next/link";
import { useParams } from "next/navigation";
import { Droplet, FlaskConical } from "lucide-react";
import { useMutation, useQuery } from "@tanstack/react-query";
import { toast } from "sonner";
import { fetchHoneyBatch, fetchHoneyBatchTraceability } from "@/lib/honey-batches/api";
import { HONEY_BATCH_STATUS_LABELS } from "@/lib/honey-batches/labels";
import { exportHoneyBatchTraceabilityPdf } from "@/lib/export/api";
@@ -32,6 +33,7 @@ export default function HoneyBatchDetailPage() {
const exportPdfMutation = useMutation({
mutationFn: () => exportHoneyBatchTraceabilityPdf(params.id),
onError: () => toast.error("PDF-Bericht konnte nicht exportiert werden"),
});
if (isLoading) {
@@ -3,6 +3,7 @@
import { useState } from "react";
import { Droplet } from "lucide-react";
import { useMutation, useQuery } from "@tanstack/react-query";
import { toast } from "sonner";
import { fetchHoneyBatches } from "@/lib/honey-batches/api";
import { HoneyBatchStatus } from "@/lib/honey-batches/types";
import { HONEY_BATCH_STATUS_LABELS } from "@/lib/honey-batches/labels";
@@ -26,7 +27,10 @@ export default function HoneyBatchesPage() {
queryFn: () => fetchHoneyBatches({}),
});
const exportMutation = useMutation({ mutationFn: exportHoneyBatchesCsv });
const exportMutation = useMutation({
mutationFn: exportHoneyBatchesCsv,
onError: () => toast.error("CSV-Export konnte nicht heruntergeladen werden"),
});
const activeBatches = (honeyBatches ?? []).filter(
(batch) => !HISTORY_STATUSES.includes(batch.status),