organizationProfile.ts 5.0 KB

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