changeVisibility.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { useTicketArticleChangeVisibilityMutation } from '#shared/entities/ticket-article/graphql/mutations/changeVisibility.api.ts'
  3. import { MutationHandler } from '#shared/server/apollo/handler/index.ts'
  4. import type { TicketArticleActionPlugin, TicketArticleAction } from './types.ts'
  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 ? 'lock' : 'lock-open'
  28. const action: TicketArticleAction = {
  29. apps: ['mobile', 'desktop'],
  30. label,
  31. name: 'changeVisibility',
  32. icon: iconName,
  33. view: {
  34. agent: ['change'],
  35. },
  36. perform: () => changeVisibilityAction(article.id, targetInternalState),
  37. }
  38. return [action]
  39. },
  40. }
  41. export default actionPlugin