Skip to content

feat: allow to download json for invoices and burn reports#34

Merged
wzrdx merged 2 commits intodevelopfrom
invoicing-json
Dec 5, 2025
Merged

feat: allow to download json for invoices and burn reports#34
wzrdx merged 2 commits intodevelopfrom
invoicing-json

Conversation

@aledefra
Copy link
Collaborator

@aledefra aledefra commented Dec 5, 2025

No description provided.

Copilot AI review requested due to automatic review settings December 5, 2025 10:07
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds JSON download functionality for CSP invoice drafts and burn reports, providing users with an additional data format option alongside the existing document/CSV formats.

Key Changes:

  • Added two new API functions (downloadCspDraftJSON and downloadBurnReportJSON) to support JSON downloads
  • Renamed downloadBurnReport to downloadBurnReportCSV for clarity
  • Added "Download JSON" buttons to both the invoice drafts interface and burn report interface

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/lib/api/backend.tsx Added downloadCspDraftJSON and downloadBurnReportJSON functions; renamed downloadBurnReport to downloadBurnReportCSV
src/components/account/invoicing/DraftInvoiceCard.tsx Added JSON download button with handler, updated existing button label to "Download .doc" for clarity
src/components/account/BurnReport.tsx Split download functionality into separate CSV and JSON handlers with corresponding buttons

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +48 to +81
export const downloadCspDraftJSON = async (draftId: string) => {
const res = await axiosDapp.get(`/invoice-draft/download-csp-draft-json?draftId=${draftId}`);

if (res.status !== 200) {
throw new Error(`Download failed with status ${res.status}.`);
}

if (res.data?.error) {
throw new Error(res.data.error);
}

const payload = res.data?.data ?? res.data;

let filename = 'csp_draft.json';
const contentDisposition = res.headers['content-disposition'];
if (contentDisposition) {
const filenameMatch = contentDisposition.match(/filename=([^;]+)/);
if (filenameMatch) {
filename = filenameMatch[1].replace(/['"]/g, '');
}
}

const blob = new Blob([JSON.stringify(payload, null, 2)], { type: 'application/json' });
const urlObj = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = urlObj;
a.download = filename;
document.body.appendChild(a);
a.click();
a.remove();
setTimeout(() => URL.revokeObjectURL(urlObj), 0);

return payload;
};
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's significant code duplication between downloadCspDraftJSON and downloadBurnReportJSON functions. Consider extracting the common JSON download logic into a reusable helper function that accepts the URL, default filename, and optional parameters. This would improve maintainability and reduce the risk of bugs when updating the download logic.

Copilot uses AI. Check for mistakes.
@wzrdx wzrdx merged commit 054fee2 into develop Dec 5, 2025
1 check passed
@aledefra aledefra deleted the invoicing-json branch January 9, 2026 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants