communicationMenuBuilder.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import AbstractMenuBuilder from '~/services/layout/menuBuilder/abstractMenuBuilder'
  2. import type { MenuGroup, MenuItem, MenuItems } from '~/types/layout'
  3. import { MENU_LINK_TYPE } from '~/types/enum/layout'
  4. /**
  5. * Menu Communication
  6. */
  7. export default class CommunicationMenuBuilder extends AbstractMenuBuilder {
  8. static override readonly menuName = 'Communication'
  9. /**
  10. * Construit le menu Communication ou null si aucune page accessible
  11. */
  12. build(): MenuItem | MenuGroup | null {
  13. const children: MenuItems = []
  14. if (this.ability.can('display', 'inbox_page')) {
  15. children.push(
  16. this.createItem(
  17. 'inbox',
  18. { name: 'fas fa-inbox' },
  19. '/messages/list/',
  20. MENU_LINK_TYPE.V1,
  21. ),
  22. )
  23. }
  24. if (this.ability.can('display', 'message_send_page')) {
  25. children.push(
  26. this.createItem(
  27. 'message_send',
  28. { name: 'fas fa-paper-plane' },
  29. '/messagessends/list/',
  30. MENU_LINK_TYPE.V1,
  31. ),
  32. )
  33. }
  34. if (this.ability.can('display', 'message_templates_page')) {
  35. children.push(
  36. this.createItem(
  37. 'message_templates',
  38. { name: 'fas fa-edit' },
  39. '/templates/list/',
  40. MENU_LINK_TYPE.V1,
  41. ),
  42. )
  43. }
  44. if (children.length > 1) {
  45. // Plusieurs éléments, on retourne un groupe
  46. return this.createGroup(
  47. 'communication',
  48. { name: 'fas fa-comments' },
  49. children,
  50. )
  51. } else if (children.length === 1) {
  52. // Un seul élément, on retourne cet élément seul
  53. return children[0]
  54. }
  55. return null
  56. }
  57. }