From 7b11ef9b403d1208619085f6034ac835bfc8d223 Mon Sep 17 00:00:00 2001 From: Anshuman Pandey <54475686+pandeymangg@users.noreply.github.com> Date: Wed, 18 Dec 2024 17:32:21 +0530 Subject: [PATCH] fix: adds example CSV and other fixes on the contacts page (#4493) Co-authored-by: Johannes <72809645+jobenjada@users.noreply.github.com> --- .../contacts/components/contact-data-view.tsx | 2 +- .../ee/contacts/components/contacts-table.tsx | 2 +- .../components/upload-contacts-button.tsx | 102 ++++++++++++------ .../components/data-table-toolbar.tsx | 17 ++- .../web/modules/ui/components/modal/index.tsx | 2 +- .../ui/components/styling-tabs/index.tsx | 2 +- packages/lib/messages/de-DE.json | 3 + packages/lib/messages/en-US.json | 3 + packages/lib/messages/fr-FR.json | 3 + packages/lib/messages/pt-BR.json | 3 + 10 files changed, 99 insertions(+), 40 deletions(-) diff --git a/apps/web/modules/ee/contacts/components/contact-data-view.tsx b/apps/web/modules/ee/contacts/components/contact-data-view.tsx index 3863f1c1eb..b0b00ce149 100644 --- a/apps/web/modules/ee/contacts/components/contact-data-view.tsx +++ b/apps/web/modules/ee/contacts/components/contact-data-view.tsx @@ -24,7 +24,7 @@ interface ContactDataViewProps { itemsPerPage: number; isReadOnly: boolean; hasMore: boolean; - refreshContacts: () => void; + refreshContacts: () => Promise; } export const ContactDataView = ({ diff --git a/apps/web/modules/ee/contacts/components/contacts-table.tsx b/apps/web/modules/ee/contacts/components/contacts-table.tsx index d526cb15c3..60389077b8 100644 --- a/apps/web/modules/ee/contacts/components/contacts-table.tsx +++ b/apps/web/modules/ee/contacts/components/contacts-table.tsx @@ -42,7 +42,7 @@ interface ContactsTableProps { searchValue: string; setSearchValue: (value: string) => void; isReadOnly: boolean; - refreshContacts: () => void; + refreshContacts: () => Promise; } export const ContactsTable = ({ diff --git a/apps/web/modules/ee/contacts/components/upload-contacts-button.tsx b/apps/web/modules/ee/contacts/components/upload-contacts-button.tsx index 506e07ee3b..f0db56557e 100644 --- a/apps/web/modules/ee/contacts/components/upload-contacts-button.tsx +++ b/apps/web/modules/ee/contacts/components/upload-contacts-button.tsx @@ -210,6 +210,29 @@ export const UploadContactsCSVButton = ({ } }, [error]); + // Function to download an example CSV + const handleDownloadExampleCSV = () => { + const exampleData = [ + { email: "user1@example.com", userId: "1001", firstName: "John", lastName: "Doe" }, + { email: "user2@example.com", userId: "1002", firstName: "Jane", lastName: "Smith" }, + { email: "user3@example.com", userId: "1003", firstName: "Mark", lastName: "Jones" }, + { email: "user4@example.com", userId: "1004", firstName: "Emily", lastName: "Brown" }, + { email: "user5@example.com", userId: "1005", firstName: "David", lastName: "Wilson" }, + ]; + + const headers = Object.keys(exampleData[0]); + const csvRows = [headers.join(","), ...exampleData.map((row) => headers.map((h) => row[h]).join(","))]; + const csvContent = "data:text/csv;charset=utf-8," + csvRows.join("\n"); + const encodedUri = encodeURI(csvContent); + + const link = document.createElement("a"); + link.setAttribute("href", encodedUri); + link.setAttribute("download", "example.csv"); + document.body.appendChild(link); // Required for Firefox + link.click(); + document.body.removeChild(link); + }; + return ( <>