organizationProfile.ts 5.6 KB

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