GuidedSetupManualEmailNotification.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { useRouter } from 'vue-router'
  4. import Form from '#shared/components/Form/Form.vue'
  5. import type { FormSubmitData } from '#shared/components/Form/types.ts'
  6. import { useDebouncedLoading } from '#shared/composables/useDebouncedLoading.ts'
  7. import { EnumFormUpdaterId } from '#shared/graphql/types.ts'
  8. import MutationHandler from '#shared/server/apollo/handler/MutationHandler.ts'
  9. import { useEmailOutboundForm } from '#desktop/entities/channel-email/composables/useEmailOutboundForm.ts'
  10. import { useChannelEmailSetNotificationConfigurationMutation } from '#desktop/entities/channel-email/graphql/mutations/channelEmailSetNotificationConfiguration.api.ts'
  11. import { useChannelEmailValidateConfigurationOutboundMutation } from '#desktop/entities/channel-email/graphql/mutations/channelEmailValidateConfigurationOutbound.api.ts'
  12. import type { EmailNotificationData } from '#desktop/entities/channel-email/types/email-notification.ts'
  13. import { useSSLVerificationWarningHandler } from '#desktop/form/composables/useSSLVerificationWarningHandler.ts'
  14. import GuidedSetupActionFooter from '../../components/GuidedSetupActionFooter.vue'
  15. import GuidedSetupStatusMessage from '../../components/GuidedSetupStatusMessage.vue'
  16. import { useSystemSetup } from '../../composables/useSystemSetup.ts'
  17. import { emailBeforeRouteEnterGuard } from '../../router/guards/emailBeforeRouteEnterGuard.ts'
  18. defineOptions({
  19. beforeRouteEnter: emailBeforeRouteEnterGuard,
  20. })
  21. const router = useRouter()
  22. const { setTitle } = useSystemSetup()
  23. setTitle(__('Email Notification'))
  24. const {
  25. formEmailOutbound,
  26. emailOutboundSchema,
  27. emailOutboundFormChangeFields,
  28. } = useEmailOutboundForm()
  29. const emailNotificationSchema = [
  30. // For now this is hidden, but should be changeable at some point: https://github.com/zammad/zammad/issues/3343
  31. {
  32. name: 'notification_sender',
  33. label: __('Notification Sender'),
  34. type: 'hidden',
  35. },
  36. ...emailOutboundSchema,
  37. ]
  38. const { loading, debouncedLoading } = useDebouncedLoading()
  39. const probeEmailNotification = async (data: EmailNotificationData) => {
  40. loading.value = true
  41. const validationConfigurationOutbound = new MutationHandler(
  42. useChannelEmailValidateConfigurationOutboundMutation(),
  43. )
  44. const setNotificationConfiguration = new MutationHandler(
  45. useChannelEmailSetNotificationConfigurationMutation(),
  46. )
  47. const emailOutboundData = {
  48. adapter: data.adapter,
  49. host: data.host,
  50. port: Number(data.port),
  51. user: data.user,
  52. password: data.password,
  53. sslVerify: data.sslVerify,
  54. }
  55. return validationConfigurationOutbound
  56. .send({
  57. outboundConfiguration: emailOutboundData,
  58. emailAddress: data.notification_sender,
  59. })
  60. .then(async () => {
  61. const result = await setNotificationConfiguration.send({
  62. outboundConfiguration: emailOutboundData,
  63. })
  64. if (result?.channelEmailSetNotificationConfiguration?.success) {
  65. router.push('/guided-setup/manual/channels')
  66. }
  67. })
  68. .finally(async () => {
  69. loading.value = false
  70. })
  71. }
  72. </script>
  73. <template>
  74. <GuidedSetupStatusMessage
  75. v-if="debouncedLoading"
  76. :message="__('Verifying and saving your configuration…')"
  77. />
  78. <div v-show="!debouncedLoading" class="flex flex-col gap-2.5">
  79. <Form
  80. id="email-notification-setup"
  81. ref="formEmailOutbound"
  82. data-test-id="email-notification-setup"
  83. form-class="mb-2.5"
  84. :flatten-form-groups="['outbound']"
  85. :form-updater-id="
  86. EnumFormUpdaterId.FormUpdaterUpdaterGuidedSetupEmailNotification
  87. "
  88. :schema="emailNotificationSchema"
  89. :handlers="[useSSLVerificationWarningHandler()]"
  90. :change-fields="emailOutboundFormChangeFields"
  91. @submit="
  92. probeEmailNotification($event as FormSubmitData<EmailNotificationData>)
  93. "
  94. />
  95. <GuidedSetupActionFooter
  96. go-back-route="/guided-setup/manual/system-information"
  97. skip-route="/guided-setup/manual/channels"
  98. :form="formEmailOutbound"
  99. :submit-button-text="__('Save and Continue')"
  100. />
  101. </div>
  102. </template>