workspaceList.js 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import {
  2. SET,
  3. UPDATE,
  4. WORKSPACE_LIST,
  5. USER_ROLE
  6. } from '../action-creator.sync.js'
  7. import { handleRouteFromApi } from '../helper.js'
  8. export function workspaceList (state = [], action) {
  9. switch (action.type) {
  10. case `${UPDATE}/${WORKSPACE_LIST}`:
  11. return action.workspaceList.map(ws => ({
  12. id: ws.workspace_id,
  13. label: ws.label,
  14. slug: ws.slug,
  15. // description: ws.description, // not returned by /api/v2/users/:idUser/workspaces
  16. sidebarEntry: ws.sidebar_entries.map(sbe => ({
  17. slug: sbe.slug,
  18. route: handleRouteFromApi(sbe.route),
  19. faIcon: sbe.fa_icon,
  20. hexcolor: sbe.hexcolor,
  21. label: sbe.label
  22. })),
  23. isOpenInSidebar: false
  24. }))
  25. case `${SET}/${WORKSPACE_LIST}/isOpenInSidebar`:
  26. return state.map(ws => ws.id === action.workspaceId
  27. ? {...ws, isOpenInSidebar: action.isOpenInSidebar}
  28. : ws
  29. )
  30. case `${SET}/${USER_ROLE}`: // not used yet
  31. return state.map(ws => {
  32. const foundWorkspace = action.userRole.find(r => ws.id === r.workspace.id) || {role: '', subscribed_to_notif: ''}
  33. return {
  34. ...ws,
  35. role: foundWorkspace.role,
  36. notif: foundWorkspace.subscribed_to_notif
  37. }
  38. })
  39. case `${UPDATE}/${USER_ROLE}/SubscriptionNotif`: // not used yet
  40. return state.map(ws => ws.id === action.workspaceId
  41. ? {...ws, notif: action.subscriptionNotif}
  42. : ws
  43. )
  44. default:
  45. return state
  46. }
  47. }
  48. export default workspaceList