rewardsMenuBuilder.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. export class RewardsMenuBuilder extends AbstractMenuBuilder {
  5. static override readonly menuName = 'AccessRewards'
  6. /**
  7. * Construit le menu distinctions, ou null si aucune page accessible
  8. */
  9. build(): MenuItem | MenuGroup | null {
  10. const children: MenuItems = []
  11. if (this.ability.can('display', 'access_rewards_list_page')) {
  12. children.push(
  13. this.createItem(
  14. 'access_rewards_list',
  15. { name: 'fas fa-trophy' },
  16. '/access_rewards_not_delivered/list/',
  17. MENU_LINK_TYPE.V1,
  18. ),
  19. )
  20. }
  21. if (this.ability.can('display', 'access_rewards_command_page')) {
  22. children.push(
  23. this.createItem(
  24. 'access_rewards_command',
  25. { name: 'fas fa-trophy' },
  26. '/access_reward_commands',
  27. MENU_LINK_TYPE.V1,
  28. ),
  29. )
  30. }
  31. if (this.ability.can('display', 'rewards_list_page')) {
  32. children.push(
  33. this.createItem(
  34. 'rewards_list',
  35. { name: 'fas fa-trophy' },
  36. '/rewards/list/',
  37. MENU_LINK_TYPE.V1,
  38. ),
  39. )
  40. }
  41. if (children.length > 1) {
  42. // Plusieurs éléments, on retourne un groupe
  43. return this.createGroup(
  44. 'access_rewards',
  45. { name: 'fas fa-trophy' },
  46. children,
  47. )
  48. } else if (children.length === 1) {
  49. // Un seul élément, on retourne cet élément seul
  50. return children[0]
  51. }
  52. return null
  53. }
  54. }