-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathExportPreview.tsx
More file actions
57 lines (52 loc) · 1.62 KB
/
Copy pathExportPreview.tsx
File metadata and controls
57 lines (52 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import React, { useState, useRef } from 'react';
import { CSVLink } from 'react-csv';
import ScheduledTable from '../UserTables/ScheduledTable';
import styles from './exportPreview.module.css';
import { useEmployees } from '../../context/EmployeesContext';
import ExportButton from '../ExportButton/ExportButton';
import { useDate } from '../../context/date';
import { format_date } from '../../util';
import axios from '../../util/axios';
const ExportPreview = () => {
const { drivers } = useEmployees();
const [downloadData, setDownloadData] = useState<string>('');
const { curDate } = useDate();
const csvLink = useRef<
CSVLink & HTMLAnchorElement & { link: HTMLAnchorElement }
>(null);
const today = format_date(curDate);
const downloadCSV = () => {
axios
.get(`/api/rides/download?date=${today}`, {
responseType: 'text',
transformResponse: [(data) => data],
})
.then((res) => res.data)
.then((data) => {
setDownloadData(data);
if (csvLink.current) {
csvLink.current.link.click();
}
});
};
return (
<>
<p className={styles.date}>{format_date(curDate)}</p>
<h1 className={styles.header}>Scheduled Rides</h1>
<div id="exportTable">
<ScheduledTable />
</div>
<div className={styles.exportButtonContainer}>
{/* <ExportButton onClick={downloadCSV} /> */}
<CSVLink
data={downloadData}
filename={`scheduledRides_${today}.csv`}
className="hidden"
ref={csvLink}
target="_blank"
/>
</div>
</>
);
};
export default ExportPreview;