diff --git a/apps/dashboard/pages/participant-database/index.tsx b/apps/dashboard/pages/participant-database/index.tsx index 9a7fc405..2f7a858b 100644 --- a/apps/dashboard/pages/participant-database/index.tsx +++ b/apps/dashboard/pages/participant-database/index.tsx @@ -15,6 +15,8 @@ import { Button, ParagraphText } from '@hibiscus/ui-kit-2023'; import { getWordCount } from '../../common/utils'; import HackerProfile from '../../components/sponsor-portal/hacker-profile'; import { SponsorServiceAPI } from '../../common/api'; +import { CSVLink } from 'react-csv'; +import JSZip from 'jszip'; const Index = () => { const router = useRouter(); @@ -36,6 +38,7 @@ const Index = () => { const [currentAttendee, setCurrentAttendee] = useState(null); const [modalActive, setModalActive] = useState(false); const [attendeeName, setAttendeeName] = useState(''); + const zip = new JSZip(); useEffect(() => { async function getFilteredAttendee() { @@ -241,15 +244,61 @@ const Index = () => { } } + async function downloadResumePdfs() { + for (const attendee of attendees) { + if (attendee.resume) { + const response = await fetch(attendee.resume); + const resumeBlob = await response.blob(); + const attendeeName = attendee.full_name.replace(' ', ''); // Remove whitespaces from name + // eslint-disable-next-line + const regExp = '[^/]+$'; + const fileType = resumeBlob.type.match(regExp)[0]; + zip.file(attendeeName + '_Resume.' + fileType, resumeBlob); + } + } + // Generate the zip file asynchronously + zip + .generateAsync({ type: 'blob' }) + .then((content) => { + // 'content' is a Blob containing the zip file data + // Example: Create a download link for the zip file + // Could use something like FileSaver.js (https://github.com/eligrey/FileSaver.js), but didn't want to add extra dependencies + const downloadLink = document.createElement('a'); + downloadLink.href = URL.createObjectURL(content); + downloadLink.download = 'participant_resumes.zip'; + downloadLink.click(); + downloadLink.remove(); + }) + .catch((error) => { + console.error('Error generating zip file:', error); + }); + } + return ( - { - router.replace('/sponsor-booth'); - }} - > - Illustration - + + { + router.replace('/sponsor-booth'); + }} + > + Illustration + + + Download participant resumes + + item + ) /* Supplying attendees without resume field */ + } + > + Export participant data to CSV + + +