organization.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import * as _ from 'lodash'
  2. import { baseOrganizationState, organizationState } from '~/types/interfaces'
  3. export const state = () => ({
  4. id: null,
  5. name: '',
  6. product: '',
  7. modules: [],
  8. hasChildren: false,
  9. showAdherentList: false,
  10. networks: [],
  11. website: '',
  12. subDomain: '',
  13. parents: []
  14. })
  15. export const mutations = {
  16. setId (state: organizationState, id: number) {
  17. state.id = id
  18. },
  19. setName (state: organizationState, name: string) {
  20. state.name = name
  21. },
  22. setProduct (state: organizationState, product: string) {
  23. state.product = product
  24. },
  25. setModules (state: organizationState, modules: Array<string>) {
  26. state.modules = modules
  27. },
  28. setHasChildren (state: organizationState, hasChildren: boolean) {
  29. state.hasChildren = hasChildren
  30. },
  31. setShowAdherentList(state:organizationState, showAdherentList:boolean) {
  32. state.showAdherentList = showAdherentList
  33. },
  34. setNetworks(state:organizationState, networks:Array<string>) {
  35. state.networks = networks
  36. },
  37. setParents (state: organizationState, parents: Array<organizationState>) {
  38. state.parents = parents
  39. },
  40. setWebsite (state: organizationState, website: string) {
  41. state.website = website
  42. },
  43. setSubDomain (state: organizationState, subDomain: string) {
  44. state.subDomain = subDomain
  45. },
  46. addParent (state: organizationState, parent: organizationState) {
  47. state.parents.push(parent)
  48. }
  49. }
  50. export const actions = {
  51. setProfile (context: any, profile: any) {
  52. context.commit('setId', profile.id)
  53. context.commit('setName', profile.name)
  54. context.commit('setProduct', profile.product)
  55. context.commit('setWebsite', profile.website)
  56. context.commit('setSubDomain', profile.subDomain)
  57. context.commit('setModules', profile.modules)
  58. context.commit('setHasChildren', profile.hasChildren)
  59. context.commit('setShowAdherentList', profile.showAdherentList)
  60. context.commit('setNetworks', profile.networks)
  61. _.each(profile.parents, (parent) => {
  62. const p: baseOrganizationState = {
  63. id: parent.id,
  64. name: parent.name,
  65. website: parent.website,
  66. subDomain: parent.subDomain
  67. }
  68. context.commit('addParent', p)
  69. })
  70. }
  71. }