Skip to content

Commit

Permalink
Import in Signup: Validate site is importable (#27382)
Browse files Browse the repository at this point in the history
Includes the following:

* Client-side validation to check URL of site to be imported, added to `/lib/importers` to
  be shared with Import page in Calypso
* Uses `is-site-importable` endpoint to check import-ability of site
* Adds tracks events for exiting import signup flow and viewing help
* Extracts `example-domain-browser` into a separate component so it can be used in import-url
  step, in addition to domains step
  • Loading branch information
creativecoder authored Oct 18, 2018
1 parent bf01aef commit 36a1c7a
Show file tree
Hide file tree
Showing 18 changed files with 432 additions and 167 deletions.
1 change: 1 addition & 0 deletions assets/stylesheets/_components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
@import 'components/domains/domain-search-results/style';
@import 'components/domains/domain-suggestion/style';
@import 'components/domains/domain-transfer-suggestion/style';
@import 'components/domains/example-domain-browser/style';
@import 'components/domains/example-domain-suggestions/style';
@import 'components/domains/featured-domain-suggestions/style';
@import 'components/domains/map-domain-step/style';
Expand Down
1 change: 1 addition & 0 deletions assets/stylesheets/sections/signup.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
@import 'signup/steps/design-type-with-store/style';
@import 'signup/steps/design-type/style';
@import 'signup/steps/domains/style';
@import 'signup/steps/import-url/style';
@import 'signup/steps/site-or-domain/style';
@import 'signup/steps/site-picker/style';
@import 'signup/steps/survey/style';
Expand Down
4 changes: 4 additions & 0 deletions client/components/domains/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ domain-suggestion
-----------------
A single registration suggestion

example-domain-browser
----------------------
A svg illustration of a browser URL bar

example-domain-suggestions
--------------------------
Gives examples of what domains are available
Expand Down
32 changes: 32 additions & 0 deletions client/components/domains/example-domain-browser/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/** @format */

/**
* External dependencies
*/
import React from 'react';
import classNames from 'classnames';

export default function ExampleDomainBrowser( { className } ) {
return (
<div className={ classNames( 'example-domain-browser', className ) }>
<svg width="295" height="102" viewBox="0 0 295 102" xmlns="http://www.w3.org/2000/svg">
<title>Example Browser</title>
<g fill="none" fillRule="evenodd">
<path fill="#E9EFF3" d="M0 49h295v53H0z" />
<path d="M295 50V0H8.005C3.585 0 0 3.576 0 8.006V50h295z" fill="#C8D7E1" />
<rect fill="#E9EFF3" opacity=".8" x="10" y="10" width="30" height="30" rx="4" />
<rect fill="#E9EFF3" opacity=".8" x="50" y="10" width="30" height="30" rx="4" />
<path d="M295 10H94c-2.21 0-4 1.79-4 4v22c0 2.213 1.79 4 4 4h201V10z" fill="#F3F6F8" />
<path
d="M102.26 30h1.26v-4.673c0-1.333.776-2.226 2.19-2.226 1.193 0 1.823.696 1.823 2.095V30h1.26v-5.112c0-1.853-1.055-2.923-2.725-2.923-1.208 0-2.036.513-2.43 1.385h-.118v-4.38h-1.26V30zm9.36-9.94v2.044h-1.274v1.055h1.274v4.79c0 1.508.652 2.11 2.278 2.11.25 0 .49-.03.74-.075v-1.062c-.235.022-.36.03-.586.03-.82 0-1.172-.396-1.172-1.326V23.16h1.758v-1.056h-1.758V20.06h-1.26zm5.45 0v2.044h-1.275v1.055h1.274v4.79c0 1.508.65 2.11 2.277 2.11.25 0 .49-.03.74-.075v-1.062c-.234.022-.36.03-.586.03-.82 0-1.17-.396-1.17-1.326V23.16h1.757v-1.056h-1.758V20.06h-1.26zm8.766 1.905c-1.076 0-2.02.55-2.526 1.458h-.118v-1.32h-1.2v10.534h1.26v-3.824h.116c.432.835 1.34 1.326 2.468 1.326 2.007 0 3.318-1.62 3.318-4.088 0-2.483-1.303-4.087-3.318-4.087zm-.3 7.04c-1.42 0-2.322-1.144-2.322-2.953 0-1.816.9-2.95 2.33-2.95 1.442 0 2.307 1.105 2.307 2.95 0 1.846-.864 2.952-2.314 2.952zm6.636 1.068c.527 0 .952-.432.952-.952 0-.526-.425-.95-.952-.95-.52 0-.952.424-.952.95 0 .52.432.953.952.953zm0-5.632c.527 0 .952-.43.952-.95 0-.53-.425-.953-.952-.953-.52 0-.952.424-.952.952 0 .52.432.95.952.95zm3.765 7.94l3.237-12.95h-1.113l-3.222 12.95h1.1zm5.214 0l3.24-12.95h-1.115l-3.222 12.95h1.098z"
fill="#87A6BC"
/>
<path
d="M150.336 23.08c1.252 0 2.087.92 2.117 2.32h-4.35c.094-1.4.973-2.32 2.233-2.32zm2.08 4.877c-.33.695-1.018 1.07-2.036 1.07-1.34 0-2.212-.99-2.278-2.55v-.06h5.676v-.482c0-2.454-1.296-3.97-3.427-3.97-2.167 0-3.56 1.612-3.56 4.095 0 2.497 1.37 4.08 3.56 4.08 1.73 0 2.945-.828 3.326-2.183h-1.26zm6.138-.938L160.42 30h1.496l-2.718-4 2.68-3.896h-1.427l-1.852 2.938h-.118l-1.875-2.938h-1.5l2.73 3.948L155.134 30h1.43l1.874-2.98h.117zm7.514 2.013c-.915 0-1.596-.47-1.596-1.274 0-.792.527-1.21 1.728-1.29l2.124-.14v.726c0 1.128-.96 1.977-2.256 1.977zm-.234 1.106c1.055 0 1.92-.462 2.432-1.305h.117V30h1.2v-5.405c0-1.64-1.076-2.63-3.002-2.63-1.684 0-2.93.835-3.097 2.102h1.274c.176-.622.835-.98 1.78-.98 1.18 0 1.787.534 1.787 1.508v.718l-2.278.14c-1.838.11-2.878.922-2.878 2.335 0 1.443 1.135 2.35 2.666 2.35zm6.08-.14h1.26v-4.893c0-1.113.797-2.006 1.83-2.006.996 0 1.648.6 1.648 1.54V30h1.26v-5.076c0-1.003.732-1.823 1.83-1.823 1.114 0 1.663.572 1.663 1.736V30h1.26v-5.457c0-1.655-.9-2.578-2.512-2.578-1.09 0-1.992.55-2.417 1.385h-.117c-.368-.82-1.115-1.385-2.184-1.385-1.055 0-1.846.506-2.205 1.385h-.116v-1.246h-1.2V30zm16.896-8.035c-1.077 0-2.02.55-2.527 1.458h-.117v-1.32h-1.2v10.534h1.26v-3.824h.116c.432.835 1.34 1.326 2.468 1.326 2.007 0 3.318-1.62 3.318-4.088 0-2.483-1.304-4.087-3.318-4.087zm-.3 7.04c-1.42 0-2.322-1.144-2.322-2.953 0-1.816.9-2.95 2.33-2.95 1.442 0 2.306 1.105 2.306 2.95 0 1.846-.864 2.952-2.314 2.952zm5.67.995h1.258V18.97h-1.26V30zm6.854-6.92c1.253 0 2.088.92 2.117 2.32h-4.35c.096-1.4.974-2.32 2.234-2.32zm2.08 4.877c-.33.695-1.018 1.07-2.036 1.07-1.34 0-2.212-.99-2.278-2.55v-.06h5.677v-.482c0-2.454-1.297-3.97-3.428-3.97-2.17 0-3.56 1.612-3.56 4.095 0 2.497 1.37 4.08 3.56 4.08 1.727 0 2.943-.828 3.324-2.183h-1.26zm4.38 2.116c.527 0 .952-.432.952-.952 0-.526-.425-.95-.952-.95-.52 0-.952.424-.952.95 0 .52.432.953.952.953zm9.946-5.552c-.22-1.405-1.39-2.555-3.31-2.555-2.212 0-3.618 1.597-3.618 4.058 0 2.512 1.413 4.116 3.625 4.116 1.897 0 3.076-1.07 3.303-2.52h-1.274c-.234.893-.974 1.384-2.036 1.384-1.406 0-2.315-1.157-2.315-2.98 0-1.788.894-2.923 2.315-2.923 1.135 0 1.83.638 2.036 1.42h1.274zm5.105 4.484c-1.494 0-2.336-1.084-2.336-2.952 0-1.875.84-2.95 2.335-2.95s2.337 1.075 2.337 2.95c0 1.868-.842 2.952-2.337 2.952zm0 1.135c2.25 0 3.64-1.554 3.64-4.088 0-2.54-1.39-4.087-3.64-4.087-2.248 0-3.64 1.546-3.64 4.087 0 2.534 1.392 4.087 3.64 4.087zm5.618-.14h1.26v-4.893c0-1.113.798-2.006 1.83-2.006.997 0 1.65.6 1.65 1.54V30h1.26v-5.076c0-1.003.73-1.823 1.83-1.823 1.113 0 1.662.572 1.662 1.736V30h1.26v-5.457c0-1.655-.9-2.578-2.512-2.578-1.09 0-1.992.55-2.417 1.385h-.117c-.368-.82-1.115-1.385-2.184-1.385-1.055 0-1.846.506-2.205 1.385h-.116v-1.246h-1.2V30z"
fill="#3D596D"
/>
</g>
</svg>
</div>
);
}
23 changes: 23 additions & 0 deletions client/components/domains/example-domain-browser/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.example-domain-browser {
pointer-events: none;

&::before,
&::after {
display: block;
content: '';
position: absolute;
right: 0;
bottom: 0;
left: 0;
}

&::before {
height: 30px;
background: linear-gradient( to bottom, rgba( $gray-light, 0 ) 0%, rgba( $gray-light, 1 ) 100% );
}

&::after {
width: 80px;
background: linear-gradient( to right, rgba( $gray-light, 0 ) 0%, rgba( $gray-light, 1 ) 100% );
}
}
25 changes: 2 additions & 23 deletions client/components/domains/example-domain-suggestions/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { connect } from 'react-redux';
import { recordTracksEvent } from 'state/analytics/actions';
import { getDesignType } from 'state/signup/steps/design-type/selectors';
import { DESIGN_TYPE_STORE } from 'signup/constants';
import ExampleDomainBrowser from '../example-domain-browser';

class DomainSuggestionsExample extends React.Component {
static propTypes = {
Expand Down Expand Up @@ -42,29 +43,7 @@ class DomainSuggestionsExample extends React.Component {
</a>
</p>
) }
<div className="example-domain-suggestions__browser">
<svg width="295" height="102" viewBox="0 0 295 102" xmlns="http://www.w3.org/2000/svg">
<title>Example Browser</title>
<g fill="none" fillRule="evenodd">
<path fill="#E9EFF3" d="M0 49h295v53H0z" />
<path d="M295 50V0H8.005C3.585 0 0 3.576 0 8.006V50h295z" fill="#C8D7E1" />
<rect fill="#E9EFF3" opacity=".8" x="10" y="10" width="30" height="30" rx="4" />
<rect fill="#E9EFF3" opacity=".8" x="50" y="10" width="30" height="30" rx="4" />
<path
d="M295 10H94c-2.21 0-4 1.79-4 4v22c0 2.213 1.79 4 4 4h201V10z"
fill="#F3F6F8"
/>
<path
d="M102.26 30h1.26v-4.673c0-1.333.776-2.226 2.19-2.226 1.193 0 1.823.696 1.823 2.095V30h1.26v-5.112c0-1.853-1.055-2.923-2.725-2.923-1.208 0-2.036.513-2.43 1.385h-.118v-4.38h-1.26V30zm9.36-9.94v2.044h-1.274v1.055h1.274v4.79c0 1.508.652 2.11 2.278 2.11.25 0 .49-.03.74-.075v-1.062c-.235.022-.36.03-.586.03-.82 0-1.172-.396-1.172-1.326V23.16h1.758v-1.056h-1.758V20.06h-1.26zm5.45 0v2.044h-1.275v1.055h1.274v4.79c0 1.508.65 2.11 2.277 2.11.25 0 .49-.03.74-.075v-1.062c-.234.022-.36.03-.586.03-.82 0-1.17-.396-1.17-1.326V23.16h1.757v-1.056h-1.758V20.06h-1.26zm8.766 1.905c-1.076 0-2.02.55-2.526 1.458h-.118v-1.32h-1.2v10.534h1.26v-3.824h.116c.432.835 1.34 1.326 2.468 1.326 2.007 0 3.318-1.62 3.318-4.088 0-2.483-1.303-4.087-3.318-4.087zm-.3 7.04c-1.42 0-2.322-1.144-2.322-2.953 0-1.816.9-2.95 2.33-2.95 1.442 0 2.307 1.105 2.307 2.95 0 1.846-.864 2.952-2.314 2.952zm6.636 1.068c.527 0 .952-.432.952-.952 0-.526-.425-.95-.952-.95-.52 0-.952.424-.952.95 0 .52.432.953.952.953zm0-5.632c.527 0 .952-.43.952-.95 0-.53-.425-.953-.952-.953-.52 0-.952.424-.952.952 0 .52.432.95.952.95zm3.765 7.94l3.237-12.95h-1.113l-3.222 12.95h1.1zm5.214 0l3.24-12.95h-1.115l-3.222 12.95h1.098z"
fill="#87A6BC"
/>
<path
d="M150.336 23.08c1.252 0 2.087.92 2.117 2.32h-4.35c.094-1.4.973-2.32 2.233-2.32zm2.08 4.877c-.33.695-1.018 1.07-2.036 1.07-1.34 0-2.212-.99-2.278-2.55v-.06h5.676v-.482c0-2.454-1.296-3.97-3.427-3.97-2.167 0-3.56 1.612-3.56 4.095 0 2.497 1.37 4.08 3.56 4.08 1.73 0 2.945-.828 3.326-2.183h-1.26zm6.138-.938L160.42 30h1.496l-2.718-4 2.68-3.896h-1.427l-1.852 2.938h-.118l-1.875-2.938h-1.5l2.73 3.948L155.134 30h1.43l1.874-2.98h.117zm7.514 2.013c-.915 0-1.596-.47-1.596-1.274 0-.792.527-1.21 1.728-1.29l2.124-.14v.726c0 1.128-.96 1.977-2.256 1.977zm-.234 1.106c1.055 0 1.92-.462 2.432-1.305h.117V30h1.2v-5.405c0-1.64-1.076-2.63-3.002-2.63-1.684 0-2.93.835-3.097 2.102h1.274c.176-.622.835-.98 1.78-.98 1.18 0 1.787.534 1.787 1.508v.718l-2.278.14c-1.838.11-2.878.922-2.878 2.335 0 1.443 1.135 2.35 2.666 2.35zm6.08-.14h1.26v-4.893c0-1.113.797-2.006 1.83-2.006.996 0 1.648.6 1.648 1.54V30h1.26v-5.076c0-1.003.732-1.823 1.83-1.823 1.114 0 1.663.572 1.663 1.736V30h1.26v-5.457c0-1.655-.9-2.578-2.512-2.578-1.09 0-1.992.55-2.417 1.385h-.117c-.368-.82-1.115-1.385-2.184-1.385-1.055 0-1.846.506-2.205 1.385h-.116v-1.246h-1.2V30zm16.896-8.035c-1.077 0-2.02.55-2.527 1.458h-.117v-1.32h-1.2v10.534h1.26v-3.824h.116c.432.835 1.34 1.326 2.468 1.326 2.007 0 3.318-1.62 3.318-4.088 0-2.483-1.304-4.087-3.318-4.087zm-.3 7.04c-1.42 0-2.322-1.144-2.322-2.953 0-1.816.9-2.95 2.33-2.95 1.442 0 2.306 1.105 2.306 2.95 0 1.846-.864 2.952-2.314 2.952zm5.67.995h1.258V18.97h-1.26V30zm6.854-6.92c1.253 0 2.088.92 2.117 2.32h-4.35c.096-1.4.974-2.32 2.234-2.32zm2.08 4.877c-.33.695-1.018 1.07-2.036 1.07-1.34 0-2.212-.99-2.278-2.55v-.06h5.677v-.482c0-2.454-1.297-3.97-3.428-3.97-2.17 0-3.56 1.612-3.56 4.095 0 2.497 1.37 4.08 3.56 4.08 1.727 0 2.943-.828 3.324-2.183h-1.26zm4.38 2.116c.527 0 .952-.432.952-.952 0-.526-.425-.95-.952-.95-.52 0-.952.424-.952.95 0 .52.432.953.952.953zm9.946-5.552c-.22-1.405-1.39-2.555-3.31-2.555-2.212 0-3.618 1.597-3.618 4.058 0 2.512 1.413 4.116 3.625 4.116 1.897 0 3.076-1.07 3.303-2.52h-1.274c-.234.893-.974 1.384-2.036 1.384-1.406 0-2.315-1.157-2.315-2.98 0-1.788.894-2.923 2.315-2.923 1.135 0 1.83.638 2.036 1.42h1.274zm5.105 4.484c-1.494 0-2.336-1.084-2.336-2.952 0-1.875.84-2.95 2.335-2.95s2.337 1.075 2.337 2.95c0 1.868-.842 2.952-2.337 2.952zm0 1.135c2.25 0 3.64-1.554 3.64-4.088 0-2.54-1.39-4.087-3.64-4.087-2.248 0-3.64 1.546-3.64 4.087 0 2.534 1.392 4.087 3.64 4.087zm5.618-.14h1.26v-4.893c0-1.113.798-2.006 1.83-2.006.997 0 1.65.6 1.65 1.54V30h1.26v-5.076c0-1.003.73-1.823 1.83-1.823 1.113 0 1.662.572 1.662 1.736V30h1.26v-5.457c0-1.655-.9-2.578-2.512-2.578-1.09 0-1.992.55-2.417 1.385h-.117c-.368-.82-1.115-1.385-2.184-1.385-1.055 0-1.846.506-2.205 1.385h-.116v-1.246h-1.2V30z"
fill="#3D596D"
/>
</g>
</svg>
</div>
<ExampleDomainBrowser className="example-domain-suggestions__browser" />
</div>
);
}
Expand Down
25 changes: 1 addition & 24 deletions client/components/domains/example-domain-suggestions/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,14 @@
}

.example-domain-suggestions__browser {
pointer-events: none;
position: absolute;
top: 0;
right: 0;
width: 300px;

&:before {
display: block;
content: '';
position: absolute;
right: 0;
bottom: 0;
left: 0;
height: 30px;
background: linear-gradient( to bottom, rgba( $gray-light, 0 ) 0%, rgba( $gray-light, 1 ) 100% );
}

&:after {
display: block;
content: '';
position: absolute;
top: 0;
right: 0;
bottom: 0;
width: 80px;
background: linear-gradient( to right, rgba( $gray-light, 0 ) 0%, rgba( $gray-light, 1 ) 100% );
}

@include breakpoint( "<660px" ) {
padding-top: 24px;
position: relative;
margin: 0 auto;
}
}
}
2 changes: 1 addition & 1 deletion client/components/forms/form-input-validation/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class extends React.Component {
static defaultProps = { isError: false, id: null };

render() {
const classes = classNames( {
const classes = classNames( this.props.className, {
'form-input-validation': true,
'is-warning': this.props.isWarning,
'is-error': this.props.isError,
Expand Down
5 changes: 5 additions & 0 deletions client/lib/importers/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** @format */

export const SITE_IMPORTER_ERR_INVALID_URL = 1000001;

export const SITE_IMPORTER_ERR_BAD_REMOTE = 1000002;
58 changes: 58 additions & 0 deletions client/lib/importers/url-validation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/** @format */

/**
* External dependencies
*/
import url from 'url';
import { isURL } from '@wordpress/url';
import { translate } from 'i18n-calypso';
import { inRange, trim } from 'lodash';

const parseUrl = function( value = '' ) {
const rawUrl = trim( value );
const parsedUrl = url.parse( rawUrl, false, true );

// `url.parse` will only parse the host/hostname if protocol is included.
return parsedUrl.protocol ? parsedUrl : url.parse( 'https://' + rawUrl );
};

const hasTld = function( hostname ) {
// Min length of hostname with TLD is 4 characters, e.g. "a.co".
return hostname.length > 3 && inRange( hostname.lastIndexOf( '.' ), 1, hostname.length - 2 );
};

export function validateImportUrl( value ) {
let parsedUrl, formattedUrl;
try {
parsedUrl = parseUrl( value );
formattedUrl = url.format( parsedUrl );
} catch ( error ) {
return translate( 'Please enter a valid URL.' );
}

const { hostname, pathname } = parsedUrl;

// `isURL` considers `http://a` valid, so check for a top level domain name as well.
if ( ! formattedUrl || ! isURL( formattedUrl ) || ! hasTld( hostname ) ) {
return translate( 'Please enter a valid URL.' );
}

if ( hostname === 'editor.wix.com' || hostname === 'www.wix.com' ) {
return translate(
"You've entered a URL for the Wix editor. Please enter your site's public URL. See examples below."
);
}

if ( hostname.indexOf( '.wixsite.com' ) > -1 && pathname === '/' ) {
return translate(
'Please enter the full URL and include the part that comes after %(hostname)s. See example below.',
{
args: {
hostname: '"wixsite.com"',
},
}
);
}

return null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import moment from 'moment';
*/
import wpLib from 'lib/wp';
import config from 'config';
import { validateImportUrl } from 'lib/importers/url-validation';

const wpcom = wpLib.undocumented();

Expand Down Expand Up @@ -201,16 +202,7 @@ class SiteImporterInputPane extends React.Component {
return;
}

let errorMessage;
if ( hostname === 'editor.wix.com' || hostname === 'www.wix.com' ) {
errorMessage = this.props.translate(
"You've entered the URL for the Wix editor, which only you can access. Please enter your site's public URL. It should look like one of the examples below."
);
} else if ( hostname.indexOf( '.wixsite.com' ) > -1 && pathname === '/' ) {
errorMessage = this.props.translate(
"You haven't entered the full URL. Please include the part of the URL that comes after wixsite.com. See below for an example."
);
}
const errorMessage = validateImportUrl( siteURL );

if ( errorMessage ) {
this.setState( {
Expand Down
7 changes: 4 additions & 3 deletions client/signup/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
indexOf,
isEmpty,
isEqual,
kebabCase,
last,
pick,
startsWith,
Expand Down Expand Up @@ -518,7 +519,7 @@ class Signup extends React.Component {

return (
<CSSTransition classNames="signup__step" timeout={ 400 } key={ stepKey }>
<div className="signup__step">
<div className={ `signup__step is-${ kebabCase( this.props.stepName ) }` }>
{ shouldRenderLocaleSuggestions && (
<LocaleSuggestions path={ this.props.path } locale={ this.props.locale } />
) }
Expand Down Expand Up @@ -572,7 +573,7 @@ class Signup extends React.Component {
const showProgressIndicator = 'pressable-nux' === this.props.flowName ? false : true;

return (
<span>
<div className={ `signup is-${ kebabCase( this.props.flowName ) }` }>
<DocumentHead title={ pageTitle } />
{ ! this.state.loadingScreenStartTime &&
showProgressIndicator && (
Expand All @@ -592,7 +593,7 @@ class Signup extends React.Component {
redirectTo={ this.state.redirectTo }
/>
) }
</span>
</div>
);
}
}
Expand Down
Loading

0 comments on commit 36a1c7a

Please sign in to comment.