organization.ts 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. legalStatus: '',
  11. showAdherentList: false,
  12. networks: [],
  13. website: '',
  14. subDomain: '',
  15. parents: []
  16. })
  17. export const mutations = {
  18. setId (state: organizationState, id: number) {
  19. state.id = id
  20. },
  21. setName (state: organizationState, name: string) {
  22. state.name = name
  23. },
  24. setProduct (state: organizationState, product: string) {
  25. state.product = product
  26. },
  27. setCurrentActivityYear (state: organizationState, currentActivityYear: number) {
  28. state.currentActivityYear = currentActivityYear
  29. },
  30. setModules (state: organizationState, modules: Array<string>) {
  31. state.modules = modules
  32. },
  33. setHasChildren (state: organizationState, hasChildren: boolean) {
  34. state.hasChildren = hasChildren
  35. },
  36. setShowAdherentList(state:organizationState, showAdherentList:boolean) {
  37. state.showAdherentList = showAdherentList
  38. },
  39. setLegalStatus(state:organizationState, legalStatus:string) {
  40. state.legalStatus = legalStatus
  41. },
  42. setNetworks(state:organizationState, networks:Array<string>) {
  43. state.networks = networks
  44. },
  45. setParents (state: organizationState, parents: Array<organizationState>) {
  46. state.parents = parents
  47. },
  48. setWebsite (state: organizationState, website: string) {
  49. state.website = website
  50. },
  51. setSubDomain (state: organizationState, subDomain: string) {
  52. state.subDomain = subDomain
  53. },
  54. addParent (state: organizationState, parent: organizationState) {
  55. state.parents.push(parent)
  56. }
  57. }
  58. export const actions = {
  59. setProfile (context: any, profile: any) {
  60. context.commit('setId', profile.id)
  61. context.commit('setName', profile.name)
  62. context.commit('setProduct', profile.product)
  63. context.commit('setCurrentActivityYear', profile.currentYear)
  64. context.commit('setWebsite', profile.website)
  65. context.commit('setSubDomain', profile.subDomain)
  66. context.commit('setModules', profile.modules)
  67. context.commit('setHasChildren', profile.hasChildren)
  68. context.commit('setLegalStatus', profile.legalStatus)
  69. context.commit('setShowAdherentList', profile.showAdherentList)
  70. context.commit('setNetworks', profile.networks)
  71. _.each(profile.parents, (parent) => {
  72. const p: baseOrganizationState = {
  73. id: parent.id,
  74. name: parent.name,
  75. website: parent.website,
  76. subDomain: parent.subDomain
  77. }
  78. context.commit('addParent', p)
  79. })
  80. }
  81. }