organization.ts 2.4 KB

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