| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- import type { BaseOrganizationProfile } from '~/types/interfaces'
- import { defineStore } from "pinia";
- import {computed} from "@vue/reactivity";
- import type {Ref} from "@vue/reactivity";
- import * as _ from 'lodash-es'
- import {LEGAL_STATUS, NETWORK, ORGANIZATION_ID, PRODUCT} from '~/types/enum/enums';
- export const useOrganizationProfileStore = defineStore('organizationProfile', () => {
- // State
- const id: Ref<number | null> = ref(null)
- const parametersId: Ref<number | null> = ref(null)
- const name: Ref<string | null> = ref(null)
- const product: Ref<string | null> = ref(null)
- const currentActivityYear: Ref<number | null> = ref(null)
- const modules: Ref<Array<string>> = ref([])
- const hasChildren: Ref<boolean | null> = ref(false)
- const legalStatus: Ref<string | null> = ref(null)
- const showAdherentList: Ref<boolean | null> = ref(false)
- const networks: Ref<Array<string>> = ref([])
- const website: Ref<string | null> = ref(null)
- const parents: Ref<Array<BaseOrganizationProfile>> = ref([])
- // Getters
- /**
- * L'organization fait-elle partie du réseau CMF ?
- *
- * @return {boolean}
- */
- const isCmf = computed( (): boolean => {
- return networks.value && networks.value.filter((network: string) => {
- return network === NETWORK.CMF
- }).length > 0
- })
- /**
- * L'organization fait-elle partie du réseau FFEC ?
- *
- * @return {boolean}
- */
- const isFfec = computed( (): boolean => {
- return networks.value && networks.value.filter((network: string) => {
- return network === NETWORK.FFEC
- }).length > 0
- })
- /**
- * L'organization fait-elle partie d'un réseau ?
- *
- * @return {boolean}
- */
- const isInsideNetwork = computed( (): boolean => {
- return isCmf.value || isFfec.value
- })
- /**
- * L'organization possède t'elle un produit premium
- * @return {boolean}
- */
- const isArtistProduct = computed( (): boolean => {
- return product.value === PRODUCT.ARTIST
- })
- /**
- * L'organization possède t'elle un produit artiste premium
- * @return {boolean}
- */
- const isArtistPremiumProduct = computed( (): boolean => {
- return product.value === PRODUCT.ARTIST_PREMIUM
- })
- /**
- * L'organization possède-t-elle un produit artiste ou artiste premium
- * @return {boolean}
- */
- const isArtist = computed( (): boolean => {
- return isArtistProduct.value || isArtistPremiumProduct.value
- })
- /**
- * L'organization possède-t-elle un produit school?
- *
- * @return {boolean}
- */
- const isSchoolProduct = computed( (): boolean => {
- return product.value === PRODUCT.SCHOOL
- })
- /**
- * L'organization possède-t-elle un produit school-premium?
- *
- * @return {boolean}
- */
- const isSchoolPremiumProduct = computed( (): boolean => {
- return product.value === PRODUCT.SCHOOL_PREMIUM
- })
- /**
- * L'organization possède-t-elle un produit school ou school-premium
- * @return {boolean}
- */
- const isSchool = computed( (): boolean => {
- return isSchoolProduct.value || isSchoolPremiumProduct.value
- })
- /**
- * L'organization possède-t-elle un produit manager
- * @return {boolean}
- */
- const isManagerProduct = computed( (): boolean => {
- return product.value === PRODUCT.MANAGER
- })
- /**
- * L'organization peut-elle afficher la lister des adhérents avec leurs coordonnées
- * @return {boolean|null}
- */
- const isShowAdherentList = computed(():any => {
- return showAdherentList.value;
- })
- /**
- * L'organization est elle une association ?
- * @return {boolean|null}
- */
- const isAssociation = computed(():any => {
- return legalStatus.value === LEGAL_STATUS.ASSOCIATION_LAW_1901;
- })
- /**
- * L'organization est-elle la CMF ?
- *
- * @return {boolean}
- */
- const isCMFCentralService = computed((): boolean => {
- return id.value === ORGANIZATION_ID.CMF
- })
- const getWebsite = computed((): string | null => {
- return website.value ?? null
- })
- const hasModule = (module: string): boolean => {
- return modules.value && modules.value.includes(module)
- }
- /**
- * /!\ Server side only
- * @param profile
- */
- const initiateProfile = (profile: any) => {
- setProfile(profile)
- // >>> Triggers a listener in plugins/ability
- }
- // Actions
- const setProfile = (profile: any) => {
- id.value = profile.id
- parametersId.value = profile.parametersId
- name.value = profile.name
- product.value = profile.product
- currentActivityYear.value = profile.currentYear
- website.value = profile.website
- modules.value = Array.from(profile.modules)
- hasChildren.value = profile.hasChildren
- legalStatus.value = profile.legalStatus
- showAdherentList.value = profile.showAdherentList
- networks.value = Array.from(profile.networks)
- _.each(profile.parents, (parent) => {
- parents.value.push({
- id: parent.id,
- name: parent.name,
- website: parent.website
- })
- })
- }
- const refreshProfile = (profile: any) => {
- name.value = profile.name
- currentActivityYear.value = profile.currentYear
- website.value = profile.website
- legalStatus.value = profile.legalStatus
- }
- return {
- id,
- parametersId,
- name,
- product,
- currentActivityYear,
- modules,
- hasChildren,
- legalStatus,
- showAdherentList,
- networks,
- website,
- parents,
- isCmf,
- isCMFCentralService,
- isFfec,
- isInsideNetwork,
- isArtistProduct,
- isArtistPremiumProduct,
- isArtist,
- isSchoolPremiumProduct,
- isSchoolProduct,
- isSchool,
- isManagerProduct,
- isShowAdherentList,
- isAssociation,
- getWebsite,
- hasModule,
- setProfile,
- refreshProfile,
- initiateProfile
- }
- })
|