user.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { INIT_PAYMENTS_USER, INIT_PAYMENTS_COMPANY, RESET_USER} from '@/constants/actionTypes'
  2. import { SET_USER, SET_LOADING_USER } from '@/constants/mutationTypes'
  3. const initialState ={
  4. user: null,
  5. loadingUser: false,
  6. }
  7. const state = {
  8. user: initialState.user,
  9. loadingUser: initialState.loadingUser,
  10. }
  11. const getters = {
  12. /**
  13. * [user]
  14. * @param {[type]} state [description]
  15. * @return {[type]} [description]
  16. */
  17. user(state) {
  18. return state.user
  19. },
  20. /**
  21. * [loadingUser]
  22. * @param {[type]} state [description]
  23. * @return {[type]} [description]
  24. */
  25. loadingUser(state) {
  26. return state.loadingUser
  27. }
  28. }
  29. const mutations = {
  30. /**
  31. * [actions description]
  32. * @param {[type]} state [description]
  33. * @param {[type]} payload [description]
  34. */
  35. [SET_USER] (state, payload) {
  36. state.user = payload
  37. },
  38. /**
  39. * [actions description]
  40. * @param {[type]} state [description]
  41. * @param {[type]} payload [description]
  42. */
  43. [SET_LOADING_USER] (state, payload) {
  44. state.loadingUser = !!payload
  45. }
  46. }
  47. const actions ={
  48. /**
  49. * @param {*} param0
  50. * @param {*} payload
  51. */
  52. [INIT_PAYMENTS_USER] ({commit, dispatch}, payload) {
  53. commit(SET_USER, payload)
  54. commit(SET_LOADING_USER, payload)
  55. dispatch(INIT_PAYMENTS_COMPANY, payload)
  56. },
  57. /**
  58. *
  59. */
  60. [RESET_USER] ({ commit }) {
  61. commit(SET_USER, [])
  62. }
  63. }
  64. export default {
  65. state,
  66. getters,
  67. mutations,
  68. actions
  69. }