Skip to content
Snippets Groups Projects
Commit 614cccd4 authored by Alexandru Munteanu's avatar Alexandru Munteanu
Browse files

refactor(dashboard): refactor selectors

parent f921518b
No related branches found
No related tags found
2 merge requests!13Sprint #14,!12Signup functionality
......@@ -96,6 +96,7 @@ export const getUserPermissions = ({ currentUser }) =>
role: t.teamType.permissions,
}))
export const isAuthorConfirmed = ({ currentUser }) =>
export const userNotConfirmed = ({ currentUser }) =>
get(currentUser, 'isAuthenticated') &&
!currentUserIs({ currentUser }, 'staff') &&
get(currentUser, 'user.isConfirmed')
!get(currentUser, 'user.isConfirmed')
......@@ -4,9 +4,9 @@ import { connect } from 'react-redux'
import { Icon, th } from '@pubsweet/ui'
import { withRouter } from 'react-router-dom'
import styled, { withTheme } from 'styled-components'
import { withState, withHandlers, withProps, compose } from 'recompose'
import { withState, withHandlers, compose } from 'recompose'
import { currentUserIs } from '../../../../component-faraday-selectors/src'
import { userNotConfirmed } from 'pubsweet-component-faraday-selectors'
const AppBar = ({
goTo,
......@@ -65,7 +65,7 @@ export default compose(
withTheme,
connect(state => ({
currentUser: get(state, 'currentUser.user'),
isStaff: currentUserIs(state, 'staff'),
shouldShowConfirmation: userNotConfirmed(state),
})),
withState('expanded', 'setExpanded', false),
withHandlers({
......@@ -77,10 +77,6 @@ export default compose(
history.push(path)
},
}),
withProps(({ isStaff, currentUser, isAuthenticated }) => ({
shouldShowConfirmation:
isAuthenticated && !isStaff && !get(currentUser, 'isConfirmed'),
})),
)(AppBar)
// #region styled-components
......
import React from 'react'
import { get } from 'lodash'
import styled from 'styled-components'
import { Button, th } from '@pubsweet/ui'
import { compose, withProps } from 'recompose'
......@@ -7,7 +6,6 @@ import { compose, withProps } from 'recompose'
import { DashboardItems, DashboardFilters } from './'
const Dashboard = ({
isStaff,
dashboard,
currentUser,
filterItems,
......@@ -44,9 +42,8 @@ const Dashboard = ({
)
export default compose(
withProps(({ isStaff, dashboard, filterItems, currentUser }) => ({
withProps(({ dashboard, filterItems }) => ({
dashboardItems: filterItems(dashboard.all),
canCreateDraft: isStaff || get(currentUser, 'isConfirmed'),
})),
)(Dashboard)
......
......@@ -9,13 +9,13 @@ import { compose, withContext } from 'recompose'
import { newestFirst, selectCurrentUser } from 'xpub-selectors'
import { createDraftSubmission } from 'pubsweet-component-wizard/src/redux/conversion'
import { Dashboard } from './'
import { getHandlingEditors } from '../../redux/editors'
import {
currentUserIs,
userNotConfirmed,
getUserPermissions,
} from '../../../../component-faraday-selectors/src'
} from 'pubsweet-component-faraday-selectors'
import { Dashboard } from './'
import { getHandlingEditors } from '../../redux/editors'
import { priorityFilter, importanceSort, withFiltersHOC } from '../Filters'
export default compose(
......@@ -24,7 +24,7 @@ export default compose(
state => {
const { collections, conversion } = state
const currentUser = selectCurrentUser(state)
const isStaff = currentUserIs(state, 'staff')
const canCreateDraft = !userNotConfirmed(state)
const sortedCollections = newestFirst(collections)
const dashboard = {
......@@ -45,11 +45,11 @@ export default compose(
}
const userPermissions = getUserPermissions(state)
return {
isStaff,
dashboard,
conversion,
collections,
currentUser,
canCreateDraft,
userPermissions,
}
},
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment