GuidedSetupAutomatedRun.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { computed, ref } from 'vue'
  4. import MutationHandler from '#shared/server/apollo/handler/MutationHandler.ts'
  5. import LayoutPublicPage from '#desktop/components/layout/LayoutPublicPage/LayoutPublicPage.vue'
  6. import useFingerprint from '#shared/composables/useFingerprint.ts'
  7. import { useAuthenticationStore } from '#shared/stores/authentication.ts'
  8. import { useRouter } from 'vue-router'
  9. import type UserError from '#shared/errors/UserError.ts'
  10. // TODO: check
  11. // eslint-disable-next-line import/no-restricted-paths
  12. import { ensureAfterAuth } from '../../../authentication/after-auth/composable/useAfterAuthPlugins.ts'
  13. import { useSystemSetupRunAutoWizardMutation } from '../../graphql/mutations/systemSetupRunAutoWizard.api.ts'
  14. import GuidedSetupStatusMessage from '../../components/GuidedSetupStatusMessage.vue'
  15. interface Props {
  16. token?: string
  17. }
  18. const props = defineProps<Props>()
  19. const { fingerprint } = useFingerprint()
  20. const router = useRouter()
  21. const finished = ref(false)
  22. const errors = ref<UserError | undefined>()
  23. const runAutoWizardMutation = new MutationHandler(
  24. useSystemSetupRunAutoWizardMutation({
  25. variables: { token: props.token },
  26. context: {
  27. headers: {
  28. 'X-Browser-Fingerprint': fingerprint.value,
  29. },
  30. },
  31. }),
  32. )
  33. runAutoWizardMutation
  34. .send()
  35. .then(async (result) => {
  36. finished.value = true
  37. const { setAuthenticatedSessionId } = useAuthenticationStore()
  38. if (
  39. await setAuthenticatedSessionId(
  40. result?.systemSetupRunAutoWizard?.session?.id || null,
  41. )
  42. ) {
  43. const afterAuth = result?.systemSetupRunAutoWizard?.session?.afterAuth
  44. // Redirect only after some seconds, in order to give the user a chance to read the message.
  45. window.setTimeout(() => {
  46. if (afterAuth) {
  47. ensureAfterAuth(router, afterAuth)
  48. return
  49. }
  50. router.replace('/')
  51. }, 2000)
  52. }
  53. })
  54. .catch((error: UserError) => {
  55. errors.value = error
  56. })
  57. const statusMessage = computed(() => {
  58. if (finished.value)
  59. return __(
  60. 'The system was configured successfully. You are being redirected.',
  61. )
  62. return __('Relax, your system is being set up…')
  63. })
  64. </script>
  65. <template>
  66. <LayoutPublicPage box-size="medium" :title="__('Automated Setup')">
  67. <GuidedSetupStatusMessage v-if="!errors" :message="statusMessage" />
  68. <CommonAlert v-else variant="danger">{{
  69. errors?.generalErrors[0]
  70. }}</CommonAlert>
  71. </LayoutPublicPage>
  72. </template>