|
13 | 13 | </div> |
14 | 14 | </template> |
15 | 15 |
|
16 | | -<script lang="ts"> |
17 | | -// @ts-nocheck TODO(tabiodun): Fix this file |
| 16 | +<script lang="ts" setup> |
| 17 | +import { computed, watch, onBeforeUnmount, ref, onMounted } from 'vue'; |
18 | 18 | import { mapActions, mapGetters, mapMutations } from 'vuex'; |
19 | | -import { defineComponent } from '@vue/composition-api'; |
| 19 | +import { useRoute } from 'vue-router'; |
| 20 | +import { useI18n } from 'vue-i18n'; |
20 | 21 | import CCP from '@/components/phone/CCP.vue'; |
21 | | -import Version from '@/components/Version.vue'; |
22 | 22 | import BannerOverlay from '@/components/notifications/BannerOverlay.vue'; |
23 | 23 | import { cachedGet, hash } from '@/utils/promise'; |
24 | | -import PhoneLegacy from './pages/phone_legacy/Index.vue'; |
| 24 | +import useHttp from '@/use/useHttp'; |
25 | 25 |
|
| 26 | +const { t: $t } = useI18n(); |
| 27 | +const route = useRoute(); |
26 | 28 | const defaultLayout = 'authenticated'; |
27 | | -export default defineComponent({ |
28 | | - name: 'App', |
29 | | - components: { PhoneLegacy, CCP, Version, BannerOverlay }, |
30 | | - computed: { |
31 | | - ...mapGetters('ui', ['currentBanner']), |
32 | | - layout() { |
33 | | - return `${this.$route.meta?.layout || defaultLayout}-layout`; |
34 | | - }, |
35 | | - }, |
36 | | - watch: { |
37 | | - $route: { |
38 | | - immediate: true, |
39 | | - handler(to) { |
40 | | - const newTitle = `${this.$t(to.name)}: Crisis Cleanup`; |
41 | | - if (document.title !== newTitle) { |
42 | | - document.title = newTitle; |
43 | | - } |
44 | | - }, |
45 | | - }, |
46 | | - }, |
47 | | - created(): void { |
48 | | - if (process.env.NODE_ENV === 'development') { |
49 | | - this.eventsInterval = setInterval(this.pushCurrentEvents, 2000); |
50 | | - } |
51 | | - this.$http.interceptors.request.use(function (config) { |
52 | | - config.headers.CCU_WEB_URL = window.location.href; |
53 | | - config.headers.CCU_PORTAL_KEY = process.env.VUE_APP_PORTAL_KEY; |
54 | | - return config; |
55 | | - }); |
56 | | - }, |
57 | | - beforeDestroy(): void { |
58 | | - if (this.eventsInterval) { |
59 | | - clearInterval(this.eventsInterval); |
60 | | - this.eventsInterval = undefined; |
| 29 | +// const $t = (s: any) => s; |
| 30 | +const { $http } = useHttp(); |
| 31 | +
|
| 32 | +const eventsInterval = ref<any>(null); |
| 33 | +const layout = computed(() => `${route.meta?.layout || defaultLayout}-layout`); |
| 34 | +const currentBanner = computed(() => { |
| 35 | + const { currentBanner: _currentBanner } = mapGetters('ui', ['currentBanner']); |
| 36 | + return _currentBanner; |
| 37 | +}); |
| 38 | +
|
| 39 | +const { login, logout } = mapActions('auth', ['login', 'logout']); |
| 40 | +const { pushEvents } = mapActions('events', ['pushEvents']); |
| 41 | +const { validateBrowser } = mapActions('ui', ['validateBrowser']); |
| 42 | +const { isLoggedIn } = mapGetters('auth', ['isLoggedIn']); |
| 43 | +const { setStatuses, setWorkTypes, setLocationTypes, setPhases, setPortal } = |
| 44 | + mapMutations('enums', [ |
| 45 | + 'setStatuses', |
| 46 | + 'setWorkTypes', |
| 47 | + 'setLocationTypes', |
| 48 | + 'setPhases', |
| 49 | + 'setPortal', |
| 50 | + ]); |
| 51 | +
|
| 52 | +watch( |
| 53 | + () => route, |
| 54 | + (to) => { |
| 55 | + const newTitle = `${$t(to.name)}: Crisis Cleanup`; |
| 56 | + if (document.title !== newTitle) { |
| 57 | + document.title = newTitle; |
61 | 58 | } |
62 | 59 | }, |
63 | | - methods: { |
64 | | - ...mapActions('auth', ['login', 'logout']), |
65 | | - ...mapActions('events', ['pushEvents']), |
66 | | - ...mapActions('ui', ['validateBrowser']), |
67 | | - ...mapGetters('auth', ['isLoggedIn']), |
68 | | - ...mapMutations('enums', [ |
69 | | - 'setStatuses', |
70 | | - 'setWorkTypes', |
71 | | - 'setLocationTypes', |
72 | | - 'setPhases', |
73 | | - 'setPortal', |
74 | | - ]), |
75 | | - async getEnums(): Promise<void> { |
76 | | - const enums = await hash({ |
77 | | - statuses: cachedGet( |
78 | | - `${process.env.VUE_APP_API_BASE_URL}/statuses`, |
79 | | - { |
80 | | - headers: { |
81 | | - Authorization: null, |
82 | | - }, |
83 | | - }, |
84 | | - 'statuses', |
85 | | - ), |
86 | | - workTypes: cachedGet( |
87 | | - `${process.env.VUE_APP_API_BASE_URL}/work_types`, |
88 | | - { |
89 | | - headers: { |
90 | | - Authorization: null, |
91 | | - }, |
92 | | - }, |
93 | | - 'work_types', |
94 | | - ), |
95 | | - phases: cachedGet( |
96 | | - `${process.env.VUE_APP_API_BASE_URL}/incidents_phases`, |
97 | | - { |
98 | | - headers: { |
99 | | - Authorization: null, |
100 | | - }, |
101 | | - }, |
102 | | - 'incidents_phases', |
103 | | - ), |
104 | | - locationTypes: cachedGet( |
105 | | - `${process.env.VUE_APP_API_BASE_URL}/location_types`, |
106 | | - { |
107 | | - headers: { |
108 | | - Authorization: null, |
109 | | - }, |
110 | | - }, |
111 | | - 'location_types', |
112 | | - ), |
113 | | - portal: cachedGet( |
114 | | - `${process.env.VUE_APP_API_BASE_URL}/portals/current`, |
115 | | - { |
116 | | - headers: { |
117 | | - Authorization: null, |
118 | | - }, |
119 | | - }, |
120 | | - 'portal', |
121 | | - ), |
122 | | - }); |
123 | | - this.setStatuses(enums.statuses.data.results); |
124 | | - this.setWorkTypes(enums.workTypes.data.results); |
125 | | - this.setLocationTypes(enums.locationTypes.data.results); |
126 | | - this.setPhases(enums.phases.data.results); |
127 | | - this.setPortal(enums.portal.data); |
128 | | - }, |
129 | | - async pushCurrentEvents(): Promise<void> { |
130 | | - if (this.isLoggedIn()) { |
131 | | - await this.pushEvents(); |
132 | | - } |
133 | | - }, |
134 | | - }, |
135 | | - async mounted(): Promise<void> { |
136 | | - await this.validateBrowser(); |
137 | | - await this.getEnums(); |
138 | | - }, |
139 | | - data(): any { |
140 | | - return { |
141 | | - eventsInterval: null as any, |
142 | | - }; |
143 | | - }, |
| 60 | + { immediate: true }, |
| 61 | +); |
| 62 | +
|
| 63 | +async function getEnums(): Promise<void> { |
| 64 | + const enums = await hash({ |
| 65 | + statuses: cachedGet( |
| 66 | + `${process.env.VUE_APP_API_BASE_URL}/statuses`, |
| 67 | + { |
| 68 | + headers: { |
| 69 | + Authorization: null, |
| 70 | + }, |
| 71 | + }, |
| 72 | + 'statuses', |
| 73 | + ), |
| 74 | + workTypes: cachedGet( |
| 75 | + `${process.env.VUE_APP_API_BASE_URL}/work_types`, |
| 76 | + { |
| 77 | + headers: { |
| 78 | + Authorization: null, |
| 79 | + }, |
| 80 | + }, |
| 81 | + 'work_types', |
| 82 | + ), |
| 83 | + phases: cachedGet( |
| 84 | + `${process.env.VUE_APP_API_BASE_URL}/incidents_phases`, |
| 85 | + { |
| 86 | + headers: { |
| 87 | + Authorization: null, |
| 88 | + }, |
| 89 | + }, |
| 90 | + 'incidents_phases', |
| 91 | + ), |
| 92 | + locationTypes: cachedGet( |
| 93 | + `${process.env.VUE_APP_API_BASE_URL}/location_types`, |
| 94 | + { |
| 95 | + headers: { |
| 96 | + Authorization: null, |
| 97 | + }, |
| 98 | + }, |
| 99 | + 'location_types', |
| 100 | + ), |
| 101 | + portal: cachedGet( |
| 102 | + `${process.env.VUE_APP_API_BASE_URL}/portals/current`, |
| 103 | + { |
| 104 | + headers: { |
| 105 | + Authorization: null, |
| 106 | + }, |
| 107 | + }, |
| 108 | + 'portal', |
| 109 | + ), |
| 110 | + }); |
| 111 | + setStatuses(enums.statuses.data.results); |
| 112 | + setWorkTypes(enums.workTypes.data.results); |
| 113 | + setLocationTypes(enums.locationTypes.data.results); |
| 114 | + setPhases(enums.phases.data.results); |
| 115 | + setPortal(enums.portal.data); |
| 116 | +} |
| 117 | +
|
| 118 | +async function pushCurrentEvents(): Promise<void> { |
| 119 | + if (isLoggedIn()) { |
| 120 | + await pushEvents(); |
| 121 | + } |
| 122 | +} |
| 123 | +
|
| 124 | +if (process.env.NODE_ENV === 'development') { |
| 125 | + eventsInterval.value = setInterval(pushCurrentEvents, 2000); |
| 126 | +} |
| 127 | +$http.interceptors.request.use(function (config) { |
| 128 | + config.headers.CCU_WEB_URL = window.location.href; |
| 129 | + config.headers.CCU_PORTAL_KEY = process.env.VUE_APP_PORTAL_KEY; |
| 130 | + return config; |
| 131 | +}); |
| 132 | +
|
| 133 | +onMounted(async () => { |
| 134 | + await validateBrowser(); |
| 135 | + await getEnums(); |
| 136 | +}); |
| 137 | +
|
| 138 | +onBeforeUnmount(() => { |
| 139 | + if (eventsInterval.value) { |
| 140 | + clearInterval(eventsInterval.value); |
| 141 | + eventsInterval.value = undefined; |
| 142 | + } |
144 | 143 | }); |
145 | 144 | </script> |
146 | 145 | <style> |
147 | | -@import '~vue-resize/dist/vue-resize.css'; |
148 | | -@import '~vue-phone-number-input/dist/vue-phone-number-input.css'; |
| 146 | +@import 'vue-resize/dist/vue-resize.css'; |
| 147 | +@import 'vue-phone-number-input/dist/vue-phone-number-input.css'; |
149 | 148 | @lost flexbox flex; |
150 | 149 |
|
151 | 150 | html { |
|
0 commit comments