GuidedSetupAutomatedRun.vue 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { computed, ref } from 'vue'
  4. import { useRouter } from 'vue-router'
  5. import useFingerprint from '#shared/composables/useFingerprint.ts'
  6. import type UserError from '#shared/errors/UserError.ts'
  7. import MutationHandler from '#shared/server/apollo/handler/MutationHandler.ts'
  8. import { useAuthenticationStore } from '#shared/stores/authentication.ts'
  9. import LayoutPublicPage from '#desktop/components/layout/LayoutPublicPage/LayoutPublicPage.vue'
  10. // TODO: check
  11. // eslint-disable-next-line import/no-restricted-paths
  12. import { ensureAfterAuth } from '../../../authentication/after-auth/composable/useAfterAuthPlugins.ts'
  13. import GuidedSetupStatusMessage from '../../components/GuidedSetupStatusMessage.vue'
  14. import { useSystemSetupRunAutoWizardMutation } from '../../graphql/mutations/systemSetupRunAutoWizard.api.ts'
  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>