App.vue 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <!-- Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { onBeforeUnmount, onMounted } from 'vue'
  4. import { useRouter } from 'vue-router'
  5. import CommonNotifications from '@shared/components/CommonNotifications/CommonNotifications.vue'
  6. import { useApplicationStore } from '@shared/stores/application'
  7. import { useAuthenticationStore } from '@shared/stores/authentication'
  8. import useMetaTitle from '@shared/composables/useMetaTitle'
  9. import emitter from '@shared/utils/emitter'
  10. import useAppMaintenanceCheck from '@shared/composables/useAppMaintenanceCheck'
  11. import usePushMessages from '@shared/composables/usePushMessages'
  12. import { useLocaleStore } from '@shared/stores/locale'
  13. import useFormKitConfig from '@shared/composables/form/useFormKitConfig'
  14. import { useAppTheme } from '@shared/composables/useAppTheme'
  15. import useAuthenticationChanges from '@shared/composables/useAuthenticationUpdates'
  16. import DynamicInitializer from '@shared/components/DynamicInitializer/DynamicInitializer.vue'
  17. import CommonConfirmation from '@mobile/components/CommonConfirmation/CommonConfirmation.vue'
  18. import CommonImageViewer from '@shared/components/CommonImageViewer/CommonImageViewer.vue'
  19. const router = useRouter()
  20. const authentication = useAuthenticationStore()
  21. useMetaTitle().initializeMetaTitle()
  22. const application = useApplicationStore()
  23. onMounted(() => {
  24. // If Zammad was not properly set up yet, redirect to desktop front end.
  25. if (!application.config.system_init_done) {
  26. window.location.pathname = '/'
  27. } else {
  28. application.setLoaded()
  29. }
  30. })
  31. useAppMaintenanceCheck()
  32. usePushMessages()
  33. useAppTheme()
  34. // Add a check for authenticated changes (e.g. login/logout in a other
  35. // browser tab or maintenance mode switch).
  36. useAuthenticationChanges()
  37. // We need to trigger a manual translation update for the form related strings.
  38. const formConfig = useFormKitConfig()
  39. useLocaleStore().$subscribe(() => {
  40. formConfig.locale = 'staticLocale'
  41. })
  42. // The handling for invalid sessions. The event will be emitted, when from the server a "NotAuthorized"
  43. // response is received.
  44. emitter.on('sessionInvalid', async () => {
  45. if (authentication.authenticated) {
  46. await authentication.clearAuthentication()
  47. router.replace({
  48. name: 'Login',
  49. query: {
  50. invalidatedSession: '1',
  51. },
  52. })
  53. }
  54. })
  55. onBeforeUnmount(() => {
  56. emitter.off('sessionInvalid')
  57. })
  58. // Do not animate transitions in the test mode.
  59. const transition = VITE_TEST_MODE
  60. ? undefined
  61. : {
  62. enterActiveClass: 'duration-300 ease-out',
  63. enterFromClass: 'opacity-0 translate-y-3/4',
  64. enterToClass: 'opacity-100 translate-y-0',
  65. leaveActiveClass: 'duration-200 ease-in',
  66. leaveFromClass: 'opacity-100 translate-y-0',
  67. leaveToClass: 'opacity-0 translate-y-3/4',
  68. }
  69. </script>
  70. <template>
  71. <template v-if="application.loaded">
  72. <CommonNotifications />
  73. <CommonConfirmation />
  74. <Teleport to="body">
  75. <CommonImageViewer />
  76. </Teleport>
  77. </template>
  78. <div
  79. v-if="application.loaded"
  80. class="h-full min-w-full bg-black font-sans text-sm text-white antialiased"
  81. >
  82. <RouterView />
  83. </div>
  84. <DynamicInitializer name="dialog" :transition="transition" />
  85. </template>