useTicketSharedDraft.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import type { FormRef, FormValues } from '#shared/components/Form/types.ts'
  3. import { useTicketSharedDraftStartDeleteMutation } from '#shared/entities/ticket-shared-draft-start/graphql/mutations/ticketSharedDraftStartDelete.api.ts'
  4. import { useTicketSharedDraftStartSingleQuery } from '#shared/entities/ticket-shared-draft-start/graphql/queries/ticketSharedDraftStartSingle.api.ts'
  5. import { useTicketSharedDraftZoomDeleteMutation } from '#shared/entities/ticket-shared-draft-zoom/graphql/mutations/ticketSharedDraftZoomDelete.api.ts'
  6. import { useTicketSharedDraftZoomShowQuery } from '#shared/entities/ticket-shared-draft-zoom/graphql/queries/ticketSharedDraftZoomShow.api.ts'
  7. import { removeSignatureFromBody } from '#shared/utils/dom.ts'
  8. import { useFlyout } from '#desktop/components/CommonFlyout/useFlyout.ts'
  9. export const useTicketSharedDraft = () => {
  10. const mapSharedDraftParams = (ticketId: string, form?: FormRef) => {
  11. const {
  12. article: newArticle,
  13. ...ticketAttributes
  14. }: { article?: FormValues } = form?.values || {}
  15. // Map values to the expected format
  16. if (newArticle) {
  17. newArticle.type = newArticle.articleType
  18. newArticle.to = ((newArticle.to as string[]) || []).join(', ')
  19. newArticle.cc = ((newArticle.cc as string[]) || []).join(', ')
  20. newArticle.body = removeSignatureFromBody(newArticle.body)
  21. }
  22. return {
  23. ticketId,
  24. formId: form?.formId as string,
  25. newArticle: newArticle || {},
  26. ticketAttributes,
  27. }
  28. }
  29. const sharedDraftFlyout = useFlyout({
  30. name: 'shared-draft',
  31. component: () => import('../components/TicketSharedDraftFlyout.vue'),
  32. })
  33. const openSharedDraftFlyout = (
  34. draftType: 'start' | 'detail-view',
  35. sharedDraftId?: string | null,
  36. form?: FormRef,
  37. ) => {
  38. sharedDraftFlyout.open({
  39. sharedDraftId,
  40. form,
  41. draftType,
  42. metaInformationQuery:
  43. draftType === 'start'
  44. ? useTicketSharedDraftStartSingleQuery
  45. : useTicketSharedDraftZoomShowQuery,
  46. deleteMutation:
  47. draftType === 'start'
  48. ? useTicketSharedDraftStartDeleteMutation
  49. : useTicketSharedDraftZoomDeleteMutation,
  50. })
  51. }
  52. return {
  53. mapSharedDraftParams,
  54. openSharedDraftFlyout,
  55. }
  56. }