workspaceList.js 1.4KB

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