organizationProfile.ts 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. import { baseOrganizationState } from '~/types/interfaces'
  2. import { defineStore } from "pinia";
  3. import {computed, Ref} from "@vue/reactivity";
  4. import {useEach} from "#imports";
  5. export const useOrganizationProfileStore = defineStore('organizationProfile', () => {
  6. // State
  7. const id = ref(null)
  8. const parametersId = ref(null)
  9. const name = ref(null)
  10. const product = ref(null)
  11. const currentActivityYear = ref(null)
  12. const modules = ref([])
  13. const hasChildren = ref(false)
  14. const legalStatus = ref(null)
  15. const showAdherentList = ref(false)
  16. const networks = ref([])
  17. const website = ref(null)
  18. const parents: Ref<Array<baseOrganizationState>> = ref([])
  19. // Getters
  20. /**
  21. * Est-ce que l'organisation possède le module donné
  22. *
  23. * @param {Array<string>} modules Modules à tester
  24. * @return {boolean}
  25. */
  26. const hasModule = computed((): boolean => {
  27. let hasModule = false
  28. modules.value.map((module) => {
  29. if (modules && modules.value.includes(module)) {
  30. hasModule = true
  31. }
  32. })
  33. return hasModule
  34. })
  35. /**
  36. * L'organization fait-elle partie du réseau CMF?
  37. *
  38. * @return {boolean}
  39. */
  40. const isCmf = computed( (): boolean => {
  41. return networks.value.filter((network: string) => {
  42. return network === process.env.cmf_network
  43. }).length > 0
  44. })
  45. /**
  46. * L'organization fait-elle partie du réseau FFEC?
  47. *
  48. * @return {boolean}
  49. */
  50. const isFfec = computed( (): boolean => {
  51. return networks.value.filter((network: string) => {
  52. return network === process.env.ffec_network
  53. }).length > 0
  54. })
  55. /**
  56. * L'organization fait-elle partie d'un réseau ?
  57. *
  58. * @return {boolean}
  59. */
  60. const isInsideNetwork = computed( (): boolean => {
  61. return isCmf.value || isFfec.value
  62. })
  63. /**
  64. * L'organization possède t'elle un produit premium
  65. * @return {boolean}
  66. */
  67. const isArtistProduct = computed( (): boolean => {
  68. return product.value === process.env.artist_product
  69. })
  70. /**
  71. * L'organization possède t'elle un produit artiste premium
  72. * @return {boolean}
  73. */
  74. const isArtistPremiumProduct = computed( (): boolean => {
  75. return product.value === process.env.artist_premium_product
  76. })
  77. /**
  78. * L'organization possède-t-elle un produit artiste ou artiste premium
  79. * @return {boolean}
  80. */
  81. const isArtist = computed( (): boolean => {
  82. return isArtistProduct.value || isArtistPremiumProduct.value
  83. })
  84. /**
  85. * L'organization possède-t-elle un produit school?
  86. *
  87. * @return {boolean}
  88. */
  89. const isSchoolProduct = computed( (): boolean => {
  90. return product.value === process.env.school_product
  91. })
  92. /**
  93. * L'organization possède-t-elle un produit school-premium?
  94. *
  95. * @return {boolean}
  96. */
  97. const isSchoolPremiumProduct = computed( (): boolean => {
  98. return product.value === process.env.school_premium_product
  99. })
  100. /**
  101. * L'organization possède-t-elle un produit school ou school-premium
  102. * @return {boolean}
  103. */
  104. const isSchool = computed( (): boolean => {
  105. return isSchoolProduct.value || isSchoolPremiumProduct.value
  106. })
  107. /**
  108. * L'organization possède t'elle un produit manager
  109. * @return {boolean}
  110. */
  111. const isManagerProduct = computed( (): boolean => {
  112. return product.value === process.env.manager_product
  113. })
  114. /**
  115. * L'organization peut-elle afficher la lister des adhérents avec leurs coordonnées
  116. * @return {boolean|null}
  117. */
  118. const isShowAdherentList = computed(():any => {
  119. return showAdherentList.value;
  120. })
  121. /**
  122. * L'organization est elle une association ?
  123. * @return {boolean|null}
  124. */
  125. const isAssociation = computed(():any => {
  126. return legalStatus.value === 'ASSOCIATION_LAW_1901';
  127. })
  128. /**
  129. * L'organization est-elle la CMF ?
  130. *
  131. * @return {boolean}
  132. */
  133. const isCMFCentralService = computed((): boolean => {
  134. if(process.env.CMF_ID)
  135. return id.value === parseInt(process.env.CMF_ID)
  136. return false
  137. })
  138. const getWebsite = computed((): string | null => {
  139. return website.value ?? null
  140. })
  141. // Actions
  142. const setProfile = (profile: any) => {
  143. id.value = profile.id
  144. parametersId.value = profile.parametersId
  145. name.value = profile.name
  146. product.value = profile.product
  147. currentActivityYear.value = profile.currentYear
  148. website.value = profile.website
  149. modules.value = profile.modules
  150. hasChildren.value = profile.hasChildren
  151. legalStatus.value = profile.legalStatus
  152. showAdherentList.value = profile.showAdherentList
  153. networks.value = profile.networks
  154. useEach(profile.parents, (parent) => {
  155. parents.value.push({
  156. id: parent.id,
  157. name: parent.name,
  158. website: parent.website
  159. })
  160. })
  161. }
  162. const refreshProfile = (profile: any) => {
  163. name.value = profile.name
  164. currentActivityYear.value = profile.currentYear
  165. website.value = profile.website
  166. legalStatus.value = profile.legalStatus
  167. }
  168. return {
  169. id,
  170. parametersId,
  171. name,
  172. product,
  173. currentActivityYear,
  174. modules,
  175. hasChildren,
  176. legalStatus,
  177. showAdherentList,
  178. networks,
  179. website,
  180. parents,
  181. hasModule,
  182. isCmf,
  183. isFfec,
  184. isInsideNetwork,
  185. isArtistProduct,
  186. isArtistPremiumProduct,
  187. isArtist,
  188. isSchoolPremiumProduct,
  189. isSchoolProduct,
  190. isSchool,
  191. isManagerProduct,
  192. isShowAdherentList,
  193. isAssociation,
  194. getWebsite,
  195. setProfile,
  196. refreshProfile
  197. }
  198. })