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 }) => ...@@ -96,6 +96,7 @@ export const getUserPermissions = ({ currentUser }) =>
role: t.teamType.permissions, role: t.teamType.permissions,
})) }))
export const isAuthorConfirmed = ({ currentUser }) => export const userNotConfirmed = ({ currentUser }) =>
get(currentUser, 'isAuthenticated') &&
!currentUserIs({ currentUser }, 'staff') && !currentUserIs({ currentUser }, 'staff') &&
get(currentUser, 'user.isConfirmed') !get(currentUser, 'user.isConfirmed')
...@@ -4,9 +4,9 @@ import { connect } from 'react-redux' ...@@ -4,9 +4,9 @@ import { connect } from 'react-redux'
import { Icon, th } from '@pubsweet/ui' import { Icon, th } from '@pubsweet/ui'
import { withRouter } from 'react-router-dom' import { withRouter } from 'react-router-dom'
import styled, { withTheme } from 'styled-components' 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 = ({ const AppBar = ({
goTo, goTo,
...@@ -65,7 +65,7 @@ export default compose( ...@@ -65,7 +65,7 @@ export default compose(
withTheme, withTheme,
connect(state => ({ connect(state => ({
currentUser: get(state, 'currentUser.user'), currentUser: get(state, 'currentUser.user'),
isStaff: currentUserIs(state, 'staff'), shouldShowConfirmation: userNotConfirmed(state),
})), })),
withState('expanded', 'setExpanded', false), withState('expanded', 'setExpanded', false),
withHandlers({ withHandlers({
...@@ -77,10 +77,6 @@ export default compose( ...@@ -77,10 +77,6 @@ export default compose(
history.push(path) history.push(path)
}, },
}), }),
withProps(({ isStaff, currentUser, isAuthenticated }) => ({
shouldShowConfirmation:
isAuthenticated && !isStaff && !get(currentUser, 'isConfirmed'),
})),
)(AppBar) )(AppBar)
// #region styled-components // #region styled-components
......
import React from 'react' import React from 'react'
import { get } from 'lodash'
import styled from 'styled-components' import styled from 'styled-components'
import { Button, th } from '@pubsweet/ui' import { Button, th } from '@pubsweet/ui'
import { compose, withProps } from 'recompose' import { compose, withProps } from 'recompose'
...@@ -7,7 +6,6 @@ import { compose, withProps } from 'recompose' ...@@ -7,7 +6,6 @@ import { compose, withProps } from 'recompose'
import { DashboardItems, DashboardFilters } from './' import { DashboardItems, DashboardFilters } from './'
const Dashboard = ({ const Dashboard = ({
isStaff,
dashboard, dashboard,
currentUser, currentUser,
filterItems, filterItems,
...@@ -44,9 +42,8 @@ const Dashboard = ({ ...@@ -44,9 +42,8 @@ const Dashboard = ({
) )
export default compose( export default compose(
withProps(({ isStaff, dashboard, filterItems, currentUser }) => ({ withProps(({ dashboard, filterItems }) => ({
dashboardItems: filterItems(dashboard.all), dashboardItems: filterItems(dashboard.all),
canCreateDraft: isStaff || get(currentUser, 'isConfirmed'),
})), })),
)(Dashboard) )(Dashboard)
......
...@@ -9,13 +9,13 @@ import { compose, withContext } from 'recompose' ...@@ -9,13 +9,13 @@ import { compose, withContext } from 'recompose'
import { newestFirst, selectCurrentUser } from 'xpub-selectors' import { newestFirst, selectCurrentUser } from 'xpub-selectors'
import { createDraftSubmission } from 'pubsweet-component-wizard/src/redux/conversion' import { createDraftSubmission } from 'pubsweet-component-wizard/src/redux/conversion'
import { Dashboard } from './'
import { getHandlingEditors } from '../../redux/editors'
import { import {
currentUserIs, userNotConfirmed,
getUserPermissions, 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' import { priorityFilter, importanceSort, withFiltersHOC } from '../Filters'
export default compose( export default compose(
...@@ -24,7 +24,7 @@ export default compose( ...@@ -24,7 +24,7 @@ export default compose(
state => { state => {
const { collections, conversion } = state const { collections, conversion } = state
const currentUser = selectCurrentUser(state) const currentUser = selectCurrentUser(state)
const isStaff = currentUserIs(state, 'staff') const canCreateDraft = !userNotConfirmed(state)
const sortedCollections = newestFirst(collections) const sortedCollections = newestFirst(collections)
const dashboard = { const dashboard = {
...@@ -45,11 +45,11 @@ export default compose( ...@@ -45,11 +45,11 @@ export default compose(
} }
const userPermissions = getUserPermissions(state) const userPermissions = getUserPermissions(state)
return { return {
isStaff,
dashboard, dashboard,
conversion, conversion,
collections, collections,
currentUser, currentUser,
canCreateDraft,
userPermissions, 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