2022-05-17 15:31:45 +00:00
|
|
|
import fromUnixTime from 'date-fns/fromUnixTime';
|
|
|
|
import format from 'date-fns/format';
|
|
|
|
|
2022-05-18 06:45:30 +00:00
|
|
|
export const downloadCsvFile = (fileName, content) => {
|
|
|
|
const contentType = 'data:text/csv;charset=utf-8;';
|
|
|
|
const blob = new Blob([content], { type: contentType });
|
|
|
|
const url = URL.createObjectURL(blob);
|
|
|
|
|
2021-10-06 18:23:51 +00:00
|
|
|
const link = document.createElement('a');
|
2022-05-18 06:45:30 +00:00
|
|
|
link.setAttribute('download', fileName);
|
|
|
|
link.setAttribute('href', url);
|
2021-10-06 18:23:51 +00:00
|
|
|
link.click();
|
2022-05-18 06:45:30 +00:00
|
|
|
return link;
|
2021-10-06 18:23:51 +00:00
|
|
|
};
|
2022-05-17 15:31:45 +00:00
|
|
|
|
2022-05-27 03:56:59 +00:00
|
|
|
export const generateFileName = ({ type, to, businessHours = false }) => {
|
|
|
|
let name = `${type}-report-${format(fromUnixTime(to), 'dd-MM-yyyy')}`;
|
|
|
|
if (businessHours) {
|
|
|
|
name = `${name}-business-hours`;
|
|
|
|
}
|
|
|
|
return `${name}.csv`;
|
|
|
|
};
|