allow unprotected pages

This commit is contained in:
Sebastian Sdorra
2018-07-13 10:57:11 +02:00
parent 8ff84abf67
commit 5c59c6bac6
19 changed files with 567 additions and 450 deletions

View File

@@ -3,7 +3,7 @@ import React from "react";
import Notification from "./Notification";
type Props = {
error: Error
error?: Error
};
class ErrorNotification extends React.Component<Props> {

View File

@@ -3,15 +3,19 @@ import React from "react";
import type { Me } from "../types/me";
type Props = {
me: Me
me?: Me
};
class Footer extends React.Component<Props> {
render() {
const { me } = this.props;
if (!me) {
return "";
}
return (
<footer className="footer">
<div className="container is-centered">
<p className="has-text-centered">{this.props.me.username}</p>
<p className="has-text-centered">{me.username}</p>
</div>
</footer>
);

View File

@@ -1,11 +1,8 @@
//@flow
import React from "react";
import PrimaryNavigationLink from "./PrimaryNavigationLink";
import PrimaryNavigationAction from "./PrimaryNavigationAction";
type Props = {
onLogout: () => void
};
type Props = {};
class PrimaryNavigation extends React.Component<Props> {
render() {
@@ -13,10 +10,7 @@ class PrimaryNavigation extends React.Component<Props> {
<nav className="tabs is-boxed">
<ul>
<PrimaryNavigationLink to="/users" label="Users" />
<PrimaryNavigationAction
onClick={this.props.onLogout}
label="Logout"
/>
<PrimaryNavigationLink to="/logout" label="Logout" />
</ul>
</nav>
);

View File

@@ -1,20 +0,0 @@
//@flow
import * as React from "react";
type Props = {
label: string,
onClick: () => void
};
class PrimaryNavigationAction extends React.Component<Props> {
render() {
const { label, onClick } = this.props;
return (
<li>
<a onClick={onClick}>{label}</a>
</li>
);
}
}
export default PrimaryNavigationAction;

View File

@@ -0,0 +1,39 @@
//@flow
import React, { Component } from "react";
import { Route, Redirect, withRouter } from "react-router-dom";
type Props = {
authenticated?: boolean,
component: Component<any, any>
};
class ProtectedRoute extends React.Component<Props> {
renderRoute = (Component: any, authenticated?: boolean) => {
return (routeProps: any) => {
if (authenticated) {
return <Component {...routeProps} />;
} else {
return (
<Redirect
to={{
pathname: "/login",
state: { from: routeProps.location }
}}
/>
);
}
};
};
render() {
const { component, authenticated, ...routeProps } = this.props;
return (
<Route
{...routeProps}
render={this.renderRoute(component, authenticated)}
/>
);
}
}
export default withRouter(ProtectedRoute);

View File

@@ -22,7 +22,6 @@ class SubmitButton extends React.Component<Props> {
<div className="field">
<div className="control">
<button
type="submit"
disabled={disabled}
className={classNames(
"button",