changeVisibility.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. import { MutationHandler } from '@shared/server/apollo/handler'
  3. import { useTicketArticleChangeVisibilityMutation } from '@shared/entities/ticket-article/graphql/mutations/changeVisibility.api'
  4. import type { TicketArticleActionPlugin, TicketArticleAction } from './types'
  5. const changeVisibilityAction = (
  6. articleId: string,
  7. targetInternalState: boolean,
  8. ) => {
  9. const errorNotificationMessage = targetInternalState
  10. ? __('The article could not be set to internal.')
  11. : __('The article could not be set to public.')
  12. const mutation = new MutationHandler(
  13. useTicketArticleChangeVisibilityMutation({
  14. variables: { articleId, internal: targetInternalState },
  15. }),
  16. { errorNotificationMessage },
  17. )
  18. return mutation.send()
  19. }
  20. const actionPlugin: TicketArticleActionPlugin = {
  21. order: 50,
  22. addActions(ticket, article) {
  23. const targetInternalState = !article.internal
  24. const label = targetInternalState
  25. ? __('Set to internal')
  26. : __('Set to public')
  27. const iconName = targetInternalState ? 'mobile-lock' : 'mobile-lock-open'
  28. const action: TicketArticleAction = {
  29. apps: ['mobile'],
  30. label,
  31. name: 'changeVisibility',
  32. icon: { mobile: iconName },
  33. view: {
  34. agent: ['change'],
  35. },
  36. perform: () => changeVisibilityAction(article.id, targetInternalState),
  37. }
  38. return [action]
  39. },
  40. }
  41. export default actionPlugin