From 7a0d12e2e03bba6341e2b054eeebceff9d3ab4ee Mon Sep 17 00:00:00 2001 From: MeeraSRaj Date: Tue, 23 Jun 2026 22:59:07 +0530 Subject: [PATCH 1/2] fix: add error handling for metric exports --- src/components/ExportButton.tsx | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/components/ExportButton.tsx b/src/components/ExportButton.tsx index f4698a159..286ededfc 100644 --- a/src/components/ExportButton.tsx +++ b/src/components/ExportButton.tsx @@ -4,6 +4,7 @@ import { useMemo, useState } from "react"; import { useSession } from "next-auth/react"; import jsPDF from "jspdf"; import autoTable from "jspdf-autotable"; +import { toast } from "sonner"; interface PRData { open: number; @@ -297,9 +298,9 @@ export default function ExportButton() { .sort(([a], [b]) => a.localeCompare(b)) .map(([day, commits]) => ({ day, commits: commits as number })); - return { - prData, - contribData, + return { + prData, + contribData, goalsData: goalsData?.goals as Goal[], dbExportData }; @@ -404,7 +405,14 @@ export default function ExportButton() { ]); downloadFile(csv, "dashboard-metrics.csv", "text/csv"); - } finally { + toast.success("CSV exported successfully."); + } catch (error) { + console.error("CSV export failed:", error); + + toast.error( + "Failed to export CSV. Please try again." + ); + } finally { setIsExportingCSV(false); } }; @@ -658,7 +666,15 @@ export default function ExportButton() { addFooter(doc, generatedAt); doc.save(`devtrack-export-${reportName || "metrics"}-${new Date().toISOString().slice(0, 10)}.pdf`); - } finally { + toast.success("PDF exported successfully."); + } catch (error) { + console.error("PDF export failed:", error); + + toast.error( + "Failed to export PDF. Please try again." + ); + } + finally { setIsExportingPDF(false); } }; @@ -668,7 +684,7 @@ export default function ExportButton() { try { const { prData, goalsData, contribData, dbExportData } = await fetchData(); const generatedAt = formatGeneratedTimestamp(); - + const jsonData = { generatedAt, githubUser: reportName || "unknown", From a74e5e621e8d5823983f3ef5658f9f4635c66356 Mon Sep 17 00:00:00 2001 From: MeeraSRaj Date: Sat, 27 Jun 2026 16:45:55 +0530 Subject: [PATCH 2/2] style: fix export error handling indentation --- src/components/ExportButton.tsx | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/components/ExportButton.tsx b/src/components/ExportButton.tsx index 286ededfc..014875eec 100644 --- a/src/components/ExportButton.tsx +++ b/src/components/ExportButton.tsx @@ -407,12 +407,12 @@ export default function ExportButton() { downloadFile(csv, "dashboard-metrics.csv", "text/csv"); toast.success("CSV exported successfully."); } catch (error) { - console.error("CSV export failed:", error); + console.error("CSV export failed:", error); - toast.error( - "Failed to export CSV. Please try again." - ); - } finally { + toast.error( + "Failed to export CSV. Please try again." + ); + } finally { setIsExportingCSV(false); } }; @@ -668,12 +668,12 @@ export default function ExportButton() { doc.save(`devtrack-export-${reportName || "metrics"}-${new Date().toISOString().slice(0, 10)}.pdf`); toast.success("PDF exported successfully."); } catch (error) { - console.error("PDF export failed:", error); + console.error("PDF export failed:", error); - toast.error( - "Failed to export PDF. Please try again." - ); - } + toast.error( + "Failed to export PDF. Please try again." + ); + } finally { setIsExportingPDF(false); }