#304: show Create new account link on LoginPanel for authorized users

This commit is contained in:
SleepWalker 2017-03-03 07:48:25 +02:00
parent e9e04d8336
commit fbcc2a740c
5 changed files with 30 additions and 1 deletions

View File

@ -2,7 +2,15 @@ import React, { PropTypes } from 'react';
import { FormattedMessage as Message } from 'react-intl';
import { userShape } from 'components/user/User';
export default function RejectionLink(props, context) {
if (props.isAvailable && !props.isAvailable(context)) {
// TODO: if want to properly support multiple links, we should control
// the dividers ' | ' rendered from factory too
return null;
}
return (
<a href="#" onClick={(event) => {
event.preventDefault();
@ -16,6 +24,7 @@ export default function RejectionLink(props, context) {
RejectionLink.displayName = 'RejectionLink';
RejectionLink.propTypes = {
isAvailable: PropTypes.func, // a function from context to allow link visibility control
// eslint-disable-next-line react/forbid-prop-types
payload: PropTypes.object, // Custom payload for active state
label: PropTypes.shape({
@ -23,5 +32,6 @@ RejectionLink.propTypes = {
}).isRequired
};
RejectionLink.contextTypes = {
reject: PropTypes.func.isRequired
reject: PropTypes.func.isRequired,
user: userShape
};

View File

@ -1,4 +1,5 @@
{
"createNewAccount": "Create new account",
"loginTitle": "Sign in",
"emailOrUsername": "Email or username",
"next": "Next"

View File

@ -9,6 +9,10 @@ export default factory({
footer: {
color: 'green',
label: messages.next
},
links: {
isAvailable: (context) => !context.user.isGuest,
label: messages.createNewAccount
}
});

View File

@ -2,6 +2,7 @@ import logger from 'services/logger';
import AbstractState from './AbstractState';
import PasswordState from './PasswordState';
import RegisterState from './RegisterState';
export default class LoginState extends AbstractState {
enter(context) {
@ -29,6 +30,10 @@ export default class LoginState extends AbstractState {
);
}
reject(context) {
context.setState(new RegisterState());
}
goBack(context) {
context.run('goBack', '/');
}

View File

@ -2,6 +2,7 @@ import sinon from 'sinon';
import LoginState from 'services/authFlow/LoginState';
import PasswordState from 'services/authFlow/PasswordState';
import RegisterState from 'services/authFlow/RegisterState';
import { bootstrap, expectState, expectNavigate, expectRun } from './helpers';
@ -82,6 +83,14 @@ describe('LoginState', () => {
});
});
describe('#reject', () => {
it('should transition to register state', () => {
expectState(mock, RegisterState);
state.reject(context);
});
});
describe('#goBack', () => {
it('should return to previous page', () => {
expectRun(mock, 'goBack', '/');