workspaceList.js 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import {
  2. SET,
  3. UPDATE,
  4. USER_WORKSPACE_DO_NOTIFY,
  5. WORKSPACE_LIST,
  6. WORKSPACE_LIST_MEMBER
  7. } from '../action-creator.sync.js'
  8. import { handleRouteFromApi } from '../helper.js'
  9. export function workspaceList (state = [], action) {
  10. switch (action.type) {
  11. case `${SET}/${WORKSPACE_LIST}`:
  12. return action.workspaceList.map(ws => ({
  13. id: ws.workspace_id,
  14. label: ws.label,
  15. slug: ws.slug,
  16. // description: ws.description, // not returned by /api/v2/users/:idUser/workspaces
  17. sidebarEntry: ws.sidebar_entries.map(sbe => ({
  18. slug: sbe.slug,
  19. route: handleRouteFromApi(sbe.route),
  20. faIcon: sbe.fa_icon,
  21. hexcolor: sbe.hexcolor,
  22. label: sbe.label
  23. })),
  24. isOpenInSidebar: false,
  25. memberList: []
  26. }))
  27. case `${SET}/${WORKSPACE_LIST}/isOpenInSidebar`:
  28. return state.map(ws => ws.id === action.workspaceId
  29. ? {...ws, isOpenInSidebar: action.isOpenInSidebar}
  30. : ws
  31. )
  32. case `${SET}/${WORKSPACE_LIST_MEMBER}`:
  33. return state.map(ws => ({
  34. ...ws,
  35. memberList: action.workspaceListMemberList.find(wlml => wlml.idWorkspace === ws.id).memberList
  36. }))
  37. case `${UPDATE}/${USER_WORKSPACE_DO_NOTIFY}`:
  38. return state.map(ws => ws.id === action.idWorkspace
  39. ? {
  40. ...ws,
  41. memberList: ws.memberList.map(u => u.user_id === action.idUser
  42. ? {...u, do_notify: action.doNotify}
  43. : u
  44. )
  45. }
  46. : ws
  47. )
  48. default:
  49. return state
  50. }
  51. }
  52. export default workspaceList