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 = ref(null) const parametersId: Ref = ref(null) const name: Ref = ref(null) const product: Ref = ref(null) const currentActivityYear: Ref = ref(null) const modules: Ref> = ref([]) const hasChildren: Ref = ref(false) const legalStatus: Ref = ref(null) const showAdherentList: Ref = ref(false) const networks: Ref> = ref([]) const website: Ref = ref(null) const parents: Ref> = 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 } })