import { BaseOrganizationProfile } from '~/types/interfaces' import { defineStore } from "pinia"; import {computed, Ref} from "@vue/reactivity"; import {useEach} from "#imports"; export const useOrganizationProfileStore = defineStore('organizationProfile', () => { // State const id = ref(null) const parametersId = ref(null) const name = ref(null) const product = ref(null) const currentActivityYear = ref(null) const modules = ref([]) const hasChildren = ref(false) const legalStatus = ref(null) const showAdherentList = ref(false) const networks = ref([]) const website = 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.filter((network: string) => { return network === process.env.cmf_network }).length > 0 }) /** * L'organization fait-elle partie du réseau FFEC? * * @return {boolean} */ const isFfec = computed( (): boolean => { return networks.value.filter((network: string) => { return network === process.env.ffec_network }).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 === process.env.artist_product }) /** * L'organization possède t'elle un produit artiste premium * @return {boolean} */ const isArtistPremiumProduct = computed( (): boolean => { return product.value === process.env.artist_premium_product }) /** * 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 === process.env.school_product }) /** * L'organization possède-t-elle un produit school-premium? * * @return {boolean} */ const isSchoolPremiumProduct = computed( (): boolean => { return product.value === process.env.school_premium_product }) /** * 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 === process.env.manager_product }) /** * 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 === 'ASSOCIATION_LAW_1901'; }) /** * L'organization est-elle la CMF ? * * @return {boolean} */ const isCMFCentralService = computed((): boolean => { if(process.env.CMF_ID) return id.value === parseInt(process.env.CMF_ID) return false }) const getWebsite = computed((): string | null => { return website.value ?? null }) // 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 = profile.modules hasChildren.value = profile.hasChildren legalStatus.value = profile.legalStatus showAdherentList.value = profile.showAdherentList networks.value = profile.networks useEach(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, isFfec, isInsideNetwork, isArtistProduct, isArtistPremiumProduct, isArtist, isSchoolPremiumProduct, isSchoolProduct, isSchool, isManagerProduct, isShowAdherentList, isAssociation, getWebsite, setProfile, refreshProfile } })