organizationProfile.ts 5.3 KB

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