user.js 882B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import {
  2. USER_CONNECTED,
  3. USER_DISCONNECTED,
  4. USER_DATA
  5. } from '../action-creator.sync.js'
  6. const defaultUser = {
  7. user_id: -1,
  8. logged: false, // undefined avoid to be redirected to /login while whoami ep has not responded yet
  9. timezone: '',
  10. profile: {
  11. id: 1,
  12. slug: 'user'
  13. },
  14. email: '',
  15. is_active: true,
  16. caldav_url: null,
  17. avatar_url: null,
  18. created: '',
  19. display_name: ''
  20. }
  21. export default function user (state = defaultUser, action) {
  22. switch (action.type) {
  23. case `Set/${USER_CONNECTED}`:
  24. return {
  25. ...action.user,
  26. avatar_url: 'https://www.algoo.fr/static/images/people_images/PERSO_SEUL.png' // @FIXME use avatar from api when db handles it
  27. }
  28. case `Set/${USER_DISCONNECTED}`:
  29. return defaultUser
  30. case `Update/${USER_DATA}`:
  31. return {...state, ...action.data}
  32. default:
  33. return state
  34. }
  35. }