currentWorkspace.js 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import {
  2. SET,
  3. WORKSPACE_DETAIL,
  4. WORKSPACE_MEMBER_LIST,
  5. WORKSPACE_READ_STATUS_LIST, WORKSPACE_RECENT_ACTIVITY_FOR_USER_LIST,
  6. WORKSPACE_RECENT_ACTIVITY_LIST
  7. } from '../action-creator.sync.js'
  8. import { handleRouteFromApi } from '../helper.js'
  9. const defaultWorkspace = {
  10. id: 0,
  11. slug: '',
  12. label: '',
  13. description: '',
  14. sidebarEntryList: [],
  15. memberList: [],
  16. recentActivityList: [],
  17. recentActivityForUserList: [],
  18. contentReadStatusList: []
  19. }
  20. export default function currentWorkspace (state = defaultWorkspace, action) {
  21. switch (action.type) {
  22. case `${SET}/${WORKSPACE_DETAIL}`:
  23. return {
  24. ...state,
  25. id: action.workspaceDetail.workspace_id,
  26. slug: action.workspaceDetail.slug,
  27. label: action.workspaceDetail.label,
  28. description: action.workspaceDetail.description,
  29. sidebarEntryList: action.workspaceDetail.sidebar_entries.map(sbe => ({
  30. slug: sbe.slug,
  31. route: handleRouteFromApi(sbe.route),
  32. faIcon: sbe.fa_icon,
  33. hexcolor: sbe.hexcolor,
  34. label: sbe.label
  35. }))
  36. }
  37. case `${SET}/${WORKSPACE_MEMBER_LIST}`:
  38. return {
  39. ...state,
  40. memberList: action.workspaceMemberList.map(m => ({
  41. id: m.user_id,
  42. publicName: m.user.public_name,
  43. avatarUrl: m.user.avatar_url,
  44. role: m.role,
  45. isActive: m.is_active
  46. }))
  47. }
  48. case `${SET}/${WORKSPACE_RECENT_ACTIVITY_LIST}`:
  49. return {
  50. ...state,
  51. recentActivityList: action.workspaceRecentActivityList.map(ra => ({
  52. id: ra.content_id,
  53. slug: ra.slug,
  54. label: ra.label,
  55. type: ra.content_type,
  56. idParent: ra.parent_id,
  57. showInUi: ra.show_in_ui,
  58. isArchived: ra.is_archived,
  59. isDeleted: ra.is_deleted,
  60. statusSlug: ra.status,
  61. subContentTypeSlug: ra.sub_content_types
  62. }))
  63. }
  64. case `${SET}/${WORKSPACE_RECENT_ACTIVITY_FOR_USER_LIST}`:
  65. return {
  66. ...state,
  67. recentActivityForUserList: action.workspaceRecentActivityForUserList.map(ra => ({
  68. id: ra.content_id,
  69. slug: ra.slug,
  70. label: ra.label,
  71. type: ra.content_type,
  72. idParent: ra.parent_id,
  73. showInUi: ra.show_in_ui,
  74. isArchived: ra.is_archived,
  75. isDeleted: ra.is_deleted,
  76. statusSlug: ra.status,
  77. subContentTypeSlug: ra.sub_content_types
  78. }))
  79. }
  80. case `${SET}/${WORKSPACE_READ_STATUS_LIST}`:
  81. return {
  82. ...state,
  83. contentReadStatusList: action.workspaceReadStatusList
  84. .filter(content => content.read_by_user)
  85. .map(content => content.content_id)
  86. }
  87. default:
  88. return state
  89. }
  90. }