2018-10-03 19:42:20 -07:00
|
|
|
import React from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
2018-12-03 18:08:29 -08:00
|
|
|
import { Layout } from 'antd';
|
2018-10-03 19:42:20 -07:00
|
|
|
import classnames from 'classnames';
|
|
|
|
import BasicHead from 'components/BasicHead';
|
|
|
|
import Header from 'components/Header';
|
|
|
|
import Footer from 'components/Footer';
|
|
|
|
import { AppState } from 'store/reducers';
|
|
|
|
import './index.less';
|
|
|
|
|
|
|
|
interface StateProps {
|
2018-12-14 11:36:22 -08:00
|
|
|
authUser: AppState['auth']['user'];
|
2018-10-03 19:42:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface TemplateProps {
|
|
|
|
title: string;
|
|
|
|
isHeaderTransparent?: boolean;
|
|
|
|
isFullScreen?: boolean;
|
|
|
|
hideFooter?: boolean;
|
2018-12-14 11:36:22 -08:00
|
|
|
requiresAuth?: boolean;
|
2018-10-03 19:42:20 -07:00
|
|
|
}
|
|
|
|
|
2018-12-14 11:36:22 -08:00
|
|
|
type Props = StateProps & TemplateProps;
|
2018-10-03 19:42:20 -07:00
|
|
|
|
|
|
|
class Template extends React.PureComponent<Props> {
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
children,
|
|
|
|
title,
|
|
|
|
isHeaderTransparent,
|
|
|
|
isFullScreen,
|
|
|
|
hideFooter,
|
2018-12-14 11:36:22 -08:00
|
|
|
requiresAuth,
|
|
|
|
authUser,
|
2018-10-03 19:42:20 -07:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
let content = children;
|
|
|
|
let isCentered = false;
|
2018-12-14 11:36:22 -08:00
|
|
|
if (requiresAuth) {
|
|
|
|
if (!authUser) {
|
2018-10-03 19:42:20 -07:00
|
|
|
isCentered = true;
|
|
|
|
content = (
|
2018-12-14 11:36:22 -08:00
|
|
|
<div>
|
|
|
|
Login required. <br /> TODO: links or redirect
|
|
|
|
</div>
|
2018-10-03 19:42:20 -07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const className = classnames(
|
|
|
|
'Template',
|
|
|
|
isFullScreen && 'is-fullscreen',
|
|
|
|
isCentered && 'is-centered',
|
|
|
|
);
|
|
|
|
return (
|
|
|
|
<BasicHead title={title}>
|
|
|
|
<div className={className}>
|
|
|
|
<Header isTransparent={isHeaderTransparent} />
|
|
|
|
<Layout.Content className="Template-content">
|
|
|
|
<div className="Template-content-inner">{content}</div>
|
|
|
|
</Layout.Content>
|
|
|
|
{!hideFooter && <Footer />}
|
|
|
|
</div>
|
|
|
|
</BasicHead>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-14 11:36:22 -08:00
|
|
|
export default connect<StateProps, {}, TemplateProps, AppState>(state => {
|
|
|
|
return {
|
|
|
|
authUser: state.auth.user,
|
|
|
|
};
|
|
|
|
})(Template);
|