GuidedSetupManualChannelEmail.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { computed, watch } 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 { EnumFormUpdaterId } from '#shared/graphql/types.ts'
  8. import { useSSLVerificationWarningHandler } from '#desktop/form/composables/useSSLVerificationWarningHandler.ts'
  9. import { useEmailAccountForm } from '#desktop/entities/channel-email/composables/useEmailAccountForm.ts'
  10. import { useEmailInboundForm } from '#desktop/entities/channel-email/composables/useEmailInboundForm.ts'
  11. import { useEmailInboundMessagesForm } from '#desktop/entities/channel-email/composables/useEmailInboundMessagesForm.ts'
  12. import { useEmailChannelConfiguration } from '#desktop/entities/channel-email/composables/useEmailChannelConfiguration.ts'
  13. import { useEmailOutboundForm } from '#desktop/entities/channel-email/composables/useEmailOutboundForm.ts'
  14. import type { EmailAccountData } from '#desktop/entities/channel-email/types/email-account.ts'
  15. import type {
  16. EmailInboundData,
  17. EmailOutboundData,
  18. EmailInboundMessagesData,
  19. } from '#desktop/entities/channel-email/types/email-inbound-outbound.ts'
  20. import GuidedSetupActionFooter from '../../components/GuidedSetupActionFooter.vue'
  21. import GuidedSetupStatusMessage from '../../components/GuidedSetupStatusMessage.vue'
  22. import { useSystemSetup } from '../../composables/useSystemSetup.ts'
  23. import { emailBeforeRouteEnterGuard } from '../../router/guards/emailBeforeRouteEnterGuard.ts'
  24. defineOptions({
  25. beforeRouteEnter: emailBeforeRouteEnterGuard,
  26. })
  27. const router = useRouter()
  28. const { setTitle } = useSystemSetup()
  29. const {
  30. formEmailAccount,
  31. emailAccountSchema,
  32. formEmailAccountValues,
  33. formEmailAccountSetErrors,
  34. updateEmailAccountFieldValues,
  35. } = useEmailAccountForm()
  36. const {
  37. formEmailInbound,
  38. emailInboundSchema,
  39. formEmailInboundValues,
  40. formEmailInboundSetErrors,
  41. updateEmailInboundFieldValues,
  42. emailInboundFormOnChanged,
  43. metaInformationInbound,
  44. emailInboundFormChangeFields,
  45. updateMetaInformationInbound,
  46. } = useEmailInboundForm()
  47. const {
  48. formEmailInboundMessages,
  49. emailInboundMessageSchema,
  50. emailInboundMessageSchemaData,
  51. } = useEmailInboundMessagesForm(metaInformationInbound)
  52. const {
  53. formEmailOutbound,
  54. emailOutboundSchema,
  55. formEmailOutboundValues,
  56. formEmailOutboundSetErrors,
  57. updateEmailOutboundFieldValues,
  58. emailOutboundFormChangeFields,
  59. emailOutboundFormOnChanged,
  60. } = useEmailOutboundForm()
  61. const {
  62. activeStep,
  63. activeForm,
  64. stepTitle,
  65. debouncedLoading,
  66. guessEmailAccount,
  67. validateEmailInbound,
  68. validateEmailOutbound,
  69. importEmailInboundMessages,
  70. } = useEmailChannelConfiguration(
  71. {
  72. emailAccount: {
  73. form: formEmailAccount,
  74. values: formEmailAccountValues,
  75. updateFieldValues: updateEmailAccountFieldValues,
  76. setErrors: formEmailAccountSetErrors,
  77. },
  78. emailInbound: {
  79. form: formEmailInbound,
  80. values: formEmailInboundValues,
  81. setErrors: formEmailInboundSetErrors,
  82. updateFieldValues: updateEmailInboundFieldValues,
  83. },
  84. emailInboundMessages: {
  85. form: formEmailInboundMessages,
  86. },
  87. emailOutbound: {
  88. form: formEmailOutbound,
  89. values: formEmailOutboundValues,
  90. setErrors: formEmailOutboundSetErrors,
  91. updateFieldValues: updateEmailOutboundFieldValues,
  92. },
  93. },
  94. metaInformationInbound,
  95. updateMetaInformationInbound,
  96. () => router.push('/guided-setup/manual/invite'),
  97. )
  98. watch(stepTitle, setTitle, { immediate: true })
  99. const activeInboundMessageNextRoundtrip = computed(
  100. () =>
  101. activeStep.value === 'inbound-messages' &&
  102. metaInformationInbound.value?.nextAction === 'roundtrip',
  103. )
  104. const goBack = () => {
  105. if (
  106. activeStep.value === 'inbound' ||
  107. activeInboundMessageNextRoundtrip.value
  108. ) {
  109. activeStep.value = 'account'
  110. } else if (activeStep.value === 'outbound' && metaInformationInbound.value) {
  111. activeStep.value = 'inbound-messages'
  112. } else if (['outbound', 'inbound-messages'].includes(activeStep.value)) {
  113. activeStep.value = 'inbound'
  114. } else {
  115. router.push('/guided-setup/manual/channels')
  116. }
  117. }
  118. const submitButtonText = computed(() => {
  119. if (activeStep.value === 'account') {
  120. return __('Connect and Continue')
  121. }
  122. if (
  123. activeStep.value === 'inbound' ||
  124. (activeStep.value !== 'outbound' &&
  125. !activeInboundMessageNextRoundtrip.value)
  126. ) {
  127. return __('Continue')
  128. }
  129. if (['outbound', 'inbound-messages'].includes(activeStep.value)) {
  130. return __('Save and Continue')
  131. }
  132. return __('Connect and Continue')
  133. })
  134. const submitButtonVariant = computed(() => {
  135. if (activeStep.value === 'account') {
  136. return 'submit'
  137. }
  138. if (
  139. activeStep.value === 'inbound' ||
  140. (activeStep.value !== 'outbound' &&
  141. !activeInboundMessageNextRoundtrip.value)
  142. ) {
  143. return 'primary'
  144. }
  145. return 'submit'
  146. })
  147. const emailConfigurationCheck = computed(() => {
  148. if (activeStep.value === 'account') {
  149. return __('Verifying and saving your configuration…')
  150. }
  151. if (
  152. activeStep.value === 'inbound' ||
  153. (activeStep.value !== 'outbound' &&
  154. !activeInboundMessageNextRoundtrip.value)
  155. ) {
  156. return __('Verifying your configuration…')
  157. }
  158. return __('Verifying and saving your configuration…')
  159. })
  160. </script>
  161. <template>
  162. <GuidedSetupStatusMessage
  163. v-if="debouncedLoading"
  164. :message="emailConfigurationCheck"
  165. />
  166. <div v-show="!debouncedLoading" class="flex flex-col gap-2.5">
  167. <div v-show="activeStep === 'account'">
  168. <Form
  169. id="channel-email-account"
  170. ref="formEmailAccount"
  171. data-test-id="channel-email-account"
  172. form-class="mb-2.5"
  173. :schema="emailAccountSchema"
  174. @submit="guessEmailAccount($event as FormSubmitData<EmailAccountData>)"
  175. />
  176. </div>
  177. <div v-show="activeStep === 'inbound'">
  178. <Form
  179. id="channel-email-inbound"
  180. ref="formEmailInbound"
  181. data-test-id="channel-email-inbound"
  182. form-class="mb-2.5"
  183. :handlers="[useSSLVerificationWarningHandler()]"
  184. :flatten-form-groups="['inbound']"
  185. :form-updater-id="
  186. EnumFormUpdaterId.FormUpdaterUpdaterGuidedSetupEmailInbound
  187. "
  188. :schema="emailInboundSchema"
  189. :change-fields="emailInboundFormChangeFields"
  190. @changed="emailInboundFormOnChanged"
  191. @submit="
  192. validateEmailInbound($event as FormSubmitData<EmailInboundData>)
  193. "
  194. />
  195. </div>
  196. <div v-show="activeStep === 'inbound-messages'">
  197. <Form
  198. id="channel-email-inbound-messages"
  199. ref="formEmailInboundMessages"
  200. data-test-id="channel-email-inbound-messages"
  201. form-class="mb-2.5"
  202. :schema="emailInboundMessageSchema"
  203. :schema-data="emailInboundMessageSchemaData"
  204. @submit="
  205. importEmailInboundMessages(
  206. $event as FormSubmitData<EmailInboundMessagesData>,
  207. )
  208. "
  209. />
  210. </div>
  211. <div v-show="activeStep === 'outbound'">
  212. <Form
  213. id="channel-email-outbound"
  214. ref="formEmailOutbound"
  215. data-test-id="channel-email-outbound"
  216. form-class="mb-2.5"
  217. :handlers="[useSSLVerificationWarningHandler()]"
  218. :flatten-form-groups="['outbound']"
  219. :form-updater-id="
  220. EnumFormUpdaterId.FormUpdaterUpdaterGuidedSetupEmailOutbound
  221. "
  222. :schema="emailOutboundSchema"
  223. :change-fields="emailOutboundFormChangeFields"
  224. @changed="emailOutboundFormOnChanged"
  225. @submit="
  226. validateEmailOutbound($event as FormSubmitData<EmailOutboundData>)
  227. "
  228. />
  229. </div>
  230. <GuidedSetupActionFooter
  231. :form="activeForm"
  232. :submit-button-variant="submitButtonVariant"
  233. :submit-button-text="submitButtonText"
  234. @back="goBack"
  235. />
  236. </div>
  237. </template>