2018-01-06 03:26:57 +01:00
import React from 'react' ;
2018-01-18 00:00:03 +01:00
import ChannelLoginForm from 'containers/ChannelLoginForm' ;
import ChannelCreateForm from 'containers/ChannelCreateForm' ;
2018-01-24 21:02:40 +01:00
import * as states from 'constants/publish_channel_select_states' ;
2018-01-06 03:26:57 +01:00
2018-01-17 19:49:57 +01:00
class ChannelSelect extends React . Component {
2018-01-06 03:26:57 +01:00
constructor ( props ) {
super ( props ) ;
this . toggleAnonymousPublish = this . toggleAnonymousPublish . bind ( this ) ;
2018-01-17 18:46:16 +01:00
this . handleSelection = this . handleSelection . bind ( this ) ;
2018-01-06 03:26:57 +01:00
}
toggleAnonymousPublish ( event ) {
const value = event . target . value ;
if ( value === 'anonymous' ) {
2018-01-10 03:49:26 +01:00
this . props . onPublishInChannelChange ( false ) ;
2018-01-06 03:26:57 +01:00
} else {
2018-01-10 03:49:26 +01:00
this . props . onPublishInChannelChange ( true ) ;
2018-01-06 03:26:57 +01:00
}
}
2018-01-17 18:46:16 +01:00
handleSelection ( event ) {
const selectedOption = event . target . selectedOptions [ 0 ] . value ;
2018-01-19 19:16:55 +01:00
this . props . onChannelSelect ( selectedOption ) ;
2018-01-17 18:46:16 +01:00
}
2018-01-06 03:26:57 +01:00
render ( ) {
return (
2018-01-17 18:46:16 +01:00
< div >
< form >
2018-03-06 07:45:39 +01:00
< div className = 'column column--3 column--med-10' >
< input type = 'radio' name = 'anonymous-or-channel' id = 'anonymous-radio' className = 'input-radio' value = 'anonymous' checked = { ! this . props . publishInChannel } onChange = { this . toggleAnonymousPublish } / >
< label className = 'label label--pointer' htmlFor = 'anonymous-radio' > Anonymous < / label >
2018-01-17 18:46:16 +01:00
< / div >
2018-03-06 07:45:39 +01:00
< div className = 'column column--7 column--med-10' >
< input type = 'radio' name = 'anonymous-or-channel' id = 'channel-radio' className = 'input-radio' value = 'in a channel' checked = { this . props . publishInChannel } onChange = { this . toggleAnonymousPublish } / >
< label className = 'label label--pointer' htmlFor = 'channel-radio' > In a channel < / label >
2018-01-17 18:46:16 +01:00
< / div >
2018-03-06 07:45:39 +01:00
{ this . props . channelError ? (
< p className = 'info-message--failure' > { this . props . channelError } < / p >
) : (
< p className = 'info-message' > Publish anonymously or in a channel < / p >
) }
2018-01-17 18:46:16 +01:00
< / form >
{ this . props . publishInChannel && (
< div >
2018-03-06 07:45:39 +01:00
< div className = 'column column--3' >
< label className = 'label' htmlFor = 'channel-name-select' > Channel : < / label >
< / div > < div className = 'column column--7' >
< select type = 'text' id = 'channel-name-select' className = 'select select--arrow' value = { this . props . selectedChannel } onChange = { this . handleSelection } >
{ this . props . loggedInChannelName && < option value = { this . props . loggedInChannelName } id = 'publish-channel-select-channel-option' > { this . props . loggedInChannelName } < / option > }
< option value = { states . LOGIN } > Existing < / option >
< option value = { states . CREATE } > New < / option >
< / select >
< / div >
2018-01-19 19:16:55 +01:00
{ ( this . props . selectedChannel === states . LOGIN ) && < ChannelLoginForm / > }
{ ( this . props . selectedChannel === states . CREATE ) && < ChannelCreateForm / > }
2018-01-17 18:46:16 +01:00
< / div >
) }
< / div >
2018-01-06 03:26:57 +01:00
) ;
}
}
2018-01-17 19:49:57 +01:00
export default ChannelSelect ;