organizationProfile.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. // Actions
  131. const setProfile = (profile: any) => {
  132. id.value = profile.id
  133. parametersId.value = profile.parametersId
  134. name.value = profile.name
  135. product.value = profile.product
  136. currentActivityYear.value = profile.currentYear
  137. website.value = profile.website
  138. modules.value = Array.from(profile.modules)
  139. hasChildren.value = profile.hasChildren
  140. legalStatus.value = profile.legalStatus
  141. showAdherentList.value = profile.showAdherentList
  142. networks.value = Array.from(profile.networks)
  143. _.each(profile.parents, (parent) => {
  144. parents.value.push({
  145. id: parent.id,
  146. name: parent.name,
  147. website: parent.website
  148. })
  149. })
  150. }
  151. const refreshProfile = (profile: any) => {
  152. name.value = profile.name
  153. currentActivityYear.value = profile.currentYear
  154. website.value = profile.website
  155. legalStatus.value = profile.legalStatus
  156. }
  157. return {
  158. id,
  159. parametersId,
  160. name,
  161. product,
  162. currentActivityYear,
  163. modules,
  164. hasChildren,
  165. legalStatus,
  166. showAdherentList,
  167. networks,
  168. website,
  169. parents,
  170. isCmf,
  171. isFfec,
  172. isInsideNetwork,
  173. isArtistProduct,
  174. isArtistPremiumProduct,
  175. isArtist,
  176. isSchoolPremiumProduct,
  177. isSchoolProduct,
  178. isSchool,
  179. isManagerProduct,
  180. isShowAdherentList,
  181. isAssociation,
  182. getWebsite,
  183. hasModule,
  184. setProfile,
  185. refreshProfile
  186. }
  187. })