From 978aed6397dee9d8146201a071d647a3cd79ede5 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Tue, 6 May 2025 20:10:21 +0100 Subject: [PATCH 1/2] fixing remote assessment modal --- .../components/RemoteAssessmentModal.tsx | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/app/portfolio/[slug]/components/RemoteAssessmentModal.tsx b/src/app/portfolio/[slug]/components/RemoteAssessmentModal.tsx index 0a46857c..52ade5ac 100644 --- a/src/app/portfolio/[slug]/components/RemoteAssessmentModal.tsx +++ b/src/app/portfolio/[slug]/components/RemoteAssessmentModal.tsx @@ -332,16 +332,29 @@ function generateS3Keys(userId: string, portfolioId: string) { type GenericObject = Record; -const convertToCSV = (data: T[]): string => { - // Get headers (keys from the first object) +const convertToCSV = >(data: T[]): string => { + if (data.length === 0) return ""; + const headers = Object.keys(data[0]) as (keyof T)[]; - // Create CSV rows + const escape = (value: any): string => { + if (value == null) return ""; + + const str = String(value); + + // Check if field contains special characters + if (/[",\n]/.test(str)) { + // Escape double quotes and wrap in quotes + return `"${str.replace(/"/g, '""')}"`; + } + + return str; + }; + const rows = data.map((row) => - headers.map((header) => row[header]).join(",") + headers.map((header) => escape(row[header])).join(",") ); - // Combine headers and rows into CSV string return [headers.join(","), ...rows].join("\n"); }; @@ -414,6 +427,8 @@ function useCreateRemoteAssessment({ }, ]; + console.log("HELLO WORLD", convertToCSV(assetList)); + csvFile = new Blob([convertToCSV(assetList)], { type: "text/csv", }); From c3c536df16c72c0489bff1fefd602217394ad88d Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Tue, 6 May 2025 20:11:50 +0100 Subject: [PATCH 2/2] removing comments --- .../portfolio/[slug]/components/RemoteAssessmentModal.tsx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/app/portfolio/[slug]/components/RemoteAssessmentModal.tsx b/src/app/portfolio/[slug]/components/RemoteAssessmentModal.tsx index 52ade5ac..8b119d9d 100644 --- a/src/app/portfolio/[slug]/components/RemoteAssessmentModal.tsx +++ b/src/app/portfolio/[slug]/components/RemoteAssessmentModal.tsx @@ -288,8 +288,7 @@ async function uploadCsvToS3({ console.error(error); throw new Error("Upload failed."); } - - console.log("S3 got the stuff"); + console.log("File uploaded successfully"); return { success: true }; } @@ -427,8 +426,6 @@ function useCreateRemoteAssessment({ }, ]; - console.log("HELLO WORLD", convertToCSV(assetList)); - csvFile = new Blob([convertToCSV(assetList)], { type: "text/csv", });