currentWorkspace.js 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import {SET, WORKSPACE_DETAIL, WORKSPACE_MEMBER_LIST} from '../action-creator.sync.js'
  2. import { handleRouteFromApi } from '../helper.js'
  3. const defaultWorkspace = {
  4. id: 0,
  5. slug: '',
  6. label: '',
  7. description: '',
  8. sidebarEntries: [],
  9. member: []
  10. }
  11. export default function currentWorkspace (state = defaultWorkspace, action) {
  12. switch (action.type) {
  13. case `${SET}/${WORKSPACE_DETAIL}`:
  14. return {
  15. ...state,
  16. id: action.workspaceDetail.workspace_id,
  17. slug: action.workspaceDetail.slug,
  18. label: action.workspaceDetail.label,
  19. description: action.workspaceDetail.description,
  20. sidebarEntries: action.workspaceDetail.sidebar_entries.map(sbe => ({
  21. slug: sbe.slug,
  22. route: handleRouteFromApi(sbe.route),
  23. faIcon: sbe.fa_icon,
  24. hexcolor: sbe.hexcolor,
  25. label: sbe.label
  26. }))
  27. }
  28. case `${SET}/${WORKSPACE_MEMBER_LIST}`:
  29. return {
  30. ...state,
  31. member: action.workspaceMemberList.map(m => ({
  32. id: m.user_id,
  33. publicName: m.user.public_name,
  34. avatarUrl: m.user.avatar_url,
  35. role: m.role,
  36. isActive: m.is_active,
  37. }))
  38. }
  39. default:
  40. return state
  41. }
  42. }