accountMenuBuilder.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. import type { MenuGroup, MenuItem, MenuItems } from '~/types/layout'
  2. import { MENU_LINK_TYPE } from '~/types/enum/layout'
  3. import AbstractMenuBuilder from '~/services/layout/menuBuilder/abstractMenuBuilder'
  4. /**
  5. * Menu Mon compte
  6. */
  7. export default class AccountMenuBuilder extends AbstractMenuBuilder {
  8. static override readonly menuName = 'Account'
  9. /**
  10. * Construit le menu Header Configuration ou null si aucune page accessible
  11. */
  12. build(): MenuItem | MenuGroup | null {
  13. const children: MenuItems = []
  14. const actions: Array<MenuItem> = []
  15. if (this.ability.can('display', 'my_schedule_page')) {
  16. children.push(
  17. this.createItem(
  18. 'my_schedule_page',
  19. undefined,
  20. '/my_calendar',
  21. MENU_LINK_TYPE.V1,
  22. ),
  23. )
  24. }
  25. if (this.ability.can('display', 'attendance_bookings_page')) {
  26. children.push(
  27. this.createItem(
  28. 'attendance_bookings_menu',
  29. undefined,
  30. '/own_attendance',
  31. MENU_LINK_TYPE.V1,
  32. ),
  33. )
  34. }
  35. if (this.ability.can('display', 'my_attendance_page')) {
  36. children.push(
  37. this.createItem(
  38. 'my_attendance',
  39. undefined,
  40. '/my_attendances/list/',
  41. MENU_LINK_TYPE.V1,
  42. ),
  43. )
  44. }
  45. if (this.ability.can('display', 'my_invitation_page')) {
  46. children.push(
  47. this.createItem(
  48. 'my_invitation',
  49. undefined,
  50. '/my_invitations/list/',
  51. MENU_LINK_TYPE.V1,
  52. ),
  53. )
  54. }
  55. if (this.ability.can('display', 'my_students_page')) {
  56. children.push(
  57. this.createItem(
  58. 'my_students',
  59. undefined,
  60. '/my_students/list/',
  61. MENU_LINK_TYPE.V1,
  62. ),
  63. )
  64. }
  65. if (this.ability.can('display', 'my_students_education_students_page')) {
  66. children.push(
  67. this.createItem(
  68. 'my_students_education_students',
  69. undefined,
  70. '/my_students_education_students/list/',
  71. MENU_LINK_TYPE.V1,
  72. ),
  73. )
  74. }
  75. if (this.ability.can('display', 'my_education_students_page')) {
  76. children.push(
  77. this.createItem(
  78. 'my_education_students',
  79. undefined,
  80. `/main/my_profile/${this.accessProfile.id}/dashboard/my_education_students/list/`,
  81. MENU_LINK_TYPE.V1,
  82. ),
  83. )
  84. }
  85. if (this.ability.can('display', 'send_an_email_page')) {
  86. children.push(
  87. this.createItem(
  88. 'send_an_email',
  89. undefined,
  90. `/list/create/emails`,
  91. MENU_LINK_TYPE.V1,
  92. ),
  93. )
  94. }
  95. if (this.ability.can('display', 'my_documents_page')) {
  96. children.push(
  97. this.createItem(
  98. 'my_documents',
  99. undefined,
  100. `/main/my_profile/${this.accessProfile.id}/dashboard/show/my_access_file`,
  101. MENU_LINK_TYPE.V1,
  102. ),
  103. )
  104. }
  105. if (this.ability.can('display', 'my_profile_page')) {
  106. children.push(
  107. this.createItem(
  108. 'my_profile',
  109. undefined,
  110. `/main/my_profile/${this.accessProfile.id}/dashboard`,
  111. MENU_LINK_TYPE.V1,
  112. ),
  113. )
  114. }
  115. if (this.ability.can('display', 'adherent_list_page')) {
  116. children.push(
  117. this.createItem(
  118. 'adherent_list',
  119. undefined,
  120. `/adherent_contacts/list/`,
  121. MENU_LINK_TYPE.V1,
  122. false,
  123. true,
  124. ),
  125. )
  126. }
  127. children.push(
  128. ...this.makeChildren([
  129. { pageName: 'subscription_page', endOfSubsection: true },
  130. ]),
  131. )
  132. if (this.ability.can('display', 'my_bills_page')) {
  133. children.push(
  134. this.createItem(
  135. 'my_bills',
  136. undefined,
  137. `/main/my_profile/${this.accessProfile.id}/dashboard/show/my_bills`,
  138. MENU_LINK_TYPE.V1,
  139. ),
  140. )
  141. }
  142. if (this.ability.can('display', 'cmf_licence_person_page')) {
  143. children.push(
  144. this.createItem(
  145. 'print_my_licence',
  146. undefined,
  147. `/licence_cmf/user`,
  148. MENU_LINK_TYPE.V1,
  149. ),
  150. )
  151. }
  152. children.push(
  153. ...this.makeChildren([
  154. { pageName: 'my_settings_page', endOfSubsection: true },
  155. ]),
  156. )
  157. children.push(
  158. ...this.makeChildren([{ pageName: 'freemium_organization_page' }]),
  159. )
  160. actions.push(
  161. this.createItem('logout', undefined, `/logout`, MENU_LINK_TYPE.V1),
  162. )
  163. const icon = {
  164. avatarId: this.accessProfile.avatarId,
  165. avatarByDefault:
  166. this.accessProfile.gender === 'MISTER'
  167. ? '/images/default/men-1.png'
  168. : '/images/default/women-1.png',
  169. }
  170. return this.createGroup('my_account', icon, children, actions)
  171. }
  172. }