mirror of
https://github.com/elyby/accounts-frontend.git
synced 2025-01-16 08:33:15 +05:30
#304: show Create new account link on LoginPanel for authorized users
This commit is contained in:
parent
e9e04d8336
commit
fbcc2a740c
@ -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
|
||||
};
|
||||
|
@ -1,4 +1,5 @@
|
||||
{
|
||||
"createNewAccount": "Create new account",
|
||||
"loginTitle": "Sign in",
|
||||
"emailOrUsername": "E‑mail or username",
|
||||
"next": "Next"
|
||||
|
@ -9,6 +9,10 @@ export default factory({
|
||||
footer: {
|
||||
color: 'green',
|
||||
label: messages.next
|
||||
},
|
||||
links: {
|
||||
isAvailable: (context) => !context.user.isGuest,
|
||||
label: messages.createNewAccount
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -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', '/');
|
||||
}
|
||||
|
@ -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', '/');
|
||||
|
Loading…
x
Reference in New Issue
Block a user