got login component working
This commit is contained in:
parent
257df15e44
commit
697501410b
4 changed files with 52 additions and 21 deletions
|
@ -19,6 +19,24 @@ class ChannelLoginForm extends React.Component {
|
||||||
}
|
}
|
||||||
loginToChannel (event) {
|
loginToChannel (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
const params = `username=${this.state.name}&password=${this.state.password}`;
|
||||||
|
const url = '/login';
|
||||||
|
const that = this;
|
||||||
|
this.props.makePostRequest(url, params)
|
||||||
|
.then(result => {
|
||||||
|
that.props.updateLoggedInChannelOutsideReact(result.channelName, result.channelClaimId, result.shortChannelId);
|
||||||
|
that.props.updateUploaderState('loggedInChannelName', result.channelName);
|
||||||
|
that.props.updateUploaderState('loggedInChannelShortId', result.shortChannelId);
|
||||||
|
that.props.selectOption(result.channelName);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.log('login error', error);
|
||||||
|
if (error.message) {
|
||||||
|
that.setState({'error': error.message});
|
||||||
|
} else {
|
||||||
|
that.setState({'error': 'There was an error logging into your channel'});
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
render () {
|
render () {
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -9,24 +9,28 @@ class ChannelSelector extends React.Component {
|
||||||
constructor (props) {
|
constructor (props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
displayCreateOrLogin: LOGIN,
|
optionState: LOGIN,
|
||||||
};
|
};
|
||||||
this.toggleCreateOrLogin = this.toggleCreateOrLogin.bind(this);
|
this.handleSelection = this.handleSelection.bind(this);
|
||||||
|
this.selectOption = this.selectOption.bind(this);
|
||||||
|
this.updateLoggedInChannelOutsideReact = this.updateLoggedInChannelOutsideReact.bind(this);
|
||||||
}
|
}
|
||||||
componentWillMount () {
|
componentWillMount () {
|
||||||
if (this.props.loggedInChannelName) {
|
if (this.props.loggedInChannelName) {
|
||||||
this.setState({ displayCreateOrLogin: null });
|
this.setState({ optionState: null });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
toggleCreateOrLogin (event) {
|
handleSelection (event) {
|
||||||
const selectedOption = event.target.selectedOptions[0].value;
|
const selectedOption = event.target.selectedOptions[0].value;
|
||||||
if (selectedOption === 'login') {
|
this.selectOption(selectedOption);
|
||||||
this.setState({ displayCreateOrLogin: LOGIN });
|
}
|
||||||
} else if (selectedOption === 'create') {
|
selectOption (option) {
|
||||||
this.setState({ displayCreateOrLogin: CREATE });
|
this.setState({optionState: option});
|
||||||
} else {
|
}
|
||||||
this.setState({ displayCreateOrLogin: null });
|
updateLoggedInChannelOutsideReact (channelName, channelClaimId, shortChannelId) {
|
||||||
}
|
// update anywhere on page that needs to be updated outside of this component
|
||||||
|
setUserCookies(channelName, channelClaimId, shortChannelId);
|
||||||
|
replaceChannelOptionInNavBarChannelSelect(channelName);
|
||||||
}
|
}
|
||||||
render () {
|
render () {
|
||||||
return (
|
return (
|
||||||
|
@ -39,19 +43,28 @@ class ChannelSelector extends React.Component {
|
||||||
<div className="column column--3">
|
<div className="column column--3">
|
||||||
<label className="label" htmlFor="channel-name-select">Channel:</label>
|
<label className="label" htmlFor="channel-name-select">Channel:</label>
|
||||||
</div><div className="column column--7">
|
</div><div className="column column--7">
|
||||||
<select type="text" id="channel-name-select" className="select select--arrow" onChange={this.toggleCreateOrLogin}>
|
<select type="text" id="channel-name-select" className="select select--arrow" value={this.state.optionState} onChange={this.handleSelection}>
|
||||||
{ this.props.loggedInChannelName && <option value={this.props.loggedInChannelName} id="publish-channel-select-channel-option">{this.props.loggedInChannelName}</option> }
|
{ this.props.loggedInChannelName && <option value={this.props.loggedInChannelName} id="publish-channel-select-channel-option">{this.props.loggedInChannelName}</option> }
|
||||||
<option value="login">Existing</option>
|
<option value="login">Existing</option>
|
||||||
<option value="create">New</option>
|
<option value="create">New</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{ (this.state.displayCreateOrLogin === LOGIN) && <ChannelLoginForm /> }
|
{ (this.state.optionState === LOGIN) &&
|
||||||
{ (this.state.displayCreateOrLogin === CREATE) &&
|
<ChannelLoginForm
|
||||||
<ChannelCreateForm
|
makePostRequest={this.props.makePostRequest}
|
||||||
makeGetRequest={this.props.makeGetRequest}
|
updateLoggedInChannelOutsideReact={this.updateLoggedInChannelOutsideReact}
|
||||||
cleanseInput={this.props.cleanseInput}
|
updateUploaderState={this.props.updateUploaderState}
|
||||||
/> }
|
selectOption={this.selectOption}
|
||||||
|
/> }
|
||||||
|
{ (this.state.optionState === CREATE) &&
|
||||||
|
<ChannelCreateForm
|
||||||
|
cleanseInput={this.props.cleanseInput}
|
||||||
|
makeGetRequest={this.props.makeGetRequest}
|
||||||
|
updateLoggedInChannelOutsideReact={this.updateLoggedInChannelOutsideReact}
|
||||||
|
updateUploaderState={this.props.updateUploaderState}
|
||||||
|
selectOption={this.selectOption}
|
||||||
|
/> }
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -91,12 +91,13 @@ class PublishForm extends React.Component {
|
||||||
updateUploaderState={this.props.updateUploaderState}
|
updateUploaderState={this.props.updateUploaderState}
|
||||||
/>
|
/>
|
||||||
<ChannelSelector
|
<ChannelSelector
|
||||||
channel={this.props.channel}
|
|
||||||
loggedInChannelName={this.props.loggedInChannelName}
|
loggedInChannelName={this.props.loggedInChannelName}
|
||||||
publishToChannel={this.props.publishToChannel}
|
publishToChannel={this.props.publishToChannel}
|
||||||
cleanseInput={this.props.cleanseInput}
|
cleanseInput={this.props.cleanseInput}
|
||||||
updateUploaderState={this.updateUploaderState}
|
updateUploaderState={this.updateUploaderState}
|
||||||
makeGetRequest={this.props.makeGetRequest}
|
makeGetRequest={this.props.makeGetRequest}
|
||||||
|
makePostRequest={this.props.makePostRequest}
|
||||||
|
updateUploaderState={this.props.updateUploaderState}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<MetadataInputs />
|
<MetadataInputs />
|
||||||
|
|
|
@ -14,7 +14,6 @@ const initialState = {
|
||||||
publishToChannel : false,
|
publishToChannel : false,
|
||||||
file : null,
|
file : null,
|
||||||
title : '',
|
title : '',
|
||||||
channel : null,
|
|
||||||
claim : '',
|
claim : '',
|
||||||
thumbnail : '',
|
thumbnail : '',
|
||||||
description : '',
|
description : '',
|
||||||
|
@ -122,13 +121,13 @@ class Uploader extends React.Component {
|
||||||
updateUploaderState={this.updateUploaderState}
|
updateUploaderState={this.updateUploaderState}
|
||||||
clearUploaderState={this.clearUploaderState}
|
clearUploaderState={this.clearUploaderState}
|
||||||
makeGetRequest={this.makeGetRequest}
|
makeGetRequest={this.makeGetRequest}
|
||||||
|
makePostRequest={this.makePostRequest}
|
||||||
cleanseInput={this.cleanseInput}
|
cleanseInput={this.cleanseInput}
|
||||||
loggedInChannelName={this.state.loggedInChannelName}
|
loggedInChannelName={this.state.loggedInChannelName}
|
||||||
loggedInChannelShortId={this.state.loggedInChannelShortId}
|
loggedInChannelShortId={this.state.loggedInChannelShortId}
|
||||||
publishToChannel={this.state.publishToChannel}
|
publishToChannel={this.state.publishToChannel}
|
||||||
file={this.state.file}
|
file={this.state.file}
|
||||||
title={this.state.title}
|
title={this.state.title}
|
||||||
channel={this.state.channel}
|
|
||||||
claim={this.state.claim}
|
claim={this.state.claim}
|
||||||
thumbnail={this.state.thumbnail}
|
thumbnail={this.state.thumbnail}
|
||||||
description={this.state.description}
|
description={this.state.description}
|
||||||
|
|
Loading…
Reference in a new issue