useImportSourceConfiguration.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { useRouter } from 'vue-router'
  3. import { EnumSystemImportSource } from '#shared/graphql/types.ts'
  4. import MutationHandler from '#shared/server/apollo/handler/MutationHandler.ts'
  5. import { useSystemImportConfigurationMutation } from '../graphql/mutations/systemImportConfiguration.api.ts'
  6. import { useImportSource } from './useImportSource.ts'
  7. import type { ImportSourceConfigurationBase } from '../types/setup-import.ts'
  8. export const useImportSourceConfiguration = <
  9. T extends ImportSourceConfigurationBase,
  10. >(
  11. source: EnumSystemImportSource,
  12. ) => {
  13. const router = useRouter()
  14. const { loading } = useImportSource()
  15. const configureSystemImportSource = (data: T) => {
  16. loading.value = true
  17. const systemImportConfigurationMutation = new MutationHandler(
  18. useSystemImportConfigurationMutation(),
  19. )
  20. let tlsVerify = true
  21. if (data.sslVerify !== undefined) {
  22. tlsVerify = data.sslVerify
  23. delete data.sslVerify
  24. }
  25. return systemImportConfigurationMutation
  26. .send({
  27. configuration: {
  28. ...data,
  29. source,
  30. tlsVerify,
  31. },
  32. })
  33. .then((result) => {
  34. if (result?.systemImportConfiguration?.success) {
  35. // TODO: For OTRS we need to remember some stuff (maybe with importSource-Date or something in the route?)
  36. router.push(`/guided-setup/import/${source}/start`)
  37. }
  38. })
  39. .finally(() => {
  40. loading.value = false
  41. })
  42. }
  43. return {
  44. configureSystemImportSource,
  45. }
  46. }