|
1 | 1 | <template> |
2 | | - <PageTabBar v-if="bugReportsData && ticketCountData" :tabs="tabs" /> |
| 2 | + <PageTabBar |
| 3 | + v-if="bugReportsData && ticketCountData" |
| 4 | + :tabs="tabs" |
| 5 | + @on-total-dashboard-count-fetched="handleTotalDashboardCountFetched" |
| 6 | + /> |
3 | 7 | </template> |
4 | 8 |
|
5 | | -<script lang="ts"> |
6 | | -import { reactive, ref, watch, onMounted } from 'vue'; |
| 9 | +<script setup lang="ts"> |
7 | 10 | import PageTabBar from '../../layouts/page/PageTabBar.vue'; |
8 | 11 | import useAcl from '@/hooks/useAcl'; |
9 | 12 | import type { Tab } from '@/hooks/useTabs'; |
10 | 13 | import { useCurrentUser } from '@/hooks'; |
| 14 | +import moment from 'moment'; |
11 | 15 |
|
12 | | -export default defineComponent({ |
13 | | - name: 'AdminPage', |
14 | | - components: { PageTabBar }, |
15 | | - setup() { |
16 | | - const tabs = reactive<Tab[]>([ |
17 | | - { |
18 | | - key: 'nav.admin_dashboard', |
19 | | - }, |
20 | | - // reactive({ |
21 | | - // key: 'nav.admin_events', |
22 | | - // }), |
23 | | - { |
24 | | - key: 'nav.admin_event_stream', |
25 | | - }, |
26 | | - { |
27 | | - key: 'nav.admin_tickets', |
28 | | - }, |
29 | | - { |
30 | | - key: 'nav.bugs', |
31 | | - }, |
32 | | - { |
33 | | - key: 'nav.cms', |
34 | | - }, |
35 | | - { |
36 | | - key: 'nav.incident_wizard', |
37 | | - }, |
38 | | - { |
39 | | - key: 'nav.localizations', |
40 | | - }, |
41 | | - { |
42 | | - key: 'nav.rag', |
43 | | - }, |
44 | | - { |
45 | | - key: 'nav.reports', |
46 | | - }, |
47 | | - ]); |
48 | | -
|
49 | | - const ccuApi = useApi(); |
50 | | - const { $can } = useAcl(); |
| 16 | +const tabs = reactive<Tab[]>([ |
| 17 | + { |
| 18 | + key: 'nav.admin_dashboard', |
| 19 | + }, |
| 20 | + { |
| 21 | + key: 'nav.admin_event_stream', |
| 22 | + }, |
| 23 | + { |
| 24 | + key: 'nav.admin_tickets', |
| 25 | + }, |
| 26 | + { |
| 27 | + key: 'nav.bugs', |
| 28 | + }, |
| 29 | + { |
| 30 | + key: 'nav.cms', |
| 31 | + }, |
| 32 | + { |
| 33 | + key: 'nav.incident_wizard', |
| 34 | + }, |
| 35 | + { |
| 36 | + key: 'nav.localizations', |
| 37 | + }, |
| 38 | + { |
| 39 | + key: 'nav.rag', |
| 40 | + }, |
| 41 | + { |
| 42 | + key: 'nav.reports', |
| 43 | + }, |
| 44 | +]); |
51 | 45 |
|
52 | | - const bugReportsData = ref({ count: 0 }); |
53 | | - const ticketCountData = ref({ count: 0 }); |
54 | | - const { currentUser } = useCurrentUser(); |
55 | | - const router = useRouter(); |
| 46 | +const ccuApi = useApi(); |
| 47 | +const { $can } = useAcl(); |
56 | 48 |
|
57 | | - onMounted(async () => { |
58 | | - if (!currentUser.value?.isAdmin) { |
59 | | - return router.push('/dashboard'); |
60 | | - } |
61 | | - if (!$can('development_mode')) { |
62 | | - const bugsData = await ccuApi('/bug_reports', { |
63 | | - method: 'GET', |
64 | | - }); |
65 | | - if (bugsData.data) { |
66 | | - bugReportsData.value = bugsData.data; |
67 | | - } |
| 49 | +const bugReportsData = ref({ count: 0 }); |
| 50 | +const ticketCountData = ref({ count: 0 }); |
| 51 | +const totalDashboardCount = ref(0); |
| 52 | +const { currentUser } = useCurrentUser(); |
| 53 | +const router = useRouter(); |
68 | 54 |
|
69 | | - const ticketsData = await ccuApi( |
70 | | - 'zendesk/search/count.json?query=type:ticket status<solved', |
71 | | - { |
72 | | - method: 'GET', |
73 | | - }, |
74 | | - ); |
75 | | - if (bugsData.data) { |
76 | | - bugsData.value = ticketsData.data; |
77 | | - } |
78 | | - } |
| 55 | +onMounted(async () => { |
| 56 | + if (!currentUser.value?.isAdmin) { |
| 57 | + return router.push('/dashboard'); |
| 58 | + } |
| 59 | + if (!$can('development_mode')) { |
| 60 | + const bugsData = await ccuApi('/bug_reports', { |
| 61 | + method: 'GET', |
| 62 | + params: { |
| 63 | + created_at__gte: moment().subtract(60, 'day').format('YYYY-MM-DD'), |
| 64 | + }, |
79 | 65 | }); |
| 66 | + if (bugsData.data) { |
| 67 | + bugReportsData.value = bugsData.data; |
| 68 | + } |
80 | 69 |
|
81 | | - watch(bugReportsData, () => { |
82 | | - const bugsTab = tabs.find((tab) => tab.key === 'nav.bugs'); |
83 | | - bugsTab.title = `Bugs (${bugReportsData.value.count})`; |
84 | | - }); |
| 70 | + const ticketsData = await ccuApi( |
| 71 | + 'zendesk/search/count.json?query=type:ticket status<solved', |
| 72 | + { |
| 73 | + method: 'GET', |
| 74 | + }, |
| 75 | + ); |
| 76 | + if (ticketsData.data) { |
| 77 | + ticketCountData.value = ticketsData.data; |
| 78 | + } |
| 79 | + } |
| 80 | +}); |
85 | 81 |
|
86 | | - watch(ticketCountData, () => { |
87 | | - const ticketTab = tabs.find((tab) => tab.key === 'nav.admin_tickets'); |
88 | | - ticketTab.title = `Tickets (${ticketCountData.value.count})`; |
89 | | - }); |
| 82 | +function handleTotalDashboardCountFetched(count: number) { |
| 83 | + totalDashboardCount.value = count; |
| 84 | + console.log('totalDashboardCount', totalDashboardCount.value); |
| 85 | +} |
90 | 86 |
|
91 | | - return { |
92 | | - tabs, |
93 | | - bugReportsData, |
94 | | - ticketCountData, |
95 | | - }; |
96 | | - }, |
| 87 | +watch(bugReportsData, () => { |
| 88 | + const bugsTab = tabs.find((tab: Tab) => tab.key === 'nav.bugs'); |
| 89 | + if (bugsTab) { |
| 90 | + bugsTab.title = `Bugs (${bugReportsData.value.count})`; |
| 91 | + } |
| 92 | +}); |
| 93 | +
|
| 94 | +watch(ticketCountData, () => { |
| 95 | + const ticketTab = tabs.find((tab: Tab) => tab.key === 'nav.admin_tickets'); |
| 96 | + if (ticketTab) { |
| 97 | + ticketTab.title = `Tickets (${ticketCountData.value.count})`; |
| 98 | + } |
| 99 | +}); |
| 100 | +
|
| 101 | +watch(totalDashboardCount, () => { |
| 102 | + const dashboardTab = tabs.find( |
| 103 | + (tab: Tab) => tab.key === 'nav.admin_dashboard', |
| 104 | + ); |
| 105 | + if (dashboardTab) { |
| 106 | + dashboardTab.title = `Dashboard (${totalDashboardCount.value})`; |
| 107 | + } |
97 | 108 | }); |
98 | 109 | </script> |
99 | 110 |
|
|
0 commit comments