-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
507be75
commit e1bff51
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React from 'react' | ||
import Button from '@mui/material/Button' | ||
import Papa from 'papaparse' | ||
import { Vehicle } from '@/utils/types' | ||
import { Box, Tooltip, Typography } from '@mui/material' | ||
|
||
interface ExportButtonProps { | ||
vehicle: Vehicle | ||
} | ||
|
||
const ExportButton: React.FC<ExportButtonProps> = ({ vehicle }) => { | ||
const handleExport = () => { | ||
const data = vehicle.journalEntries.map(entry => ({ | ||
Service: entry.service, | ||
Mileage: entry.mileage, | ||
Date: entry.date, | ||
Notes: entry.notes, | ||
Parts: entry.parts, | ||
Tools: entry.tools, | ||
Spent: entry.spent, | ||
Future: entry.future, | ||
})) | ||
const csv = Papa.unparse(data) | ||
const blob = new Blob([csv], { type: 'text/csv' }) | ||
const url = URL.createObjectURL(blob) | ||
const link = document.createElement('a') | ||
link.href = url | ||
link.download = `${vehicle.name}.csv` | ||
document.body.appendChild(link) | ||
link.click() | ||
document.body.removeChild(link) | ||
} | ||
|
||
return ( | ||
<Box sx={{m:1}}> | ||
<Tooltip title='Export all journal entries for this vehicle to a CSV file. The file will be named after the vehicle.'> | ||
<Button variant='contained' color='info' onClick={handleExport}> | ||
<Typography variant='overline' >Export</Typography> | ||
</Button> | ||
</Tooltip> | ||
</Box> | ||
) | ||
} | ||
|
||
export default ExportButton |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters