GuidedSetupManualAdmin.vue 2.5 KB

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