2019-08-14 09:48:44 +00:00
|
|
|
/* eslint no-console: 0 */
|
|
|
|
/* eslint no-param-reassign: 0 */
|
|
|
|
/* eslint no-shadow: 0 */
|
|
|
|
import * as types from '../mutation-types';
|
|
|
|
import Report from '../../api/reports';
|
|
|
|
|
2021-10-06 18:23:51 +00:00
|
|
|
import { downloadCsvFile } from '../../helper/downloadCsvFile';
|
|
|
|
|
2019-08-14 09:48:44 +00:00
|
|
|
const state = {
|
|
|
|
fetchingStatus: false,
|
|
|
|
reportData: [],
|
|
|
|
accountReport: {
|
|
|
|
isFetching: false,
|
|
|
|
data: [],
|
|
|
|
},
|
|
|
|
accountSummary: {
|
|
|
|
avg_first_response_time: 0,
|
|
|
|
avg_resolution_time: 0,
|
|
|
|
conversations_count: 0,
|
|
|
|
incoming_messages_count: 0,
|
|
|
|
outgoing_messages_count: 0,
|
|
|
|
resolutions_count: 0,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const getters = {
|
|
|
|
getAccountReports(_state) {
|
|
|
|
return _state.accountReport;
|
|
|
|
},
|
|
|
|
getAccountSummary(_state) {
|
|
|
|
return _state.accountSummary;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-12-15 18:05:03 +00:00
|
|
|
export const actions = {
|
2019-08-14 09:48:44 +00:00
|
|
|
fetchAccountReport({ commit }, reportObj) {
|
|
|
|
commit(types.default.TOGGLE_ACCOUNT_REPORT_LOADING, true);
|
feat - Add filter for reports by agent, label and inboxes (#3084)
* Adds filter for agents, labels and inboxes
* Added Inboxes Reports Feature
* Fixed populating of filter dropdown issue
* If applied, fixes code climate style-lint warnings
* Fixes codeclimate warnings
* if applied, Refactors sidebar file to fix codclimate warnings
* if applied, fixes the download reports button for filtered report-data
* If applied, replaces native img tag with thumbnail component
* If applied, replaces hardcoded color string with variable
* If applied, adds a11y labels to multiselect dropdowns
* If applied, Renames reports methods to generic names
* If applied, Adds test cases for Labels and Inboxes
* If applied, write a test spec for fileDownload helper
* if applied, Moves fileDownload method to a utils folder
* If applied, Fixes the report file name type
* Test Spec for Reports Store module
* Fix specs - add restoreAllMocks
Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
2021-09-30 07:43:45 +00:00
|
|
|
Report.getReports(
|
2019-08-21 07:29:56 +00:00
|
|
|
reportObj.metric,
|
|
|
|
reportObj.from,
|
feat - Add filter for reports by agent, label and inboxes (#3084)
* Adds filter for agents, labels and inboxes
* Added Inboxes Reports Feature
* Fixed populating of filter dropdown issue
* If applied, fixes code climate style-lint warnings
* Fixes codeclimate warnings
* if applied, Refactors sidebar file to fix codclimate warnings
* if applied, fixes the download reports button for filtered report-data
* If applied, replaces native img tag with thumbnail component
* If applied, replaces hardcoded color string with variable
* If applied, adds a11y labels to multiselect dropdowns
* If applied, Renames reports methods to generic names
* If applied, Adds test cases for Labels and Inboxes
* If applied, write a test spec for fileDownload helper
* if applied, Moves fileDownload method to a utils folder
* If applied, Fixes the report file name type
* Test Spec for Reports Store module
* Fix specs - add restoreAllMocks
Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
2021-09-30 07:43:45 +00:00
|
|
|
reportObj.to,
|
|
|
|
reportObj.type,
|
2022-02-15 11:40:49 +00:00
|
|
|
reportObj.id,
|
|
|
|
reportObj.groupBy
|
2019-08-21 07:29:56 +00:00
|
|
|
).then(accountReport => {
|
|
|
|
let { data } = accountReport;
|
2020-09-14 09:44:26 +00:00
|
|
|
data = data.filter(
|
2022-02-28 05:26:24 +00:00
|
|
|
el =>
|
|
|
|
reportObj.to - el.timestamp > 0 && el.timestamp - reportObj.from >= 0
|
2020-09-14 09:44:26 +00:00
|
|
|
);
|
2019-08-21 07:29:56 +00:00
|
|
|
if (
|
|
|
|
reportObj.metric === 'avg_first_response_time' ||
|
|
|
|
reportObj.metric === 'avg_resolution_time'
|
|
|
|
) {
|
|
|
|
data = data.map(element => {
|
|
|
|
/* eslint-disable operator-assignment */
|
|
|
|
element.value = (element.value / 3600).toFixed(2);
|
|
|
|
return element;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
commit(types.default.SET_ACCOUNT_REPORTS, data);
|
|
|
|
commit(types.default.TOGGLE_ACCOUNT_REPORT_LOADING, false);
|
|
|
|
});
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
|
|
|
fetchAccountSummary({ commit }, reportObj) {
|
feat - Add filter for reports by agent, label and inboxes (#3084)
* Adds filter for agents, labels and inboxes
* Added Inboxes Reports Feature
* Fixed populating of filter dropdown issue
* If applied, fixes code climate style-lint warnings
* Fixes codeclimate warnings
* if applied, Refactors sidebar file to fix codclimate warnings
* if applied, fixes the download reports button for filtered report-data
* If applied, replaces native img tag with thumbnail component
* If applied, replaces hardcoded color string with variable
* If applied, adds a11y labels to multiselect dropdowns
* If applied, Renames reports methods to generic names
* If applied, Adds test cases for Labels and Inboxes
* If applied, write a test spec for fileDownload helper
* if applied, Moves fileDownload method to a utils folder
* If applied, Fixes the report file name type
* Test Spec for Reports Store module
* Fix specs - add restoreAllMocks
Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
2021-09-30 07:43:45 +00:00
|
|
|
Report.getSummary(
|
|
|
|
reportObj.from,
|
|
|
|
reportObj.to,
|
|
|
|
reportObj.type,
|
2022-02-15 11:40:49 +00:00
|
|
|
reportObj.id,
|
|
|
|
reportObj.groupBy
|
feat - Add filter for reports by agent, label and inboxes (#3084)
* Adds filter for agents, labels and inboxes
* Added Inboxes Reports Feature
* Fixed populating of filter dropdown issue
* If applied, fixes code climate style-lint warnings
* Fixes codeclimate warnings
* if applied, Refactors sidebar file to fix codclimate warnings
* if applied, fixes the download reports button for filtered report-data
* If applied, replaces native img tag with thumbnail component
* If applied, replaces hardcoded color string with variable
* If applied, adds a11y labels to multiselect dropdowns
* If applied, Renames reports methods to generic names
* If applied, Adds test cases for Labels and Inboxes
* If applied, write a test spec for fileDownload helper
* if applied, Moves fileDownload method to a utils folder
* If applied, Fixes the report file name type
* Test Spec for Reports Store module
* Fix specs - add restoreAllMocks
Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
2021-09-30 07:43:45 +00:00
|
|
|
)
|
2019-08-21 07:29:56 +00:00
|
|
|
.then(accountSummary => {
|
2019-08-14 09:48:44 +00:00
|
|
|
commit(types.default.SET_ACCOUNT_SUMMARY, accountSummary.data);
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
commit(types.default.TOGGLE_ACCOUNT_REPORT_LOADING, false);
|
|
|
|
});
|
|
|
|
},
|
2020-12-15 18:05:03 +00:00
|
|
|
downloadAgentReports(_, reportObj) {
|
|
|
|
return Report.getAgentReports(reportObj.from, reportObj.to)
|
|
|
|
.then(response => {
|
2021-10-06 18:23:51 +00:00
|
|
|
downloadCsvFile(reportObj.fileName, response.data);
|
2020-12-15 18:05:03 +00:00
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.error(error);
|
|
|
|
});
|
|
|
|
},
|
feat - Add filter for reports by agent, label and inboxes (#3084)
* Adds filter for agents, labels and inboxes
* Added Inboxes Reports Feature
* Fixed populating of filter dropdown issue
* If applied, fixes code climate style-lint warnings
* Fixes codeclimate warnings
* if applied, Refactors sidebar file to fix codclimate warnings
* if applied, fixes the download reports button for filtered report-data
* If applied, replaces native img tag with thumbnail component
* If applied, replaces hardcoded color string with variable
* If applied, adds a11y labels to multiselect dropdowns
* If applied, Renames reports methods to generic names
* If applied, Adds test cases for Labels and Inboxes
* If applied, write a test spec for fileDownload helper
* if applied, Moves fileDownload method to a utils folder
* If applied, Fixes the report file name type
* Test Spec for Reports Store module
* Fix specs - add restoreAllMocks
Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
2021-09-30 07:43:45 +00:00
|
|
|
downloadLabelReports(_, reportObj) {
|
|
|
|
return Report.getLabelReports(reportObj.from, reportObj.to)
|
|
|
|
.then(response => {
|
2021-10-06 18:23:51 +00:00
|
|
|
downloadCsvFile(reportObj.fileName, response.data);
|
feat - Add filter for reports by agent, label and inboxes (#3084)
* Adds filter for agents, labels and inboxes
* Added Inboxes Reports Feature
* Fixed populating of filter dropdown issue
* If applied, fixes code climate style-lint warnings
* Fixes codeclimate warnings
* if applied, Refactors sidebar file to fix codclimate warnings
* if applied, fixes the download reports button for filtered report-data
* If applied, replaces native img tag with thumbnail component
* If applied, replaces hardcoded color string with variable
* If applied, adds a11y labels to multiselect dropdowns
* If applied, Renames reports methods to generic names
* If applied, Adds test cases for Labels and Inboxes
* If applied, write a test spec for fileDownload helper
* if applied, Moves fileDownload method to a utils folder
* If applied, Fixes the report file name type
* Test Spec for Reports Store module
* Fix specs - add restoreAllMocks
Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
2021-09-30 07:43:45 +00:00
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.error(error);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
downloadInboxReports(_, reportObj) {
|
|
|
|
return Report.getInboxReports(reportObj.from, reportObj.to)
|
|
|
|
.then(response => {
|
2021-10-06 18:23:51 +00:00
|
|
|
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);
|
feat - Add filter for reports by agent, label and inboxes (#3084)
* Adds filter for agents, labels and inboxes
* Added Inboxes Reports Feature
* Fixed populating of filter dropdown issue
* If applied, fixes code climate style-lint warnings
* Fixes codeclimate warnings
* if applied, Refactors sidebar file to fix codclimate warnings
* if applied, fixes the download reports button for filtered report-data
* If applied, replaces native img tag with thumbnail component
* If applied, replaces hardcoded color string with variable
* If applied, adds a11y labels to multiselect dropdowns
* If applied, Renames reports methods to generic names
* If applied, Adds test cases for Labels and Inboxes
* If applied, write a test spec for fileDownload helper
* if applied, Moves fileDownload method to a utils folder
* If applied, Fixes the report file name type
* Test Spec for Reports Store module
* Fix specs - add restoreAllMocks
Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
2021-09-30 07:43:45 +00:00
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.error(error);
|
|
|
|
});
|
|
|
|
},
|
2019-08-14 09:48:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const mutations = {
|
|
|
|
[types.default.SET_ACCOUNT_REPORTS](_state, accountReport) {
|
|
|
|
_state.accountReport.data = accountReport;
|
|
|
|
},
|
|
|
|
[types.default.TOGGLE_ACCOUNT_REPORT_LOADING](_state, flag) {
|
|
|
|
_state.accountReport.isFetching = flag;
|
|
|
|
},
|
|
|
|
[types.default.SET_ACCOUNT_SUMMARY](_state, summaryData) {
|
|
|
|
_state.accountSummary = summaryData;
|
|
|
|
// Average First Response Time
|
|
|
|
let avgFirstResTimeInHr = 0;
|
|
|
|
if (summaryData.avg_first_response_time) {
|
2019-08-21 07:29:56 +00:00
|
|
|
avgFirstResTimeInHr = (
|
|
|
|
summaryData.avg_first_response_time / 3600
|
|
|
|
).toFixed(2);
|
2019-08-14 09:48:44 +00:00
|
|
|
avgFirstResTimeInHr = `${avgFirstResTimeInHr} Hr`;
|
|
|
|
}
|
|
|
|
// Average Resolution Time
|
|
|
|
let avgResolutionTimeInHr = 0;
|
|
|
|
if (summaryData.avg_resolution_time) {
|
2019-08-21 07:29:56 +00:00
|
|
|
avgResolutionTimeInHr = (summaryData.avg_resolution_time / 3600).toFixed(
|
|
|
|
2
|
|
|
|
);
|
2019-08-14 09:48:44 +00:00
|
|
|
avgResolutionTimeInHr = `${avgResolutionTimeInHr} Hr`;
|
|
|
|
}
|
|
|
|
_state.accountSummary.avg_first_response_time = avgFirstResTimeInHr;
|
|
|
|
_state.accountSummary.avg_resolution_time = avgResolutionTimeInHr;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export default {
|
|
|
|
state,
|
|
|
|
getters,
|
|
|
|
actions,
|
|
|
|
mutations,
|
|
|
|
};
|