diff --git a/app/scripts/components/library/library-hosting-create.components.jsx b/app/scripts/components/library/library-hosting-create.components.jsx index 0c6e09678..edf7afa7c 100644 --- a/app/scripts/components/library/library-hosting-create.components.jsx +++ b/app/scripts/components/library/library-hosting-create.components.jsx @@ -13,11 +13,16 @@ export default class LibraryHostingCreate extends React.Component { autocompleteText: '', autocompleteSuggestions: [], addedFonts: [], + errors: { + domain: false, + hostedFonts: false, + }, }; this.updateAutocompleteSuggestions = this.updateAutocompleteSuggestions.bind( this, ); this.addSuggestion = this.addSuggestion.bind(this); + this.addWebsite = this.addWebsite.bind(this); } async componentWillMount() { this.client = LocalClient.instance(); @@ -40,6 +45,13 @@ export default class LibraryHostingCreate extends React.Component { let preset; let family; + this.setState({ + errors: { + domain: false, + hostedFonts: false, + }, + }); + switch (suggestion.type) { case 'Template': templateData = this.state.templatesData.find( @@ -196,6 +208,45 @@ export default class LibraryHostingCreate extends React.Component { }); } + addWebsite() { + const domain = this.state.domain + .replace('http://', '') + .replace('https://', '') + .split(/[/?#]/)[0] + .toLowerCase() + .normalize('NFD') + .replace(/[\u0300-\u036f]/g, ''); + + this.setState({domain}); + const isUrl = /^([a-zA-Z0-9]+(([\-]?[a-zA-Z0-9]+)*\.)+)*[a-zA-Z]{2,}$/; + + if (!isUrl.test(domain)) { + this.setState({ + errors: { + domain: true, + hostedFonts: false, + }, + }); + return; + } + + if (this.state.addedFonts.length === 0) { + this.setState({ + errors: { + domain: false, + hostedFonts: true, + }, + }); + return; + } + this.setState({ + errors: { + domain: false, + hostedFonts: false, + }, + }); + } + render() { return (
+ The domain you entered is incorrect. Please re-check it. +
+ )}+ Please add at least one font to your website. +
+ )}