useImportSourceConfiguration.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { useRouter } from 'vue-router'
  3. import MutationHandler from '#shared/server/apollo/handler/MutationHandler.ts'
  4. import { EnumSystemImportSource } from '#shared/graphql/types.ts'
  5. import { useSystemImportConfigurationMutation } from '../graphql/mutations/systemImportConfiguration.api.ts'
  6. import type { ImportSourceConfigurationBase } from '../types/setup-import.ts'
  7. import { useImportSource } from './useImportSource.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. }