123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
- <script setup lang="ts">
- import { computed, watch } from 'vue'
- import { useRouter } from 'vue-router'
- import Form from '#shared/components/Form/Form.vue'
- import type { FormSubmitData } from '#shared/components/Form/types.ts'
- import { EnumFormUpdaterId } from '#shared/graphql/types.ts'
- import { useEmailAccountForm } from '#desktop/entities/channel-email/composables/useEmailAccountForm.ts'
- import { useEmailChannelConfiguration } from '#desktop/entities/channel-email/composables/useEmailChannelConfiguration.ts'
- import { useEmailInboundForm } from '#desktop/entities/channel-email/composables/useEmailInboundForm.ts'
- import { useEmailInboundMessagesForm } from '#desktop/entities/channel-email/composables/useEmailInboundMessagesForm.ts'
- import { useEmailOutboundForm } from '#desktop/entities/channel-email/composables/useEmailOutboundForm.ts'
- import type { EmailAccountData } from '#desktop/entities/channel-email/types/email-account.ts'
- import type {
- EmailInboundData,
- EmailOutboundData,
- EmailInboundMessagesData,
- } from '#desktop/entities/channel-email/types/email-inbound-outbound.ts'
- import { useSSLVerificationWarningHandler } from '#desktop/form/composables/useSSLVerificationWarningHandler.ts'
- import GuidedSetupActionFooter from '../../components/GuidedSetupActionFooter.vue'
- import GuidedSetupStatusMessage from '../../components/GuidedSetupStatusMessage.vue'
- import { useSystemSetup } from '../../composables/useSystemSetup.ts'
- import { emailBeforeRouteEnterGuard } from '../../router/guards/emailBeforeRouteEnterGuard.ts'
- defineOptions({
- beforeRouteEnter: emailBeforeRouteEnterGuard,
- })
- const router = useRouter()
- const { setTitle } = useSystemSetup()
- const {
- formEmailAccount,
- emailAccountSchema,
- formEmailAccountValues,
- formEmailAccountSetErrors,
- updateEmailAccountFieldValues,
- } = useEmailAccountForm()
- const {
- formEmailInbound,
- emailInboundSchema,
- formEmailInboundValues,
- formEmailInboundSetErrors,
- updateEmailInboundFieldValues,
- metaInformationInbound,
- emailInboundFormChangeFields,
- updateMetaInformationInbound,
- } = useEmailInboundForm()
- const {
- formEmailInboundMessages,
- emailInboundMessageSchema,
- emailInboundMessageSchemaData,
- } = useEmailInboundMessagesForm(metaInformationInbound)
- const {
- formEmailOutbound,
- emailOutboundSchema,
- formEmailOutboundValues,
- formEmailOutboundSetErrors,
- updateEmailOutboundFieldValues,
- emailOutboundFormChangeFields,
- } = useEmailOutboundForm()
- const {
- activeStep,
- activeForm,
- stepTitle,
- debouncedLoading,
- guessEmailAccount,
- validateEmailInbound,
- validateEmailOutbound,
- importEmailInboundMessages,
- } = useEmailChannelConfiguration(
- {
- emailAccount: {
- form: formEmailAccount,
- values: formEmailAccountValues,
- updateFieldValues: updateEmailAccountFieldValues,
- setErrors: formEmailAccountSetErrors,
- },
- emailInbound: {
- form: formEmailInbound,
- values: formEmailInboundValues,
- setErrors: formEmailInboundSetErrors,
- updateFieldValues: updateEmailInboundFieldValues,
- },
- emailInboundMessages: {
- form: formEmailInboundMessages,
- },
- emailOutbound: {
- form: formEmailOutbound,
- values: formEmailOutboundValues,
- setErrors: formEmailOutboundSetErrors,
- updateFieldValues: updateEmailOutboundFieldValues,
- },
- },
- metaInformationInbound,
- updateMetaInformationInbound,
- () => router.push('/guided-setup/manual/invite'),
- )
- watch(stepTitle, setTitle, { immediate: true })
- const activeInboundMessageNextRoundtrip = computed(
- () =>
- activeStep.value === 'inbound-messages' &&
- metaInformationInbound.value?.nextAction === 'roundtrip',
- )
- const goBack = () => {
- if (
- activeStep.value === 'inbound' ||
- activeInboundMessageNextRoundtrip.value
- ) {
- activeStep.value = 'account'
- } else if (activeStep.value === 'outbound' && metaInformationInbound.value) {
- activeStep.value = 'inbound-messages'
- } else if (['outbound', 'inbound-messages'].includes(activeStep.value)) {
- activeStep.value = 'inbound'
- } else {
- router.push('/guided-setup/manual/channels')
- }
- }
- const submitButtonText = computed(() => {
- if (activeStep.value === 'account') {
- return __('Connect and Continue')
- }
- if (
- activeStep.value === 'inbound' ||
- (activeStep.value !== 'outbound' &&
- !activeInboundMessageNextRoundtrip.value)
- ) {
- return __('Continue')
- }
- if (['outbound', 'inbound-messages'].includes(activeStep.value)) {
- return __('Save and Continue')
- }
- return __('Connect and Continue')
- })
- const submitButtonVariant = computed(() => {
- if (activeStep.value === 'account') {
- return 'submit'
- }
- if (
- activeStep.value === 'inbound' ||
- (activeStep.value !== 'outbound' &&
- !activeInboundMessageNextRoundtrip.value)
- ) {
- return 'primary'
- }
- return 'submit'
- })
- const emailConfigurationCheck = computed(() => {
- if (activeStep.value === 'account') {
- return __('Verifying and saving your configuration…')
- }
- if (
- activeStep.value === 'inbound' ||
- (activeStep.value !== 'outbound' &&
- !activeInboundMessageNextRoundtrip.value)
- ) {
- return __('Verifying your configuration…')
- }
- return __('Verifying and saving your configuration…')
- })
- </script>
- <template>
- <GuidedSetupStatusMessage
- v-if="debouncedLoading"
- :message="emailConfigurationCheck"
- />
- <div v-show="!debouncedLoading" class="flex flex-col gap-2.5">
- <div v-show="activeStep === 'account'">
- <Form
- id="channel-email-account"
- ref="formEmailAccount"
- data-test-id="channel-email-account"
- form-class="mb-2.5"
- :schema="emailAccountSchema"
- @submit="guessEmailAccount($event as FormSubmitData<EmailAccountData>)"
- />
- </div>
- <div v-show="activeStep === 'inbound'">
- <Form
- id="channel-email-inbound"
- ref="formEmailInbound"
- data-test-id="channel-email-inbound"
- form-class="mb-2.5"
- :handlers="[useSSLVerificationWarningHandler()]"
- :flatten-form-groups="['inbound']"
- :form-updater-id="
- EnumFormUpdaterId.FormUpdaterUpdaterGuidedSetupEmailInbound
- "
- :schema="emailInboundSchema"
- :change-fields="emailInboundFormChangeFields"
- @submit="
- validateEmailInbound($event as FormSubmitData<EmailInboundData>)
- "
- />
- </div>
- <div v-show="activeStep === 'inbound-messages'">
- <Form
- id="channel-email-inbound-messages"
- ref="formEmailInboundMessages"
- data-test-id="channel-email-inbound-messages"
- form-class="mb-2.5"
- :schema="emailInboundMessageSchema"
- :schema-data="emailInboundMessageSchemaData"
- @submit="
- importEmailInboundMessages(
- $event as FormSubmitData<EmailInboundMessagesData>,
- )
- "
- />
- </div>
- <div v-show="activeStep === 'outbound'">
- <Form
- id="channel-email-outbound"
- ref="formEmailOutbound"
- data-test-id="channel-email-outbound"
- form-class="mb-2.5"
- :handlers="[useSSLVerificationWarningHandler()]"
- :flatten-form-groups="['outbound']"
- :form-updater-id="
- EnumFormUpdaterId.FormUpdaterUpdaterGuidedSetupEmailOutbound
- "
- :schema="emailOutboundSchema"
- :change-fields="emailOutboundFormChangeFields"
- @submit="
- validateEmailOutbound($event as FormSubmitData<EmailOutboundData>)
- "
- />
- </div>
- <GuidedSetupActionFooter
- :form="activeForm"
- :submit-button-variant="submitButtonVariant"
- :submit-button-text="submitButtonText"
- @go-back="goBack"
- />
- </div>
- </template>
|