feat: Add business hours in downloadable reports (#4674)
Co-authored-by: Aswin Dev P.S <aswindevps@gmail.com>
This commit is contained in:
@@ -53,27 +53,27 @@ class ReportsAPI extends ApiClient {
|
||||
});
|
||||
}
|
||||
|
||||
getAgentReports(since, until) {
|
||||
getAgentReports({ from: since, to: until, businessHours }) {
|
||||
return axios.get(`${this.url}/agents`, {
|
||||
params: { since, until },
|
||||
params: { since, until, business_hours: businessHours },
|
||||
});
|
||||
}
|
||||
|
||||
getLabelReports(since, until) {
|
||||
getLabelReports({ from: since, to: until, businessHours }) {
|
||||
return axios.get(`${this.url}/labels`, {
|
||||
params: { since, until },
|
||||
params: { since, until, business_hours: businessHours },
|
||||
});
|
||||
}
|
||||
|
||||
getInboxReports(since, until) {
|
||||
getInboxReports({ from: since, to: until, businessHours }) {
|
||||
return axios.get(`${this.url}/inboxes`, {
|
||||
params: { since, until },
|
||||
params: { since, until, business_hours: businessHours },
|
||||
});
|
||||
}
|
||||
|
||||
getTeamReports(since, until) {
|
||||
getTeamReports({ from: since, to: until, businessHours }) {
|
||||
return axios.get(`${this.url}/teams`, {
|
||||
params: { since, until },
|
||||
params: { since, until, business_hours: businessHours },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,20 +47,25 @@ describe('#Reports API', () => {
|
||||
});
|
||||
|
||||
it('#getAgentReports', () => {
|
||||
reportsAPI.getAgentReports(1621103400, 1621621800);
|
||||
reportsAPI.getAgentReports({
|
||||
from: 1621103400,
|
||||
to: 1621621800,
|
||||
businessHours: true,
|
||||
});
|
||||
expect(context.axiosMock.get).toHaveBeenCalledWith(
|
||||
'/api/v2/reports/agents',
|
||||
{
|
||||
params: {
|
||||
since: 1621103400,
|
||||
until: 1621621800,
|
||||
business_hours: true,
|
||||
},
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('#getLabelReports', () => {
|
||||
reportsAPI.getLabelReports(1621103400, 1621621800);
|
||||
reportsAPI.getLabelReports({ from: 1621103400, to: 1621621800 });
|
||||
expect(context.axiosMock.get).toHaveBeenCalledWith(
|
||||
'/api/v2/reports/labels',
|
||||
{
|
||||
@@ -73,7 +78,7 @@ describe('#Reports API', () => {
|
||||
});
|
||||
|
||||
it('#getInboxReports', () => {
|
||||
reportsAPI.getInboxReports(1621103400, 1621621800);
|
||||
reportsAPI.getInboxReports({ from: 1621103400, to: 1621621800 });
|
||||
expect(context.axiosMock.get).toHaveBeenCalledWith(
|
||||
'/api/v2/reports/inboxes',
|
||||
{
|
||||
@@ -86,7 +91,7 @@ describe('#Reports API', () => {
|
||||
});
|
||||
|
||||
it('#getTeamReports', () => {
|
||||
reportsAPI.getTeamReports(1621103400, 1621621800);
|
||||
reportsAPI.getTeamReports({ from: 1621103400, to: 1621621800 });
|
||||
expect(context.axiosMock.get).toHaveBeenCalledWith(
|
||||
'/api/v2/reports/teams',
|
||||
{
|
||||
|
||||
@@ -13,5 +13,10 @@ export const downloadCsvFile = (fileName, content) => {
|
||||
return link;
|
||||
};
|
||||
|
||||
export const generateFileName = ({ type, to }) =>
|
||||
`${type}-report-${format(fromUnixTime(to), 'dd-MM-yyyy')}.csv`;
|
||||
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`;
|
||||
};
|
||||
|
||||
@@ -5,5 +5,9 @@ describe('#generateFileName', () => {
|
||||
expect(generateFileName({ type: 'csat', to: 1652812199 })).toEqual(
|
||||
'csat-report-17-05-2022.csv'
|
||||
);
|
||||
|
||||
expect(
|
||||
generateFileName({ type: 'csat', to: 1652812199, businessHours: true })
|
||||
).toEqual('csat-report-17-05-2022-business-hours.csv');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -251,7 +251,7 @@ export default {
|
||||
});
|
||||
},
|
||||
downloadReports() {
|
||||
const { from, to, type } = this;
|
||||
const { from, to, type, businessHours } = this;
|
||||
const dispatchMethods = {
|
||||
agent: 'downloadAgentReports',
|
||||
label: 'downloadLabelReports',
|
||||
@@ -259,8 +259,8 @@ export default {
|
||||
team: 'downloadTeamReports',
|
||||
};
|
||||
if (dispatchMethods[type]) {
|
||||
const fileName = generateFileName({ type, to });
|
||||
const params = { from, to, fileName };
|
||||
const fileName = generateFileName({ type, to, businessHours });
|
||||
const params = { from, to, fileName, businessHours };
|
||||
this.$store.dispatch(dispatchMethods[type], params);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -120,7 +120,7 @@ export const actions = {
|
||||
commit(types.default.UPDATE_REPORT_AGENTS_STATUS, data);
|
||||
},
|
||||
downloadAgentReports(_, reportObj) {
|
||||
return Report.getAgentReports(reportObj.from, reportObj.to)
|
||||
return Report.getAgentReports(reportObj)
|
||||
.then(response => {
|
||||
downloadCsvFile(reportObj.fileName, response.data);
|
||||
})
|
||||
@@ -129,7 +129,7 @@ export const actions = {
|
||||
});
|
||||
},
|
||||
downloadLabelReports(_, reportObj) {
|
||||
return Report.getLabelReports(reportObj.from, reportObj.to)
|
||||
return Report.getLabelReports(reportObj)
|
||||
.then(response => {
|
||||
downloadCsvFile(reportObj.fileName, response.data);
|
||||
})
|
||||
@@ -138,7 +138,7 @@ export const actions = {
|
||||
});
|
||||
},
|
||||
downloadInboxReports(_, reportObj) {
|
||||
return Report.getInboxReports(reportObj.from, reportObj.to)
|
||||
return Report.getInboxReports(reportObj)
|
||||
.then(response => {
|
||||
downloadCsvFile(reportObj.fileName, response.data);
|
||||
})
|
||||
@@ -147,7 +147,7 @@ export const actions = {
|
||||
});
|
||||
},
|
||||
downloadTeamReports(_, reportObj) {
|
||||
return Report.getTeamReports(reportObj.from, reportObj.to)
|
||||
return Report.getTeamReports(reportObj)
|
||||
.then(response => {
|
||||
downloadCsvFile(reportObj.fileName, response.data);
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user