user.js 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import {
  2. SET,
  3. UPDATE,
  4. USER_CONNECTED,
  5. USER_DISCONNECTED,
  6. USER_DATA,
  7. USER_LANG
  8. } from '../action-creator.sync.js'
  9. const defaultUser = {
  10. user_id: -1,
  11. logged: null, // null avoid to be redirected to /login while whoami ep has not responded yet
  12. auth: '',
  13. timezone: '',
  14. profile: {
  15. id: 1,
  16. slug: 'user'
  17. },
  18. email: '',
  19. is_active: true,
  20. caldav_url: null,
  21. avatar_url: null,
  22. created: '',
  23. public_name: '',
  24. lang: 'en' // @FIXME Côme - 2018/07/30 - remove this line when api returns the lang (https://github.com/tracim/tracim/issues/734)
  25. }
  26. export default function user (state = defaultUser, action) {
  27. switch (action.type) {
  28. case `${SET}/${USER_CONNECTED}`:
  29. return {
  30. ...state,
  31. ...action.user,
  32. avatar_url: 'https://www.algoo.fr/static/images/people_images/PERSO_SEUL.png' // @FIXME use avatar from api when db handles it
  33. }
  34. case `${SET}/${USER_DISCONNECTED}`:
  35. return defaultUser
  36. case `${UPDATE}/${USER_DATA}`:
  37. return {...state, ...action.data}
  38. case `${SET}/${USER_LANG}`:
  39. return {...state, lang: action.lang}
  40. default:
  41. return state
  42. }
  43. }