Skip to content

Commit

Permalink
feat: Export winners csv
Browse files Browse the repository at this point in the history
  • Loading branch information
1marcghannam committed May 25, 2023
1 parent 98a8912 commit 6d61691
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React, { useState, useEffect } from 'react'
import { Button, Text, Stack, Flex, Heading } from '@chakra-ui/react'

export const CheckWinners = ({ store, reset }) => {
const [winners, setWinners] = useState([])

const componentDidMount = () => {
readWinners(store)
}

useEffect(componentDidMount, [])

const readWinners = (store) => {
Expand All @@ -21,6 +23,16 @@ export const CheckWinners = ({ store, reset }) => {
setWinners(winnersArr)
}

const exportToCSV = () => {
const csvData = winners.join('\n')
const blob = new Blob([csvData], { type: 'text/csv' })
const url = URL.createObjectURL(blob)
const link = document.createElement('a')
link.download = 'winners.csv'
link.href = url
link.click()
}

return (
<>
<Heading size="md" mb="6">
Expand All @@ -34,6 +46,9 @@ export const CheckWinners = ({ store, reset }) => {
))}
</Stack>
<Flex mt="2" justify="end">
<Button variant="default" mr="4" onClick={exportToCSV}>
Export to CSV
</Button>
<Button variant="default" onClick={() => reset(store)}>
Close
</Button>
Expand Down

0 comments on commit 6d61691

Please sign in to comment.