AppDesktop.vue 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { onBeforeMount, onBeforeUnmount } from 'vue'
  4. import { useRouter } from 'vue-router'
  5. import CommonNotifications from '#shared/components/CommonNotifications/CommonNotifications.vue'
  6. import DynamicInitializer from '#shared/components/DynamicInitializer/DynamicInitializer.vue'
  7. import useAuthenticationChanges from '#shared/composables/authentication/useAuthenticationUpdates.ts'
  8. import useFormKitConfig from '#shared/composables/form/useFormKitConfig.ts'
  9. import useAppMaintenanceCheck from '#shared/composables/useAppMaintenanceCheck.ts'
  10. import useMetaTitle from '#shared/composables/useMetaTitle.ts'
  11. import usePushMessages from '#shared/composables/usePushMessages.ts'
  12. import { useApplicationStore } from '#shared/stores/application.ts'
  13. import { useAuthenticationStore } from '#shared/stores/authentication.ts'
  14. import { useLocaleStore } from '#shared/stores/locale.ts'
  15. import emitter from '#shared/utils/emitter.ts'
  16. import { initializeConfirmationDialog } from '#desktop/components/CommonConfirmationDialog/initializeConfirmationDialog.ts'
  17. const router = useRouter()
  18. const authentication = useAuthenticationStore()
  19. useMetaTitle().initializeMetaTitle()
  20. const application = useApplicationStore()
  21. onBeforeMount(() => {
  22. application.setLoaded()
  23. })
  24. useAppMaintenanceCheck()
  25. usePushMessages()
  26. // Add a check for authenticated changes (e.g. login/logout in a other
  27. // browser tab or maintenance mode switch).
  28. useAuthenticationChanges()
  29. // We need to trigger a manual translation update for the form related strings.
  30. const formConfig = useFormKitConfig()
  31. useLocaleStore().$subscribe(() => {
  32. formConfig.locale = 'staticLocale'
  33. })
  34. // The handling for invalid sessions. The event will be emitted, when from the server a "NotAuthorized"
  35. // response is received.
  36. emitter.on('sessionInvalid', async () => {
  37. if (authentication.authenticated) {
  38. await authentication.clearAuthentication()
  39. router.replace({
  40. name: 'Login',
  41. query: {
  42. invalidatedSession: '1',
  43. },
  44. })
  45. }
  46. })
  47. initializeConfirmationDialog()
  48. // Initialize the ticket overview store after a valid session is present on
  49. // the app level, so that the query keeps alive.
  50. // watch(
  51. // () => session.initialized,
  52. // (newValue, oldValue) => {
  53. // if (!oldValue && newValue) {
  54. // useTicketOverviewsStore()
  55. // }
  56. // },
  57. // { immediate: true },
  58. // )
  59. const transition = VITE_TEST_MODE
  60. ? undefined
  61. : {
  62. enterActiveClass: 'duration-300 ease-out',
  63. enterFromClass: 'opacity-0 rtl:-translate-x-3/4 ltr:translate-x-3/4',
  64. enterToClass: 'opacity-100 rtl:-translate-x-0 ltr:translate-x-0',
  65. leaveActiveClass: 'duration-200 ease-in',
  66. leaveFromClass: 'opacity-100 rtl:-translate-x-0 ltr:translate-x-0',
  67. leaveToClass: 'opacity-0 rtl:-translate-x-3/4 ltr:translate-x-3/4',
  68. }
  69. onBeforeUnmount(() => {
  70. emitter.off('sessionInvalid')
  71. })
  72. </script>
  73. <template>
  74. <template v-if="application.loaded">
  75. <CommonNotifications />
  76. <RouterView />
  77. </template>
  78. <DynamicInitializer name="dialog" :transition="transition" />
  79. <DynamicInitializer name="flyout" :transition="transition" />
  80. </template>