From 9f4fe3236e0c5f135c44a245b9157270e940c36d Mon Sep 17 00:00:00 2001 From: Michael Hunteman Date: Fri, 8 Nov 2024 13:25:12 -0800 Subject: Export guests as csv --- client/src/components/BlurryLoadDiv.tsx | 21 --------------------- client/src/components/Dashboard.tsx | 28 +++++++++++++++++++++++++++- client/src/components/Schedule.tsx | 5 ++--- 3 files changed, 29 insertions(+), 25 deletions(-) delete mode 100644 client/src/components/BlurryLoadDiv.tsx (limited to 'client/src') diff --git a/client/src/components/BlurryLoadDiv.tsx b/client/src/components/BlurryLoadDiv.tsx deleted file mode 100644 index 1dfe07e..0000000 --- a/client/src/components/BlurryLoadDiv.tsx +++ /dev/null @@ -1,21 +0,0 @@ -import React from 'react'; -import { ClassAttributes, ImgHTMLAttributes } from 'react'; -import { JSX } from 'react/jsx-runtime'; -import { useBlurryLoad } from '../useBlurryLoad.ts'; -import { useMediaQuery } from '@mui/material'; - -export const BlurryLoadDiv = ( - props: JSX.IntrinsicAttributes & - ClassAttributes & - ImgHTMLAttributes & { 'data-large': string } -) => { - const isMobile = useMediaQuery('(max-width: 768px)'); - let blurry = ''; - if (!isMobile) { - useBlurryLoad(); - blurry = 'blurry-load'; - } - return ( -
- ); -}; diff --git a/client/src/components/Dashboard.tsx b/client/src/components/Dashboard.tsx index 119fc5d..8b005df 100644 --- a/client/src/components/Dashboard.tsx +++ b/client/src/components/Dashboard.tsx @@ -6,7 +6,8 @@ import { type MRT_ColumnDef, } from 'material-react-table'; import type { Guest } from '../models'; -import { createTheme, ThemeProvider, useTheme } from '@mui/material'; +import { Button, createTheme, ThemeProvider, useTheme } from '@mui/material'; +import { mkConfig, generateCsv, download } from 'export-to-csv'; function Dashboard() { const tableTheme = createTheme({ @@ -52,9 +53,34 @@ function Dashboard() { ], [] ); + + const csvConfig = mkConfig({ + fieldSeparator: ',', + decimalSeparator: '.', + useKeysAsHeaders: true, + }); + + const handleExportData = () => { + let data = guests.map(({ id, partyList, ...guest }) => guest); + guests.forEach((guest) => { + const { attendance, partySize } = guest; + guest?.partyList?.forEach((partyGuest) => + data.push({ ...partyGuest, attendance, partySize }) + ); + }); + download(csvConfig)(generateCsv(csvConfig)(data)); + }; + const table = useMaterialReactTable({ columns, data: guests, + renderTopToolbarCustomActions: () => ( +
+ +
+ ), muiPaginationProps: { color: 'primary', shape: 'rounded', diff --git a/client/src/components/Schedule.tsx b/client/src/components/Schedule.tsx index dfe4a30..fc1fb64 100644 --- a/client/src/components/Schedule.tsx +++ b/client/src/components/Schedule.tsx @@ -9,7 +9,6 @@ import { import InsertInvitationIcon from '@mui/icons-material/InsertInvitation'; import { useAppDispatch } from '../hooks'; import { showDialog } from '../slices/uiSlice'; -import { BlurryLoadDiv } from './BlurryLoadDiv'; function Schedule() { const dispatch = useAppDispatch(); @@ -21,7 +20,7 @@ function Schedule() { }; return ( - - + ); } -- cgit v1.2.3