feat: Add Reports for teams (#3116)
Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
@@ -7,6 +7,8 @@ import fromUnixTime from 'date-fns/fromUnixTime';
|
||||
import * as types from '../mutation-types';
|
||||
import Report from '../../api/reports';
|
||||
|
||||
import { downloadCsvFile } from '../../helper/downloadCsvFile';
|
||||
|
||||
const state = {
|
||||
fetchingStatus: false,
|
||||
reportData: [],
|
||||
@@ -78,15 +80,7 @@ export const actions = {
|
||||
downloadAgentReports(_, reportObj) {
|
||||
return Report.getAgentReports(reportObj.from, reportObj.to)
|
||||
.then(response => {
|
||||
let csvContent = 'data:text/csv;charset=utf-8,' + response.data;
|
||||
var encodedUri = encodeURI(csvContent);
|
||||
var downloadLink = document.createElement('a');
|
||||
downloadLink.href = encodedUri;
|
||||
downloadLink.download = reportObj.fileName;
|
||||
|
||||
document.body.appendChild(downloadLink);
|
||||
downloadLink.click();
|
||||
document.body.removeChild(downloadLink);
|
||||
downloadCsvFile(reportObj.fileName, response.data);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(error);
|
||||
@@ -95,15 +89,7 @@ export const actions = {
|
||||
downloadLabelReports(_, reportObj) {
|
||||
return Report.getLabelReports(reportObj.from, reportObj.to)
|
||||
.then(response => {
|
||||
let csvContent = 'data:text/csv;charset=utf-8,' + response.data;
|
||||
var encodedUri = encodeURI(csvContent);
|
||||
var downloadLink = document.createElement('a');
|
||||
downloadLink.href = encodedUri;
|
||||
downloadLink.download = reportObj.fileName;
|
||||
|
||||
document.body.appendChild(downloadLink);
|
||||
downloadLink.click();
|
||||
document.body.removeChild(downloadLink);
|
||||
downloadCsvFile(reportObj.fileName, response.data);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(error);
|
||||
@@ -112,15 +98,16 @@ export const actions = {
|
||||
downloadInboxReports(_, reportObj) {
|
||||
return Report.getInboxReports(reportObj.from, reportObj.to)
|
||||
.then(response => {
|
||||
let csvContent = 'data:text/csv;charset=utf-8,' + response.data;
|
||||
var encodedUri = encodeURI(csvContent);
|
||||
var downloadLink = document.createElement('a');
|
||||
downloadLink.href = encodedUri;
|
||||
downloadLink.download = reportObj.fileName;
|
||||
|
||||
document.body.appendChild(downloadLink);
|
||||
downloadLink.click();
|
||||
// document.body.removeChild(downloadLink);
|
||||
downloadCsvFile(reportObj.fileName, response.data);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(error);
|
||||
});
|
||||
},
|
||||
downloadTeamReports(_, reportObj) {
|
||||
return Report.getTeamReports(reportObj.from, reportObj.to)
|
||||
.then(response => {
|
||||
downloadCsvFile(reportObj.fileName, response.data);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(error);
|
||||
|
||||
@@ -78,4 +78,25 @@ describe('#actions', () => {
|
||||
expect(mockInboxDownloadElement.download).toEqual(param.fileName);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#downloadTeamReports', () => {
|
||||
it('open CSV download prompt if API is success', async () => {
|
||||
axios.get.mockResolvedValue({
|
||||
data: `Team name,Conversations count,Avg first response time (Minutes),Avg resolution time (Minutes)
|
||||
sales team,0,0,0
|
||||
Reporting period 2021-09-23 to 2021-09-29`,
|
||||
});
|
||||
const param = {
|
||||
from: 1631039400,
|
||||
to: 1635013800,
|
||||
fileName: 'inbox-report-24-10-2021.csv',
|
||||
};
|
||||
const mockInboxDownloadElement = createElementSpy();
|
||||
await actions.downloadInboxReports(1, param);
|
||||
expect(mockInboxDownloadElement.href).toEqual(
|
||||
'data:text/csv;charset=utf-8,Team%20name,Conversations%20count,Avg%20first%20response%20time%20(Minutes),Avg%20resolution%20time%20(Minutes)%0A%20%20%20%20%20%20%20%20sales%20team,0,0,0%0A%20%20%20%20%20%20%20%20Reporting%20period%202021-09-23%20to%202021-09-29'
|
||||
);
|
||||
expect(mockInboxDownloadElement.download).toEqual(param.fileName);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user