Chatwoot/app/javascript/dashboard/helper/downloadHelper.js
Pranav Raj S 52fad886b8
feat: Add business hours in downloadable reports (#4674)
Co-authored-by: Aswin Dev P.S <aswindevps@gmail.com>
2022-05-27 09:26:59 +05:30

22 lines
695 B
JavaScript

import fromUnixTime from 'date-fns/fromUnixTime';
import format from 'date-fns/format';
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);
const link = document.createElement('a');
link.setAttribute('download', fileName);
link.setAttribute('href', url);
link.click();
return link;
};
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`;
};