hide unusable components based on site settings

This commit is contained in:
Travis Eden 2018-09-19 16:35:10 -04:00
parent 845a0a3b01
commit 3c21ce36b7
7 changed files with 63 additions and 34 deletions

View file

@ -1,21 +0,0 @@
import React from 'react';
import ChannelLoginForm from '@containers/ChannelLoginForm';
import ChannelCreateForm from '@containers/ChannelCreateForm';
import Row from '@components/Row';
const ChannelTools = () => {
return (
<div>
<Row>
<h3>Log in to an existing channel:</h3>
<ChannelLoginForm />
</Row>
<Row>
<h3>Create a brand new channel:</h3>
<ChannelCreateForm />
</Row>
</div>
);
};
export default ChannelTools;

View file

@ -0,0 +1,10 @@
import { connect } from 'react-redux';
import View from './view';
const mapStateToProps = ({ site: { closedRegistration } }) => {
return {
closedRegistration,
};
};
export default connect(mapStateToProps, null)(View);

View file

@ -0,0 +1,23 @@
import React from 'react';
import ChannelLoginForm from '@containers/ChannelLoginForm';
import ChannelCreateForm from '@containers/ChannelCreateForm';
import Row from '@components/Row';
class ChannelTools extends React.Component {
render () {
return (
<div>
<Row>
<h3>Log in to an existing channel:</h3>
<ChannelLoginForm />
</Row>
{!this.props.closedRegistration && (<Row>
<h3>Create a brand new channel:</h3>
<ChannelCreateForm />
</Row>)}
</div>
);
}
}
export default ChannelTools;

View file

@ -2,8 +2,9 @@ import { connect } from 'react-redux';
import { logOutChannel, checkForLoggedInChannel } from '../../actions/channel'; import { logOutChannel, checkForLoggedInChannel } from '../../actions/channel';
import View from './view'; import View from './view';
const mapStateToProps = ({ channel: { loggedInChannel: { name, shortId, longId } } }) => { const mapStateToProps = ({ site, channel: { loggedInChannel: { name, shortId, longId } } }) => {
return { return {
site,
channelName : name, channelName : name,
channelShortId: shortId, channelShortId: shortId,
channelLongId : longId, channelLongId : longId,

View file

@ -28,16 +28,17 @@ class NavigationLinks extends React.Component {
} }
} }
render () { render () {
const { site, channelLongId, channelName } = this.props;
return ( return (
<div className='navigation-links'> <div className='navigation-links'>
<NavLink {(!site.publishOnlyApproved || site.approvedChannels.includes(channelLongId)) && <NavLink
className='nav-bar-link link--nav' className='nav-bar-link link--nav'
activeClassName='link--nav-active' activeClassName='link--nav-active'
to='/' to='/'
exact exact
> >
Publish Publish
</NavLink> </NavLink>}
<NavLink <NavLink
className='nav-bar-link link--nav' className='nav-bar-link link--nav'
activeClassName='link--nav-active' activeClassName='link--nav-active'
@ -45,7 +46,7 @@ class NavigationLinks extends React.Component {
> >
About About
</NavLink> </NavLink>
{ this.props.channelName ? ( { channelName ? (
<NavBarChannelOptionsDropdown <NavBarChannelOptionsDropdown
channelName={this.props.channelName} channelName={this.props.channelName}
handleSelection={this.handleSelection} handleSelection={this.handleSelection}
@ -53,7 +54,7 @@ class NavigationLinks extends React.Component {
VIEW={VIEW} VIEW={VIEW}
LOGOUT={LOGOUT} LOGOUT={LOGOUT}
/> />
) : ( ) : !site.closedRegistration && (
<NavLink <NavLink
id='nav-bar-login-link' id='nav-bar-login-link'
className='nav-bar-link link--nav' className='nav-bar-link link--nav'

View file

@ -4,7 +4,7 @@ import PageLayout from '@components/PageLayout';
import HorizontalSplit from '@components/HorizontalSplit'; import HorizontalSplit from '@components/HorizontalSplit';
import ChannelAbout from '@components/ChannelAbout'; import ChannelAbout from '@components/ChannelAbout';
import ChannelTools from '@components/ChannelTools'; import ChannelTools from '@containers/ChannelTools';
class LoginPage extends React.Component { class LoginPage extends React.Component {
componentWillReceiveProps (newProps) { componentWillReceiveProps (newProps) {

View file

@ -8,6 +8,11 @@ let initialState = {
twitter : 'default twitter', twitter : 'default twitter',
defaultDescription : 'default description', defaultDescription : 'default description',
defaultThumbnail : 'default thumbnail', defaultThumbnail : 'default thumbnail',
closedRegistration : false,
serveOnlyApproved : false,
publishOnlyApproved: false,
approvedChannels : [],
}; };
if (siteConfig) { if (siteConfig) {
@ -25,6 +30,12 @@ if (siteConfig) {
title, title,
twitter, twitter,
}, },
publishing: {
closedRegistration,
serveOnlyApproved,
publishOnlyApproved,
approvedChannels,
},
} = siteConfig; } = siteConfig;
initialState = { initialState = {
@ -35,6 +46,10 @@ if (siteConfig) {
twitter, twitter,
defaultDescription, defaultDescription,
defaultThumbnail, defaultThumbnail,
closedRegistration,
serveOnlyApproved,
publishOnlyApproved,
approvedChannels,
}; };
} }