Fix extra location state modifications that caused weird redirects

This commit is contained in:
Kimmo Puputti 2017-02-17 13:38:47 +02:00
parent 067f5abce8
commit 99c9a67a4b

View file

@ -1,7 +1,7 @@
import React, { PropTypes } from 'react';
import { connect } from 'react-redux';
import { Redirect } from 'react-router-dom';
import { PageLayout, NamedLink } from '../../components';
import { PageLayout, NamedLink, NamedRedirect } from '../../components';
import { LoginForm, SignUpForm } from '../../containers';
import { login } from '../../ducks/Auth.ducks';
@ -10,9 +10,11 @@ export const AuthenticationPageComponent = props => {
const isLogin = tab === 'login';
const from = location.state && location.state.from ? location.state.from : null;
const authRedirect = from ? <Redirect to={from} /> : <NamedRedirect name="LandingPage" />;
return (
<PageLayout title={`Authentication page: ${tab} tab`}>
{isAuthenticated ? <Redirect to={from || '/'} /> : null}
{isAuthenticated ? authRedirect : null}
{from
? <p>
You must log in to view the page at
@ -21,8 +23,8 @@ export const AuthenticationPageComponent = props => {
: null}
{isLogin ? <LoginForm onSubmit={onLoginSubmit} /> : <SignUpForm onSubmit={onSignUpSubmit} />}
{isLogin
? <NamedLink name="SignUpPage" to={{ state: { from: from || '/' } }}>Sign up</NamedLink>
: <NamedLink name="LogInPage" to={{ state: { from: from || '/' } }}>Log in</NamedLink>}
? <NamedLink name="SignUpPage" to={{ state: from ? { from } : null }}>Sign up</NamedLink>
: <NamedLink name="LogInPage" to={{ state: from ? { from } : null }}>Log in</NamedLink>}
</PageLayout>
);
};