GuidedSetupManualSystemInformation.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { shallowRef, computed, reactive } from 'vue'
  4. import { useRouter } from 'vue-router'
  5. import type {
  6. FormSubmitData,
  7. FormValues,
  8. } from '#shared/components/Form/types.ts'
  9. import Form from '#shared/components/Form/Form.vue'
  10. import { MutationHandler } from '#shared/server/apollo/handler/index.ts'
  11. import { useApplicationStore } from '#shared/stores/application.ts'
  12. import { useLogoUrl } from '#shared/composables/useLogoUrl.ts'
  13. import type { SystemInformationData } from '../../types/setup-manual.ts'
  14. import { useSystemSetup } from '../../composables/useSystemSetup.ts'
  15. import GuidedSetupActionFooter from '../../components/GuidedSetupActionFooter.vue'
  16. import { useGuidedSetupSetSystemInformationMutation } from '../../graphql/mutations/setSystemInformation.api.ts'
  17. const router = useRouter()
  18. const application = useApplicationStore()
  19. const { logoUrl } = useLogoUrl()
  20. const { setTitle } = useSystemSetup()
  21. setTitle(__('System Information'))
  22. const systemInformationSchema = [
  23. {
  24. isLayout: true,
  25. element: 'div',
  26. attrs: {
  27. class: 'grid gap-y-2.5',
  28. },
  29. children: [
  30. {
  31. name: 'organization',
  32. label: __('Organization Name'),
  33. type: 'text',
  34. required: true,
  35. placeholder: __('Company Inc.'),
  36. },
  37. {
  38. name: 'logo',
  39. label: __('Organization Logo'),
  40. type: 'imageUpload',
  41. props: {
  42. placeholderImagePath: logoUrl,
  43. },
  44. },
  45. {
  46. if: '$isSystemOnlineService !== true',
  47. name: 'url',
  48. label: __('System URL'),
  49. type: 'text',
  50. required: true,
  51. validation: 'url',
  52. help: __('The URL of this installation of Zammad.'),
  53. },
  54. ],
  55. },
  56. ]
  57. const getInitialInstanceUrl = () => {
  58. const { fqdn } = application.config
  59. if (!fqdn || fqdn === 'zammad.example.com') {
  60. return window.location.origin
  61. }
  62. return `${application.config.http_type}://${fqdn}`
  63. }
  64. const initialValues: FormValues = {
  65. organization: application.config.organization,
  66. url: getInitialInstanceUrl(),
  67. }
  68. const form = shallowRef()
  69. const isSystemOnlineService = computed(
  70. () => application.config.system_online_service,
  71. )
  72. const schemaData = reactive({
  73. isSystemOnlineService,
  74. })
  75. const dateTimeFormatOptions = Intl?.DateTimeFormat
  76. ? new Intl.DateTimeFormat().resolvedOptions()
  77. : null
  78. const locale = dateTimeFormatOptions?.locale
  79. const timezone = dateTimeFormatOptions?.timeZone
  80. const setSystemInformation = async (formData: SystemInformationData) => {
  81. const setSystemInformationMutation = new MutationHandler(
  82. useGuidedSetupSetSystemInformationMutation({}),
  83. )
  84. return setSystemInformationMutation
  85. .send({
  86. input: {
  87. organization: formData.organization,
  88. logo: formData.logo,
  89. url: formData.url,
  90. localeDefault: locale,
  91. timezoneDefault: timezone,
  92. },
  93. })
  94. .then(() => {
  95. if (application.config.system_online_service) {
  96. router.push('/guided-setup/manual/channels/email-pre-configured')
  97. return
  98. }
  99. router.push('/guided-setup/manual/email-notification')
  100. })
  101. }
  102. </script>
  103. <template>
  104. <Form
  105. id="set-system-manual"
  106. ref="form"
  107. form-class="mb-2.5"
  108. :schema="systemInformationSchema"
  109. :schema-data="schemaData"
  110. :initial-values="initialValues"
  111. @submit="
  112. setSystemInformation($event as FormSubmitData<SystemInformationData>)
  113. "
  114. />
  115. <GuidedSetupActionFooter
  116. :form="form"
  117. :submit-button-text="__('Save and Continue')"
  118. />
  119. </template>