useTicketArticleReply.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { computed, ref } from 'vue'
  3. import type { FormRef } from '#shared/components/Form/types.ts'
  4. import type { Ref, ShallowRef } from 'vue'
  5. export const useTicketArticleReply = (
  6. form: ShallowRef<FormRef | undefined>,
  7. initialNewTicketArticlePresent: Ref<boolean | undefined>,
  8. ) => {
  9. const localNewTicketArticlePresent = ref<boolean>()
  10. // TODO: switching tabs when you added a new article is shortly showing the buttons (because taskbar tab don't has the information yet?)
  11. const newTicketArticlePresent = computed({
  12. get: () => {
  13. if (localNewTicketArticlePresent.value !== undefined)
  14. return localNewTicketArticlePresent.value
  15. return initialNewTicketArticlePresent.value
  16. },
  17. set: (value) => {
  18. localNewTicketArticlePresent.value = value
  19. },
  20. })
  21. const articleFormGroupNode = computed(() => {
  22. if (!newTicketArticlePresent.value) return undefined
  23. return form.value?.getNodeByName('article')
  24. })
  25. const isArticleFormGroupValid = computed(() => {
  26. return !!articleFormGroupNode.value?.context?.state.valid
  27. })
  28. const showTicketArticleReplyForm = () => {
  29. newTicketArticlePresent.value = true
  30. }
  31. return {
  32. newTicketArticlePresent,
  33. articleFormGroupNode,
  34. isArticleFormGroupValid,
  35. showTicketArticleReplyForm,
  36. }
  37. }