GuidedSetupManualChannelEmail.vue 7.6 KB

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