-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
19fb361
commit 3598462
Showing
14 changed files
with
254 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...-v2/src/common/utils/convert-csv-to-pdf-base64-string/convert-csv-to-pdf-base64-string.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { jsPDF } from 'jspdf'; | ||
import 'jspdf-autotable'; | ||
import Papa from 'papaparse'; | ||
|
||
interface jsPDFWithPlugin extends jsPDF { | ||
autoTable: any; | ||
} | ||
|
||
export const convertCsvToPdfBase64String = (csvBase64: string) => { | ||
// Extract base64 data from data URI | ||
const base64Data = csvBase64.split(',')[1] || csvBase64; | ||
|
||
// Decode base64 to string | ||
const csvString = atob(base64Data); | ||
|
||
// Parse CSV string to array using PapaParse | ||
const { data } = Papa.parse(csvString, { | ||
header: true, | ||
skipEmptyLines: true, | ||
}); | ||
|
||
// Create new PDF document | ||
const doc = new jsPDF() as jsPDFWithPlugin; | ||
|
||
// Add table to PDF using autoTable | ||
doc.autoTable({ | ||
head: [Object.keys(data[0] as object)], // Column headers | ||
body: data.map(row => Object.values(row as object)), // Row data | ||
startY: 10, | ||
margin: { top: 10 }, | ||
styles: { fontSize: 8 }, | ||
headStyles: { fillColor: [66, 66, 66] }, | ||
}); | ||
|
||
return doc.output('datauristring'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const isCsv = <T extends { fileType: string }>(document: T) => | ||
document?.fileType === 'text/csv' || document?.fileType === 'application/csv'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
apps/backoffice-v2/src/pages/Entity/components/Case/hooks/useDocuments/helpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { isCsv } from '@/common/utils/is-csv/is-csv'; | ||
import { convertCsvToPdfBase64String } from '../../../../../../common/utils/convert-csv-to-pdf-base64-string/convert-csv-to-pdf-base64-string'; | ||
import { IDocumentsProps } from '../../interfaces'; | ||
|
||
export const convertCsvDocumentsToPdf = (documents: IDocumentsProps['documents']) => { | ||
return documents.map(document => { | ||
if (isCsv(document)) { | ||
return { ...document, imageUrl: convertCsvToPdfBase64String(document.imageUrl) }; | ||
} | ||
|
||
return document; | ||
}); | ||
}; |
17 changes: 10 additions & 7 deletions
17
apps/backoffice-v2/src/pages/Entity/components/Case/hooks/useDocuments/useDocumentsLogic.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.