mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-26 16:04:59 +00:00
feat: Add live report for teams (#10849)
This commit is contained in:
@@ -1,166 +1,17 @@
|
||||
<script>
|
||||
import { mapGetters } from 'vuex';
|
||||
import AgentTable from './components/overview/AgentTable.vue';
|
||||
import MetricCard from './components/overview/MetricCard.vue';
|
||||
import { OVERVIEW_METRICS } from './constants';
|
||||
|
||||
import endOfDay from 'date-fns/endOfDay';
|
||||
import getUnixTime from 'date-fns/getUnixTime';
|
||||
<script setup>
|
||||
import ReportHeader from './components/ReportHeader.vue';
|
||||
import HeatmapContainer from './components/HeatmapContainer.vue';
|
||||
export const FETCH_INTERVAL = 60000;
|
||||
|
||||
export default {
|
||||
name: 'LiveReports',
|
||||
components: {
|
||||
ReportHeader,
|
||||
AgentTable,
|
||||
MetricCard,
|
||||
HeatmapContainer,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
// always start with 0, this is to manage the pagination in tanstack table
|
||||
// when we send the data, we do a +1 to this value
|
||||
pageIndex: 0,
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
...mapGetters({
|
||||
agentStatus: 'agents/getAgentStatus',
|
||||
agents: 'agents/getAgents',
|
||||
accountConversationMetric: 'getAccountConversationMetric',
|
||||
agentConversationMetric: 'getAgentConversationMetric',
|
||||
uiFlags: 'getOverviewUIFlags',
|
||||
}),
|
||||
agentStatusMetrics() {
|
||||
let metric = {};
|
||||
Object.keys(this.agentStatus).forEach(key => {
|
||||
const metricName = this.$t(
|
||||
`OVERVIEW_REPORTS.AGENT_STATUS.${OVERVIEW_METRICS[key]}`
|
||||
);
|
||||
metric[metricName] = this.agentStatus[key];
|
||||
});
|
||||
return metric;
|
||||
},
|
||||
conversationMetrics() {
|
||||
let metric = {};
|
||||
Object.keys(this.accountConversationMetric).forEach(key => {
|
||||
const metricName = this.$t(
|
||||
`OVERVIEW_REPORTS.ACCOUNT_CONVERSATIONS.${OVERVIEW_METRICS[key]}`
|
||||
);
|
||||
metric[metricName] = this.accountConversationMetric[key];
|
||||
});
|
||||
return metric;
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
this.$store.dispatch('agents/get');
|
||||
this.initalizeReport();
|
||||
},
|
||||
beforeUnmount() {
|
||||
if (this.timeoutId) {
|
||||
clearTimeout(this.timeoutId);
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
initalizeReport() {
|
||||
this.fetchAllData();
|
||||
this.scheduleReportRefresh();
|
||||
},
|
||||
scheduleReportRefresh() {
|
||||
this.timeoutId = setTimeout(async () => {
|
||||
await this.fetchAllData();
|
||||
this.scheduleReportRefresh();
|
||||
}, FETCH_INTERVAL);
|
||||
},
|
||||
fetchAllData() {
|
||||
this.fetchAccountConversationMetric();
|
||||
this.fetchAgentConversationMetric();
|
||||
},
|
||||
downloadHeatmapData() {
|
||||
let to = endOfDay(new Date());
|
||||
|
||||
this.$store.dispatch('downloadAccountConversationHeatmap', {
|
||||
to: getUnixTime(to),
|
||||
});
|
||||
},
|
||||
|
||||
fetchAccountConversationMetric() {
|
||||
this.$store.dispatch('fetchAccountConversationMetric', {
|
||||
type: 'account',
|
||||
});
|
||||
},
|
||||
fetchAgentConversationMetric() {
|
||||
this.$store.dispatch('fetchAgentConversationMetric', {
|
||||
type: 'agent',
|
||||
page: this.pageIndex + 1,
|
||||
});
|
||||
},
|
||||
onPageNumberChange(pageIndex) {
|
||||
this.pageIndex = pageIndex;
|
||||
this.fetchAgentConversationMetric();
|
||||
},
|
||||
},
|
||||
};
|
||||
import AgentLiveReportContainer from './components/AgentLiveReportContainer.vue';
|
||||
import TeamLiveReportContainer from './components/TeamLiveReportContainer.vue';
|
||||
import StatsLiveReportsContainer from './components/StatsLiveReportsContainer.vue';
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ReportHeader :header-title="$t('OVERVIEW_REPORTS.HEADER')" />
|
||||
<div class="flex flex-col gap-4 pb-6">
|
||||
<div class="flex flex-col items-center md:flex-row gap-4">
|
||||
<div
|
||||
class="flex-1 w-full max-w-full md:w-[65%] md:max-w-[65%] conversation-metric"
|
||||
>
|
||||
<MetricCard
|
||||
:header="$t('OVERVIEW_REPORTS.ACCOUNT_CONVERSATIONS.HEADER')"
|
||||
:is-loading="uiFlags.isFetchingAccountConversationMetric"
|
||||
:loading-message="
|
||||
$t('OVERVIEW_REPORTS.ACCOUNT_CONVERSATIONS.LOADING_MESSAGE')
|
||||
"
|
||||
>
|
||||
<div
|
||||
v-for="(metric, name, index) in conversationMetrics"
|
||||
:key="index"
|
||||
class="flex-1 min-w-0 pb-2"
|
||||
>
|
||||
<h3 class="text-base text-n-slate-11">
|
||||
{{ name }}
|
||||
</h3>
|
||||
<p class="text-n-slate-12 text-3xl mb-0 mt-1">
|
||||
{{ metric }}
|
||||
</p>
|
||||
</div>
|
||||
</MetricCard>
|
||||
</div>
|
||||
<div class="flex-1 w-full max-w-full md:w-[35%] md:max-w-[35%]">
|
||||
<MetricCard :header="$t('OVERVIEW_REPORTS.AGENT_STATUS.HEADER')">
|
||||
<div
|
||||
v-for="(metric, name, index) in agentStatusMetrics"
|
||||
:key="index"
|
||||
class="flex-1 min-w-0 pb-2"
|
||||
>
|
||||
<h3 class="text-base text-n-slate-11">
|
||||
{{ name }}
|
||||
</h3>
|
||||
<p class="text-n-slate-12 text-3xl mb-0 mt-1">
|
||||
{{ metric }}
|
||||
</p>
|
||||
</div>
|
||||
</MetricCard>
|
||||
</div>
|
||||
</div>
|
||||
<StatsLiveReportsContainer />
|
||||
<HeatmapContainer />
|
||||
<div class="flex flex-row flex-wrap max-w-full">
|
||||
<MetricCard :header="$t('OVERVIEW_REPORTS.AGENT_CONVERSATIONS.HEADER')">
|
||||
<AgentTable
|
||||
:agents="agents"
|
||||
:agent-metrics="agentConversationMetric"
|
||||
:page-index="pageIndex"
|
||||
:is-loading="uiFlags.isFetchingAgentConversationMetric"
|
||||
@page-change="onPageNumberChange"
|
||||
/>
|
||||
</MetricCard>
|
||||
</div>
|
||||
<AgentLiveReportContainer />
|
||||
<TeamLiveReportContainer />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<script setup>
|
||||
import { onMounted } from 'vue';
|
||||
|
||||
import AgentTable from './overview/AgentTable.vue';
|
||||
import MetricCard from './overview/MetricCard.vue';
|
||||
import { useStore, useMapGetter } from 'dashboard/composables/store';
|
||||
import { useLiveRefresh } from 'dashboard/composables/useLiveRefresh';
|
||||
|
||||
const store = useStore();
|
||||
|
||||
const uiFlags = useMapGetter('getOverviewUIFlags');
|
||||
const agentConversationMetric = useMapGetter('getAgentConversationMetric');
|
||||
const agents = useMapGetter('agents/getAgents');
|
||||
|
||||
const fetchData = () => store.dispatch('fetchAgentConversationMetric');
|
||||
|
||||
const { startRefetching } = useLiveRefresh(fetchData);
|
||||
|
||||
onMounted(() => {
|
||||
store.dispatch('agents/get');
|
||||
fetchData();
|
||||
startRefetching();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-row flex-wrap max-w-full">
|
||||
<MetricCard :header="$t('OVERVIEW_REPORTS.AGENT_CONVERSATIONS.HEADER')">
|
||||
<AgentTable
|
||||
:agents="agents"
|
||||
:agent-metrics="agentConversationMetric"
|
||||
:is-loading="uiFlags.isFetchingAgentConversationMetric"
|
||||
/>
|
||||
</MetricCard>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,142 @@
|
||||
<script setup>
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
import { OVERVIEW_METRICS } from '../constants';
|
||||
import { useToggle } from '@vueuse/core';
|
||||
|
||||
import MetricCard from './overview/MetricCard.vue';
|
||||
import { useStore, useMapGetter } from 'dashboard/composables/store';
|
||||
import { useLiveRefresh } from 'dashboard/composables/useLiveRefresh';
|
||||
import DropdownMenu from 'dashboard/components-next/dropdown-menu/DropdownMenu.vue';
|
||||
import Button from 'dashboard/components-next/button/Button.vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
const { t } = useI18n();
|
||||
|
||||
const uiFlags = useMapGetter('getOverviewUIFlags');
|
||||
const agentStatus = useMapGetter('agents/getAgentStatus');
|
||||
const accountConversationMetric = useMapGetter('getAccountConversationMetric');
|
||||
const store = useStore();
|
||||
|
||||
const accounti18nKey = 'OVERVIEW_REPORTS.ACCOUNT_CONVERSATIONS';
|
||||
const teams = useMapGetter('teams/getTeams');
|
||||
|
||||
const teamMenuList = computed(() => {
|
||||
return [
|
||||
{ label: t('OVERVIEW_REPORTS.TEAM_CONVERSATIONS.ALL_TEAMS'), value: null },
|
||||
...teams.value.map(team => ({ label: team.name, value: team.id })),
|
||||
];
|
||||
});
|
||||
|
||||
const agentStatusMetrics = computed(() => {
|
||||
let metric = {};
|
||||
Object.keys(agentStatus.value).forEach(key => {
|
||||
const metricName = t(
|
||||
`OVERVIEW_REPORTS.AGENT_STATUS.${OVERVIEW_METRICS[key]}`
|
||||
);
|
||||
metric[metricName] = agentStatus.value[key];
|
||||
});
|
||||
return metric;
|
||||
});
|
||||
const conversationMetrics = computed(() => {
|
||||
let metric = {};
|
||||
Object.keys(accountConversationMetric.value).forEach(key => {
|
||||
const metricName = t(`${accounti18nKey}.${OVERVIEW_METRICS[key]}`);
|
||||
metric[metricName] = accountConversationMetric.value[key];
|
||||
});
|
||||
return metric;
|
||||
});
|
||||
|
||||
const selectedTeam = ref(null);
|
||||
const selectedTeamLabel = computed(() => {
|
||||
const team =
|
||||
teamMenuList.value.find(
|
||||
menuItem => menuItem.value === selectedTeam.value
|
||||
) || {};
|
||||
return team.label;
|
||||
});
|
||||
const fetchData = () => {
|
||||
const params = {};
|
||||
if (selectedTeam.value) {
|
||||
params.team_id = selectedTeam.value;
|
||||
}
|
||||
store.dispatch('fetchAccountConversationMetric', params);
|
||||
};
|
||||
|
||||
const { startRefetching } = useLiveRefresh(fetchData);
|
||||
const [showDropdown, toggleDropdown] = useToggle();
|
||||
|
||||
const handleAction = ({ value }) => {
|
||||
toggleDropdown(false);
|
||||
selectedTeam.value = value;
|
||||
fetchData();
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
fetchData();
|
||||
startRefetching();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col items-center md:flex-row gap-4">
|
||||
<div
|
||||
class="flex-1 w-full max-w-full md:w-[65%] md:max-w-[65%] conversation-metric"
|
||||
>
|
||||
<MetricCard
|
||||
:header="t(`${accounti18nKey}.HEADER`)"
|
||||
:is-loading="uiFlags.isFetchingAccountConversationMetric"
|
||||
:loading-message="t(`${accounti18nKey}.LOADING_MESSAGE`)"
|
||||
>
|
||||
<template v-if="teams.length" #control>
|
||||
<div
|
||||
v-on-clickaway="() => toggleDropdown(false)"
|
||||
class="relative flex items-center group z-50"
|
||||
>
|
||||
<Button
|
||||
sm
|
||||
slate
|
||||
faded
|
||||
:label="selectedTeamLabel"
|
||||
class="capitalize rounded-md group-hover:bg-n-alpha-2"
|
||||
@click="toggleDropdown()"
|
||||
/>
|
||||
<DropdownMenu
|
||||
v-if="showDropdown"
|
||||
:menu-items="teamMenuList"
|
||||
class="mt-1 ltr:right-0 rtl:left-0 xl:ltr:right-0 xl:rtl:left-0 top-full"
|
||||
label-class="capitalize"
|
||||
@action="handleAction($event)"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
<div
|
||||
v-for="(metric, name, index) in conversationMetrics"
|
||||
:key="index"
|
||||
class="flex-1 min-w-0 pb-2"
|
||||
>
|
||||
<h3 class="text-base text-n-slate-11">
|
||||
{{ name }}
|
||||
</h3>
|
||||
<p class="text-n-slate-12 text-3xl mb-0 mt-1">
|
||||
{{ metric }}
|
||||
</p>
|
||||
</div>
|
||||
</MetricCard>
|
||||
</div>
|
||||
<div class="flex-1 w-full max-w-full md:w-[35%] md:max-w-[35%]">
|
||||
<MetricCard :header="$t('OVERVIEW_REPORTS.AGENT_STATUS.HEADER')">
|
||||
<div
|
||||
v-for="(metric, name, index) in agentStatusMetrics"
|
||||
:key="index"
|
||||
class="flex-1 min-w-0 pb-2"
|
||||
>
|
||||
<h3 class="text-base text-n-slate-11">
|
||||
{{ name }}
|
||||
</h3>
|
||||
<p class="text-n-slate-12 text-3xl mb-0 mt-1">
|
||||
{{ metric }}
|
||||
</p>
|
||||
</div>
|
||||
</MetricCard>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,36 @@
|
||||
<script setup>
|
||||
import { onMounted } from 'vue';
|
||||
|
||||
import MetricCard from './overview/MetricCard.vue';
|
||||
import { useStore, useMapGetter } from 'dashboard/composables/store';
|
||||
import { useLiveRefresh } from 'dashboard/composables/useLiveRefresh';
|
||||
import TeamTable from './overview/TeamTable.vue';
|
||||
|
||||
const store = useStore();
|
||||
|
||||
const uiFlags = useMapGetter('getOverviewUIFlags');
|
||||
const teamConversationMetric = useMapGetter('getTeamConversationMetric');
|
||||
const teams = useMapGetter('teams/getTeams');
|
||||
|
||||
const fetchData = () => store.dispatch('fetchTeamConversationMetric');
|
||||
|
||||
const { startRefetching } = useLiveRefresh(fetchData);
|
||||
|
||||
onMounted(() => {
|
||||
store.dispatch('teams/get');
|
||||
fetchData();
|
||||
startRefetching();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-row flex-wrap max-w-full">
|
||||
<MetricCard :header="$t('OVERVIEW_REPORTS.TEAM_CONVERSATIONS.HEADER')">
|
||||
<TeamTable
|
||||
:teams="teams"
|
||||
:team-metrics="teamConversationMetric"
|
||||
:is-loading="uiFlags.isFetchingTeamConversationMetric"
|
||||
/>
|
||||
</MetricCard>
|
||||
</div>
|
||||
</template>
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
useVueTable,
|
||||
createColumnHelper,
|
||||
getCoreRowModel,
|
||||
getPaginationRowModel,
|
||||
} from '@tanstack/vue-table';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
@@ -13,7 +14,7 @@ import Table from 'dashboard/components/table/Table.vue';
|
||||
import Pagination from 'dashboard/components/table/Pagination.vue';
|
||||
import AgentCell from './AgentCell.vue';
|
||||
|
||||
const { agents, agentMetrics, pageIndex } = defineProps({
|
||||
const { agents, agentMetrics } = defineProps({
|
||||
agents: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
@@ -26,42 +27,45 @@ const { agents, agentMetrics, pageIndex } = defineProps({
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
pageIndex: {
|
||||
type: Number,
|
||||
default: 1,
|
||||
},
|
||||
});
|
||||
|
||||
const emit = defineEmits(['pageChange']);
|
||||
const { t } = useI18n();
|
||||
|
||||
function getAgentInformation(id) {
|
||||
return agents?.find(agent => agent.id === Number(id));
|
||||
}
|
||||
const getAgentMetrics = id =>
|
||||
agentMetrics.find(metrics => metrics.assignee_id === Number(id)) || {};
|
||||
|
||||
const totalCount = computed(() => agents.length);
|
||||
|
||||
const tableData = computed(() => {
|
||||
return agentMetrics
|
||||
.filter(agentMetric => getAgentInformation(agentMetric.id))
|
||||
const tableData = computed(() =>
|
||||
agents
|
||||
.map(agent => {
|
||||
const agentInformation = getAgentInformation(agent.id);
|
||||
const metric = getAgentMetrics(agent.id);
|
||||
return {
|
||||
agent: agentInformation.name || agentInformation.available_name,
|
||||
email: agentInformation.email,
|
||||
thumbnail: agentInformation.thumbnail,
|
||||
open: agent.metric.open ?? 0,
|
||||
unattended: agent.metric.unattended ?? 0,
|
||||
status: agentInformation.availability_status,
|
||||
agent: agent.available_name || agent.name,
|
||||
email: agent.email,
|
||||
thumbnail: agent.thumbnail,
|
||||
open: metric.open || 0,
|
||||
unattended: metric.unattended || 0,
|
||||
status: agent.availability_status,
|
||||
};
|
||||
});
|
||||
});
|
||||
})
|
||||
.sort((a, b) => {
|
||||
// First sort by open tickets (descending)
|
||||
const openDiff = b.open - a.open;
|
||||
// If open tickets are equal, sort by name (ascending)
|
||||
if (openDiff === 0) {
|
||||
return a.agent.localeCompare(b.agent);
|
||||
}
|
||||
return openDiff;
|
||||
})
|
||||
);
|
||||
|
||||
const defaulSpanRender = cellProps =>
|
||||
h(
|
||||
'span',
|
||||
|
||||
{
|
||||
class: cellProps.getValue() ? '' : 'text-slate-300 dark:text-slate-700',
|
||||
class: cellProps.getValue()
|
||||
? 'capitalize text-n-slate-12'
|
||||
: 'capitalize text-n-slate-11',
|
||||
},
|
||||
cellProps.getValue() ? cellProps.getValue() : '---'
|
||||
);
|
||||
@@ -86,100 +90,33 @@ const columns = [
|
||||
}),
|
||||
];
|
||||
|
||||
const paginationParams = computed(() => {
|
||||
return {
|
||||
pageIndex: pageIndex,
|
||||
pageSize: 25,
|
||||
};
|
||||
});
|
||||
|
||||
const table = useVueTable({
|
||||
get data() {
|
||||
return tableData.value;
|
||||
},
|
||||
columns,
|
||||
manualPagination: true,
|
||||
enableSorting: false,
|
||||
getCoreRowModel: getCoreRowModel(),
|
||||
get rowCount() {
|
||||
return totalCount.value;
|
||||
},
|
||||
state: {
|
||||
get pagination() {
|
||||
return paginationParams.value;
|
||||
},
|
||||
},
|
||||
onPaginationChange: updater => {
|
||||
const newPagintaion = updater(paginationParams.value);
|
||||
emit('pageChange', newPagintaion.pageIndex);
|
||||
},
|
||||
getPaginationRowModel: getPaginationRowModel(),
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="agent-table-container">
|
||||
<div class="flex flex-col flex-1">
|
||||
<Table :table="table" class="max-h-[calc(100vh-21.875rem)]" />
|
||||
<Pagination class="mt-2" :table="table" />
|
||||
<div v-if="isLoading" class="agents-loader">
|
||||
<div
|
||||
v-if="isLoading"
|
||||
class="items-center flex text-base justify-center p-8"
|
||||
>
|
||||
<Spinner />
|
||||
<span>{{
|
||||
$t('OVERVIEW_REPORTS.AGENT_CONVERSATIONS.LOADING_MESSAGE')
|
||||
}}</span>
|
||||
<span>
|
||||
{{ $t('OVERVIEW_REPORTS.AGENT_CONVERSATIONS.LOADING_MESSAGE') }}
|
||||
</span>
|
||||
</div>
|
||||
<EmptyState
|
||||
v-else-if="!isLoading && !agentMetrics.length"
|
||||
v-else-if="!isLoading && !agents.length"
|
||||
:title="$t('OVERVIEW_REPORTS.AGENT_CONVERSATIONS.NO_AGENTS')"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.agent-table-container {
|
||||
@apply flex flex-col flex-1;
|
||||
|
||||
.ve-table {
|
||||
&::v-deep {
|
||||
th.ve-table-header-th {
|
||||
@apply text-sm rounded-xl;
|
||||
padding: var(--space-small) var(--space-two) !important;
|
||||
}
|
||||
|
||||
td.ve-table-body-td {
|
||||
padding: var(--space-one) var(--space-two) !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&::v-deep .ve-pagination {
|
||||
@apply bg-transparent dark:bg-transparent;
|
||||
}
|
||||
|
||||
&::v-deep .ve-pagination-select {
|
||||
@apply hidden;
|
||||
}
|
||||
|
||||
.row-user-block {
|
||||
@apply items-center flex text-left;
|
||||
|
||||
.user-block {
|
||||
@apply items-start flex flex-col min-w-0 my-0 mx-2;
|
||||
|
||||
.title {
|
||||
@apply text-sm m-0 leading-[1.2] text-slate-800 dark:text-slate-100;
|
||||
}
|
||||
|
||||
.sub-title {
|
||||
@apply text-xs text-slate-600 dark:text-slate-200;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.table-pagination {
|
||||
@apply mt-4 text-right;
|
||||
}
|
||||
}
|
||||
|
||||
.agents-loader {
|
||||
@apply items-center flex text-base justify-center p-8;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -19,7 +19,7 @@ defineProps({
|
||||
|
||||
<template>
|
||||
<div
|
||||
class="flex flex-col m-0.5 px-6 py-5 overflow-hidden rounded-xl flex-grow text-n-slate-12 shadow outline-1 outline outline-n-container bg-n-solid-2 min-h-[10rem]"
|
||||
class="flex flex-col m-0.5 px-6 py-5 rounded-xl flex-grow text-n-slate-12 shadow outline-1 outline outline-n-container bg-n-solid-2 min-h-[10rem]"
|
||||
>
|
||||
<div
|
||||
class="card-header grid w-full mb-6 grid-cols-[repeat(auto-fit,minmax(max-content,50%))] gap-y-2"
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
<script setup>
|
||||
import { computed, h } from 'vue';
|
||||
import {
|
||||
useVueTable,
|
||||
createColumnHelper,
|
||||
getCoreRowModel,
|
||||
getPaginationRowModel,
|
||||
} from '@tanstack/vue-table';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
import Spinner from 'shared/components/Spinner.vue';
|
||||
import EmptyState from 'dashboard/components/widgets/EmptyState.vue';
|
||||
import Table from 'dashboard/components/table/Table.vue';
|
||||
import Pagination from 'dashboard/components/table/Pagination.vue';
|
||||
|
||||
const { teams, teamMetrics } = defineProps({
|
||||
teams: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
teamMetrics: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
isLoading: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
});
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const getTeamMetrics = id =>
|
||||
teamMetrics.find(metrics => metrics.team_id === Number(id)) || {};
|
||||
|
||||
const tableData = computed(() =>
|
||||
teams
|
||||
.map(team => {
|
||||
const metric = getTeamMetrics(team.id);
|
||||
return {
|
||||
agent: team.name,
|
||||
open: metric.open || 0,
|
||||
unattended: metric.unattended || 0,
|
||||
};
|
||||
})
|
||||
.sort((a, b) => {
|
||||
// First sort by open tickets (descending)
|
||||
const openDiff = b.open - a.open;
|
||||
// If open tickets are equal, sort by name (ascending)
|
||||
if (openDiff === 0) {
|
||||
return a.agent.localeCompare(b.agent);
|
||||
}
|
||||
return openDiff;
|
||||
})
|
||||
);
|
||||
|
||||
const defaulSpanRender = cellProps =>
|
||||
h(
|
||||
'span',
|
||||
{
|
||||
class: cellProps.getValue()
|
||||
? 'capitalize text-n-slate-12'
|
||||
: 'capitalize text-n-slate-11',
|
||||
},
|
||||
cellProps.getValue() ? cellProps.getValue() : '---'
|
||||
);
|
||||
|
||||
const columnHelper = createColumnHelper();
|
||||
const columns = [
|
||||
columnHelper.accessor('agent', {
|
||||
header: t('OVERVIEW_REPORTS.TEAM_CONVERSATIONS.TABLE_HEADER.TEAM'),
|
||||
cell: defaulSpanRender,
|
||||
size: 250,
|
||||
}),
|
||||
columnHelper.accessor('open', {
|
||||
header: t('OVERVIEW_REPORTS.TEAM_CONVERSATIONS.TABLE_HEADER.OPEN'),
|
||||
cell: defaulSpanRender,
|
||||
size: 100,
|
||||
}),
|
||||
columnHelper.accessor('unattended', {
|
||||
header: t('OVERVIEW_REPORTS.TEAM_CONVERSATIONS.TABLE_HEADER.UNATTENDED'),
|
||||
cell: defaulSpanRender,
|
||||
size: 100,
|
||||
}),
|
||||
];
|
||||
|
||||
const table = useVueTable({
|
||||
get data() {
|
||||
return tableData.value;
|
||||
},
|
||||
columns,
|
||||
enableSorting: false,
|
||||
getCoreRowModel: getCoreRowModel(),
|
||||
getPaginationRowModel: getPaginationRowModel(),
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col flex-1">
|
||||
<Table :table="table" class="max-h-[calc(100vh-21.875rem)]" />
|
||||
<Pagination class="mt-2" :table="table" />
|
||||
<div
|
||||
v-if="isLoading"
|
||||
class="items-center flex text-base justify-center p-8"
|
||||
>
|
||||
<Spinner />
|
||||
<span>
|
||||
{{ $t('OVERVIEW_REPORTS.TEAM_CONVERSATIONS.LOADING_MESSAGE') }}
|
||||
</span>
|
||||
</div>
|
||||
<EmptyState
|
||||
v-else-if="!isLoading && !teams.length"
|
||||
:title="$t('OVERVIEW_REPORTS.TEAM_CONVERSATIONS.NO_TEAMS')"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
Reference in New Issue
Block a user