organizationProfile.ts 4.9 KB

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