import {organizationState} from "~/types/types"; import * as _ from "lodash"; export const state = () => ({ name: '', product: '', modules: [], hasChildren: false, website: '', subDomain: '', parents: [] }) export const mutations = { setName(state:organizationState, name:string){ state.name = name }, setProduct(state:organizationState, product:string){ state.product = product }, setModules(state:organizationState, modules:Array) { state.modules = modules }, setHasChildren(state:organizationState, hasChildren:boolean) { state.hasChildren = hasChildren }, setParents(state:organizationState, parents:Array) { state.parents = parents }, setWebsite(state:organizationState, website:string) { state.website = website }, setSubDomain(state:organizationState, subDomain:string) { state.subDomain = subDomain }, addParent(state:organizationState, parent:organizationState) { state.parents.push(parent) } } export const actions = { setProfile(context:any, profile:any){ context.commit('setName', profile.name) context.commit('setProduct', profile.product) context.commit('setWebsite', profile.website) context.commit('setSubDomain', profile.subDomain) context.commit('setModules', profile.modules) context.commit('setHasChildren', profile.hasChildren) _.each(profile.parents, parent => { const p:organizationState = { name: parent.name, website: parent.website, subDomain: parent.subDomain, parents: [] } context.commit('addParent', p) }); } }