user.js 1.1KB

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