Skip to content
Snippets Groups Projects
Commit 6e8be203 authored by Bogdan Cochior's avatar Bogdan Cochior
Browse files

Merge branch 'sign-up' of https://gitlab.coko.foundation/xpub/xpub-faraday into sign-up

parents 556bf0c3 fda60ee1
No related branches found
No related tags found
2 merge requests!13Sprint #14,!12Signup functionality
...@@ -97,3 +97,7 @@ export const getUserPermissions = ({ currentUser }) => ...@@ -97,3 +97,7 @@ export const getUserPermissions = ({ currentUser }) =>
objectType: t.object.type, objectType: t.object.type,
role: t.teamType.permissions, role: t.teamType.permissions,
})) }))
export const isAuthorConfirmed = ({ currentUser }) =>
!currentUserIs({ currentUser }, 'staff') &&
get(currentUser, 'user.isConfirmed')
...@@ -4,65 +4,113 @@ import { connect } from 'react-redux' ...@@ -4,65 +4,113 @@ 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, compose } from 'recompose' import { withState, withHandlers, withProps, compose } from 'recompose'
import { currentUserIs } from '../../../../component-faraday-selectors/src'
const AppBar = ({ const AppBar = ({
goTo,
user,
brand,
theme,
expanded, expanded,
toggleMenu, toggleMenu,
brand,
user,
goTo,
currentUser, currentUser,
onLogoutClick, onLogoutClick,
theme, shouldShowConfirmation,
}) => ( }) => (
<Root> <Root className="appbar">
<Brand> <Row bordered className="row">
{React.cloneElement(brand, { <Brand>
onClick: goTo('/'), {React.cloneElement(brand, {
})} onClick: goTo('/'),
</Brand> })}
{user && ( </Brand>
<User> {user && (
<div onClick={toggleMenu}> <User>
<Icon color={theme.colorText}>user</Icon> <div onClick={toggleMenu}>
<span> <Icon color={theme.colorText}>user</Icon>
{get(user, 'firstName') || get(user, 'username') || 'User'} <span>
</span> {get(user, 'firstName') || get(user, 'username') || 'User'}
<Icon color={theme.colorText}>chevron-down</Icon> </span>
</div> <Icon color={theme.colorText}>chevron-down</Icon>
{expanded && ( </div>
<Dropdown> {expanded && (
<DropdownOption>Settings</DropdownOption> <Dropdown>
{currentUser.admin && ( <DropdownOption>Settings</DropdownOption>
<DropdownOption onClick={goTo('/admin')}> {currentUser.admin && (
Admin dashboard <DropdownOption onClick={goTo('/admin')}>
</DropdownOption> Admin dashboard
)} </DropdownOption>
<DropdownOption onClick={onLogoutClick}>Logout</DropdownOption> )}
</Dropdown> <DropdownOption onClick={onLogoutClick}>Logout</DropdownOption>
)} </Dropdown>
</User> )}
</User>
)}
</Row>
{shouldShowConfirmation && (
<Row bgColor="salmon" centered className="row">
<ConfirmationText>
Your author account is not confirmed. Check your email.
</ConfirmationText>
</Row>
)} )}
{expanded && <ToggleOverlay onClick={toggleMenu} />} {expanded && <ToggleOverlay onClick={toggleMenu} />}
</Root> </Root>
) )
export default compose(
withRouter,
withTheme,
connect(state => ({
currentUser: get(state, 'currentUser.user'),
isStaff: currentUserIs(state, 'staff'),
})),
withState('expanded', 'setExpanded', false),
withHandlers({
toggleMenu: ({ setExpanded }) => () => {
setExpanded(v => !v)
},
goTo: ({ setExpanded, history }) => path => () => {
setExpanded(v => false)
history.push(path)
},
}),
withProps(({ isStaff, currentUser, isAuthenticated }) => ({
shouldShowConfirmation:
isAuthenticated && !isStaff && !get(currentUser, 'isConfirmed'),
})),
)(AppBar)
// #region styled-components // #region styled-components
const Root = styled.div` const Root = styled.div`
align-items: center; align-items: center;
box-shadow: ${th('dropShadow')}; background-color: #ffffff;
font-family: ${th('fontInterface')}; font-family: ${th('fontInterface')};
display: flex; display: flex;
justify-content: space-between; flex-direction: column;
height: 60px;
flex-grow: 1; flex-grow: 1;
width: 100vw;
position: fixed; position: fixed;
width: 100%; top: 0;
z-index: 10; z-index: 10;
background-color: #ffffff;
` `
const Row = styled.div`
align-items: center;
align-self: stretch;
background-color: ${({ bgColor }) => bgColor || 'transparent'};
box-shadow: ${({ bordered }) => (bordered ? th('dropShadow') : 'none')};
display: flex;
justify-content: ${({ centered }) =>
centered ? 'center' : 'space-between;'};
`
const ConfirmationText = styled.span`
font-size: ${th('fontSizeBaseSmall')};
`
const Brand = styled.div` const Brand = styled.div`
padding: 10px 20px; padding: 10px 20px;
cursor: pointer; cursor: pointer;
...@@ -126,21 +174,3 @@ const ToggleOverlay = styled.div` ...@@ -126,21 +174,3 @@ const ToggleOverlay = styled.div`
opacity: 0; opacity: 0;
` `
// #endregion // #endregion
export default compose(
withRouter,
withTheme,
connect(state => ({
currentUser: get(state, 'currentUser.user'),
})),
withState('expanded', 'setExpanded', false),
withHandlers({
toggleMenu: ({ setExpanded }) => () => {
setExpanded(v => !v)
},
goTo: ({ setExpanded, history }) => path => () => {
setExpanded(v => false)
history.push(path)
},
}),
)(AppBar)
...@@ -7,6 +7,7 @@ import { DashboardItems, DashboardFilters } from './' ...@@ -7,6 +7,7 @@ import { DashboardItems, DashboardFilters } from './'
const Dashboard = ({ const Dashboard = ({
dashboard, dashboard,
currentUser,
filterItems, filterItems,
filterValues, filterValues,
deleteProject, deleteProject,
...@@ -16,7 +17,7 @@ const Dashboard = ({ ...@@ -16,7 +17,7 @@ const Dashboard = ({
getDefaultFilterValue, getDefaultFilterValue,
createDraftSubmission, createDraftSubmission,
}) => ( }) => (
<Root> <Root className="dashboard">
<Header> <Header>
<Heading>Manuscripts</Heading> <Heading>Manuscripts</Heading>
<HeaderButtons> <HeaderButtons>
...@@ -50,6 +51,7 @@ const Root = styled.div` ...@@ -50,6 +51,7 @@ const Root = styled.div`
flex-direction: column; flex-direction: column;
margin: auto; margin: auto;
max-width: 60em; max-width: 60em;
overflow: auto;
` `
const Header = styled.div` const Header = styled.div`
......
...@@ -37,6 +37,7 @@ export default compose( ...@@ -37,6 +37,7 @@ export default compose(
reviewer => reviewer && reviewer.user === currentUser.id, reviewer => reviewer && reviewer.user === currentUser.id,
), ),
), ),
all: sortedCollections, all: sortedCollections,
} }
const userPermissions = getUserPermissions(state) const userPermissions = getUserPermissions(state)
......
import React from 'react' import React from 'react'
import { compose, lifecycle } from 'recompose' import { connect } from 'react-redux'
import { Button } from '@pubsweet/ui'
import styled from 'styled-components'
import { th } from '@pubsweet/ui-toolkit'
import { compose, lifecycle, withState } from 'recompose'
import { parseSearchParams } from '../utils' import { parseSearchParams } from '../utils'
import { confirmUser } from '../../redux/users' import { confirmUser } from '../../redux/users'
const ConfirmAccount = ({ location }) => <div>confirm</div> const ConfirmAccount = ({ location, message, history }) => (
<Root>
<Title>{message}</Title>
<Button onClick={() => history.replace('/')} primary>
Go to Dashboard
</Button>
</Root>
)
const confirmMessage = `Your account has been successfully confirmed. Welcome to Hindawi!`
const errorMessage = `Something went wrong with your account confirmation. Please try again.`
export default compose( export default compose(
connect(null, { confirmUser }),
withState('message', 'setConfirmMessage', 'Loading...'),
lifecycle({ lifecycle({
componentDidMount() { componentDidMount() {
const { location } = this.props const { location, confirmUser, setConfirmMessage } = this.props
const { confirmationToken, userId } = parseSearchParams(location.search) const { confirmationToken, userId } = parseSearchParams(location.search)
if (userId) { if (userId) {
confirmUser(userId, confirmationToken) confirmUser(userId, confirmationToken)
.then(() => {
setConfirmMessage(confirmMessage)
})
.catch(() => {
// errors are still gobbled up by pubsweet
setConfirmMessage(errorMessage)
})
} }
}, },
}), }),
)(ConfirmAccount) )(ConfirmAccount)
// #region styled components
const Root = styled.div`
color: ${th('colorText')};
margin: 0 auto;
text-align: center;
width: 70vw;
a {
color: ${th('colorText')};
}
`
const Title = styled.div`
color: ${th('colorPrimary')};
font-size: ${th('fontSizeHeading5')};
font-family: ${th('fontHeading')};
margin: 10px auto;
`
// #endregion
import { get } from 'lodash' import { get } from 'lodash'
import { create } from 'pubsweet-client/src/helpers/api' import { create } from 'pubsweet-client/src/helpers/api'
const LOGIN_SUCCESS = 'LOGIN_SUCCESS'
const loginSuccess = user => ({
type: LOGIN_SUCCESS,
token: user.token,
user,
})
export const currentUserIs = (state, role) => export const currentUserIs = (state, role) =>
get(state, `currentUser.user.${role}`) get(state, `currentUser.user.${role}`)
export const confirmUser = (userId, confirmationToken) => export const confirmUser = (userId, confirmationToken) => dispatch =>
create(`/users/confirm`, { create(`/users/confirm`, {
userId, userId,
confirmationToken, confirmationToken,
}).then(user => {
localStorage.setItem('token', user.token)
return dispatch(loginSuccess(user))
}) })
...@@ -6,14 +6,21 @@ import { actions } from 'pubsweet-client' ...@@ -6,14 +6,21 @@ import { actions } from 'pubsweet-client'
import { withJournal } from 'xpub-journal' import { withJournal } from 'xpub-journal'
import { AppBar } from 'pubsweet-components-faraday/src/components' import { AppBar } from 'pubsweet-components-faraday/src/components'
const App = ({ children, currentUser, journal, logoutUser }) => ( const App = ({
<Root> journal,
children,
logoutUser,
currentUser,
isAuthenticated,
}) => (
<Root className="faraday-root">
<AppBar <AppBar
brand={journal.metadata.name} brand={journal.metadata.name}
isAuthenticated={isAuthenticated}
onLogoutClick={logoutUser} onLogoutClick={logoutUser}
user={currentUser} user={currentUser}
/> />
<MainContainer>{children}</MainContainer> <MainContainer className="faraday-main">{children}</MainContainer>
</Root> </Root>
) )
...@@ -21,6 +28,7 @@ export default compose( ...@@ -21,6 +28,7 @@ export default compose(
connect( connect(
state => ({ state => ({
currentUser: state.currentUser.user, currentUser: state.currentUser.user,
isAuthenticated: state.currentUser.isAuthenticated,
}), }),
{ logoutUser: actions.logoutUser }, { logoutUser: actions.logoutUser },
), ),
...@@ -35,7 +43,7 @@ const Root = styled.div` ...@@ -35,7 +43,7 @@ const Root = styled.div`
` `
const MainContainer = styled.div` const MainContainer = styled.div`
padding: 90px 10px 40px;
min-height: 100vh;
background-color: ${props => props.theme.backgroundColor || '#fff'}; background-color: ${props => props.theme.backgroundColor || '#fff'};
padding: 110px 10px 0 10px;
height: 100vh;
` `
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