GuidedSetupManualAdmin.vue 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { shallowRef } from 'vue'
  4. import { useRouter } from 'vue-router'
  5. import Form from '#shared/components/Form/Form.vue'
  6. import type { FormSubmitData } from '#shared/components/Form/types.ts'
  7. import useFingerprint from '#shared/composables/useFingerprint.ts'
  8. import type { SignupFormData } from '#shared/entities/user/types.ts'
  9. import MutationHandler from '#shared/server/apollo/handler/MutationHandler.ts'
  10. import { useAuthenticationStore } from '#shared/stores/authentication.ts'
  11. import { useSignupForm } from '#desktop/composables/authentication/useSignupForm.ts'
  12. import GuidedSetupActionFooter from '../../components/GuidedSetupActionFooter.vue'
  13. import { useSystemSetup } from '../../composables/useSystemSetup.ts'
  14. import { useUserAddFirstAdminMutation } from '../../graphql/mutations/userAddFirstAdmin.api.ts'
  15. import { systemSetupBeforeRouteEnterGuard } from '../../router/guards/systemSetupBeforeRouteEnterGuard.ts'
  16. import { useSystemSetupInfoStore } from '../../stores/systemSetupInfo.ts'
  17. defineOptions({
  18. beforeRouteEnter: systemSetupBeforeRouteEnterGuard,
  19. })
  20. const { setTitle } = useSystemSetup()
  21. setTitle(__('Create Administrator Account'))
  22. const router = useRouter()
  23. const form = shallowRef()
  24. const { signupSchema } = useSignupForm()
  25. const { systemSetupUnlock } = useSystemSetupInfoStore()
  26. const signup = async (data: SignupFormData) => {
  27. const { fingerprint } = useFingerprint()
  28. const sendSignup = new MutationHandler(
  29. useUserAddFirstAdminMutation({
  30. context: {
  31. headers: {
  32. 'X-Browser-Fingerprint': fingerprint.value,
  33. },
  34. },
  35. }),
  36. )
  37. return sendSignup
  38. .send({
  39. input: {
  40. firstname: data.firstname,
  41. lastname: data.lastname,
  42. email: data.email,
  43. password: data.password,
  44. },
  45. })
  46. .then(async (result) => {
  47. const { setAuthenticatedSessionId } = useAuthenticationStore()
  48. if (
  49. await setAuthenticatedSessionId(
  50. result?.userAddFirstAdmin?.session?.id || null,
  51. )
  52. ) {
  53. // TODO: after auth handling should be at the end of the setup triggered again (maybe we need to remember it?).
  54. systemSetupUnlock(() => {
  55. router.push('/guided-setup/manual/system-information')
  56. })
  57. }
  58. })
  59. }
  60. const unlockCallback = () => {
  61. router.replace('/guided-setup')
  62. }
  63. </script>
  64. <template>
  65. <Form
  66. id="admin-signup"
  67. ref="form"
  68. form-class="mb-2.5"
  69. :schema="signupSchema"
  70. @submit="signup($event as FormSubmitData<SignupFormData>)"
  71. />
  72. <GuidedSetupActionFooter
  73. :form="form"
  74. :submit-button-text="__('Create account')"
  75. @go-back="systemSetupUnlock(unlockCallback)"
  76. />
  77. </template>