added check to make sure channel is selcted if not publishing anonymously

This commit is contained in:
bill bittner 2018-01-24 12:32:24 -08:00
parent 04754920df
commit 6a8a908130
5 changed files with 27 additions and 9 deletions

View file

@ -7,6 +7,7 @@ const mapStateToProps = ({ channel, publish }) => {
loggedInChannelName: channel.loggedInChannel.name,
publishInChannel : publish.publishInChannel,
selectedChannel : publish.selectedChannel,
channelError : publish.error.channel,
};
};

View file

@ -24,6 +24,7 @@ class ChannelSelect extends React.Component {
render () {
return (
<div>
<p id="input-error-channel-select" className="info-message-placeholder info-message--failure">{this.props.channelError}</p>
<form>
<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}/>
@ -36,7 +37,6 @@ class ChannelSelect extends React.Component {
</form>
{ this.props.publishInChannel && (
<div>
<p id="input-error-channel-select" className="info-message-placeholder info-message--failure">{this.props.channelError}</p>
<div className="column column--3">
<label className="label" htmlFor="channel-name-select">Channel:</label>
</div><div className="column column--7">

View file

@ -14,6 +14,7 @@ const mapStateToProps = ({ channel, publish }) => {
license : publish.metadata.license,
nsfw : publish.metadata.nsfw,
publishInChannel : publish.publishInChannel,
selectedChannel : publish.selectedChannel,
fileError : publish.error.file,
urlError : publish.error.url,
publishSubmitError: publish.error.publishSubmit,
@ -34,6 +35,9 @@ const mapDispatchToProps = dispatch => {
onPublishStatusChange: (status, message) => {
dispatch(updatePublishStatus(status, message));
},
onChannelSelectionError: (value) => {
dispatch(updateError('channel', value));
},
onPublishSubmitError: (value) => {
dispatch(updateError('publishSubmit', value));
},

View file

@ -10,11 +10,24 @@ import * as publishStates from 'constants/publish_claim_states';
class PublishForm extends React.Component {
constructor (props) {
super(props);
this.validatePublishRequest = this.validatePublishRequest.bind(this);
this.validateChannelSelection = this.validateChannelSelection.bind(this);
this.validatePublishParams = this.validatePublishParams.bind(this);
this.makePublishRequest = this.makePublishRequest.bind(this);
this.publish = this.publish.bind(this);
}
validatePublishRequest () {
validateChannelSelection () {
// make sure all required data is provided
return new Promise((resolve, reject) => {
// if publishInChannel is true, is a channel selected & logged in?
if (this.props.publishInChannel && (this.props.selectedChannel !== this.props.loggedInChannel.name)) {
// update state with error
this.props.onChannelSelectionError('Select "Anonymous" or log in to a channel');
// reject this promise
return reject(new Error('Fix the channel'));
}
});
}
validatePublishParams () {
// make sure all required data is provided
return new Promise((resolve, reject) => {
// is there a file?
@ -28,10 +41,6 @@ class PublishForm extends React.Component {
if (this.props.urlError) {
return reject(new Error('Fix the url'));
}
// if publishInChannel is true, is a channel logged in (or selected)
if (this.props.publishInChannel && !this.props.loggedInChannel.name) {
return reject(new Error('Select "Anonymous" or log in to a channel'));
}
// is the claim available?
resolve();
});
@ -85,7 +94,7 @@ class PublishForm extends React.Component {
thumbnail : this.props.thumbnail,
};
if (this.props.publishInChannel) {
metadata['channelName'] = this.props.loggedInChannel.name;
metadata['channelName'] = this.props.selectedChannel;
}
return metadata;
}
@ -103,7 +112,10 @@ class PublishForm extends React.Component {
publish () {
// publish the asset
const that = this;
this.validatePublishRequest()
this.validateChannelSelection()
.then(() => {
return that.validatePublishRequest();
})
.then(() => {
const metadata = that.createMetadata();
// publish the claim

View file

@ -12,6 +12,7 @@ const initialState = {
error: {
file : null,
url : null,
channel : null,
publishSubmit: null,
},
file : null,