Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:export CSV file with all event data #160

Merged
merged 4 commits into from
Apr 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion src/components/Events/ImpactSummary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import { IoDocumentText } from 'react-icons/io5';
import { MdPeopleAlt } from 'react-icons/md';
import Backend from '../../utils/utils';
import DataCard from './DataCard';
import { CSVLink } from 'react-csv';

const ImpactSummary = () => {
const [registered, setRegistered] = useState(0);
const [checkedIn, setCheckedIn] = useState(0);
const [total, setTotal] = useState(0);
const [eventIdData, setEventIdData] = useState([]);

useEffect(() => {
getData();
Expand All @@ -30,6 +32,31 @@ const ImpactSummary = () => {
}
};

const header = [
{ key: 'id', label: 'ID' },
{ key: 'volunteer_name', label: 'VOLUNTEER_NAME' },
{ key: 'number_in_party', label: 'NUMBER_IN_PARTY' },
{ key: 'pounds', label: 'POUNDS' },
{ key: 'ounces', label: 'OUNCES' },
{ key: 'notes', label: 'NOTES' },
{ key: 'event_name', label: 'EVENT_NAME' },
{ key: 'is_checked_in', label: 'IS_CHECKED_IN' },
{ key: 'image_array', label: 'IMAGE_ARRAY' },
];

useEffect(() => {
const getEventId = async () => {
try {
const eventIdData = await Backend.get(`/stats/export/data`);
setEventIdData(eventIdData.data.data);
} catch (err) {
console.log(err.message);
}
};

getEventId();
}, []);

return (
<Box
mb="5"
Expand Down Expand Up @@ -72,7 +99,13 @@ const ImpactSummary = () => {
<VStack gap={120}>
<Box></Box>
<Button colorScheme={'messenger'} leftIcon={<AiOutlineExport></AiOutlineExport>} size="md">
Export Data
<CSVLink
data={eventIdData.length ? eventIdData : []}
filename="./data.csv"
headers={header}
>
Export Data
</CSVLink>
</Button>
</VStack>
</Box>
Expand Down
Loading