updated the channel creation route with GA event
This commit is contained in:
parent
d21ab2e4b0
commit
188706ca31
3 changed files with 28 additions and 44 deletions
|
@ -106,21 +106,24 @@ module.exports = {
|
||||||
return name;
|
return name;
|
||||||
};
|
};
|
||||||
return name;
|
return name;
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
throw error;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
checkChannelAvailability (name) {
|
checkChannelAvailability (name) {
|
||||||
return new Promise((resolve, reject) => {
|
return db.Channel
|
||||||
// find any records where the name is used
|
.findAll({
|
||||||
db.Channel.findAll({ where: { channelName: name } })
|
where: { channelName: name },
|
||||||
|
})
|
||||||
.then(result => {
|
.then(result => {
|
||||||
if (result.length >= 1) {
|
if (result.length >= 1) {
|
||||||
return resolve(false);
|
throw new Error('That channel has already been claimed');
|
||||||
}
|
}
|
||||||
resolve(true);
|
return name;
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
reject(error);
|
throw error;
|
||||||
});
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -38,32 +38,13 @@ class ChannelCreateForm extends React.Component {
|
||||||
updateIsChannelAvailable (channel) {
|
updateIsChannelAvailable (channel) {
|
||||||
const channelWithAtSymbol = `@${channel}`;
|
const channelWithAtSymbol = `@${channel}`;
|
||||||
request(`/api/channel/availability/${channelWithAtSymbol}`)
|
request(`/api/channel/availability/${channelWithAtSymbol}`)
|
||||||
.then(isAvailable => {
|
.then(() => {
|
||||||
if (isAvailable) {
|
|
||||||
this.setState({'error': null});
|
this.setState({'error': null});
|
||||||
} else {
|
|
||||||
this.setState({'error': 'That channel has already been claimed'});
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
this.setState({'error': error.message});
|
this.setState({'error': error.message});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
checkIsChannelAvailable (channel) {
|
|
||||||
const channelWithAtSymbol = `@${channel}`;
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
request(`/api/channel/availability/${channelWithAtSymbol}`)
|
|
||||||
.then(isAvailable => {
|
|
||||||
if (!isAvailable) {
|
|
||||||
return reject(new Error('That channel has already been claimed'));
|
|
||||||
}
|
|
||||||
resolve();
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
reject(error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
checkIsPasswordProvided () {
|
checkIsPasswordProvided () {
|
||||||
const password = this.state.password;
|
const password = this.state.password;
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
@ -96,7 +77,9 @@ class ChannelCreateForm extends React.Component {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
this.checkIsPasswordProvided()
|
this.checkIsPasswordProvided()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
return this.checkIsChannelAvailable(this.state.channel, this.state.password);
|
if (this.state.error) {
|
||||||
|
throw new Error();
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.setState({status: 'We are publishing your new channel. Sit tight...'});
|
this.setState({status: 'We are publishing your new channel. Sit tight...'});
|
||||||
|
@ -107,7 +90,7 @@ class ChannelCreateForm extends React.Component {
|
||||||
this.props.onChannelLogin(result.channelName, result.shortChannelId, result.channelClaimId);
|
this.props.onChannelLogin(result.channelName, result.shortChannelId, result.channelClaimId);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
this.setState({'error': error.message, status: null});
|
if (error.message) this.setState({'error': error.message, status: null});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
render () {
|
render () {
|
||||||
|
|
|
@ -16,14 +16,12 @@ const NO_CLAIM = 'NO_CLAIM';
|
||||||
|
|
||||||
module.exports = (app) => {
|
module.exports = (app) => {
|
||||||
// route to check whether site has published to a channel
|
// route to check whether site has published to a channel
|
||||||
app.get('/api/channel/availability/:name', ({ ip, originalUrl, params }, res) => {
|
app.get('/api/channel/availability/:name', ({ ip, originalUrl, params: { name } }, res) => {
|
||||||
checkChannelAvailability(params.name)
|
const gaStartTime = Date.now();
|
||||||
.then(result => {
|
checkChannelAvailability(name)
|
||||||
if (result === true) {
|
.then(availableName => {
|
||||||
res.status(200).json(true);
|
res.status(200).json(availableName);
|
||||||
} else {
|
sendGATimingEvent('end-to-end', 'claim name availability', name, gaStartTime, Date.now());
|
||||||
res.status(200).json(false);
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
errorHandlers.handleErrorResponse(originalUrl, ip, error, res);
|
errorHandlers.handleErrorResponse(originalUrl, ip, error, res);
|
||||||
|
|
Loading…
Reference in a new issue