fix(client): Email and internet presence client validation (#37389)
parent
7a6e8ed2d8
commit
e4a26c9a74
|
@ -100,7 +100,7 @@ class EmailSettings extends Component {
|
||||||
return { state: 'success', message: '' };
|
return { state: 'success', message: '' };
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
state: 'warning',
|
state: 'error',
|
||||||
message:
|
message:
|
||||||
'We could not validate your email correctly, ' +
|
'We could not validate your email correctly, ' +
|
||||||
'please ensure it is correct'
|
'please ensure it is correct'
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import React, { Fragment, Component } from 'react';
|
import React, { Fragment, Component } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import {
|
import {
|
||||||
|
HelpBlock,
|
||||||
FormControl,
|
FormControl,
|
||||||
FormGroup,
|
FormGroup,
|
||||||
ControlLabel
|
ControlLabel
|
||||||
|
@ -40,12 +41,23 @@ class InternetSettings extends Component {
|
||||||
|
|
||||||
getValidationStateFor(maybeURl = '') {
|
getValidationStateFor(maybeURl = '') {
|
||||||
if (!maybeURl || !maybeUrlRE.test(maybeURl)) {
|
if (!maybeURl || !maybeUrlRE.test(maybeURl)) {
|
||||||
return null;
|
return {
|
||||||
|
state: null,
|
||||||
|
message: ''
|
||||||
|
};
|
||||||
}
|
}
|
||||||
if (isURL(maybeURl)) {
|
if (isURL(maybeURl)) {
|
||||||
return 'success';
|
return {
|
||||||
|
state: 'success',
|
||||||
|
message: ''
|
||||||
|
};
|
||||||
}
|
}
|
||||||
return 'error';
|
return {
|
||||||
|
state: 'error',
|
||||||
|
message:
|
||||||
|
'We could not validate your URL correctly, ' +
|
||||||
|
'please ensure it is correct'
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
createHandleChange = key => e => {
|
createHandleChange = key => e => {
|
||||||
|
@ -88,6 +100,27 @@ class InternetSettings extends Component {
|
||||||
const {
|
const {
|
||||||
formValues: { githubProfile, linkedin, twitter, website }
|
formValues: { githubProfile, linkedin, twitter, website }
|
||||||
} = this.state;
|
} = this.state;
|
||||||
|
|
||||||
|
const {
|
||||||
|
state: githubProfileValidation,
|
||||||
|
message: githubProfileValidationMessage
|
||||||
|
} = this.getValidationStateFor(githubProfile);
|
||||||
|
|
||||||
|
const {
|
||||||
|
state: linkedinValidation,
|
||||||
|
message: linkedinValidationMessage
|
||||||
|
} = this.getValidationStateFor(linkedin);
|
||||||
|
|
||||||
|
const {
|
||||||
|
state: twitterValidation,
|
||||||
|
message: twitterValidationMessage
|
||||||
|
} = this.getValidationStateFor(twitter);
|
||||||
|
|
||||||
|
const {
|
||||||
|
state: websiteValidation,
|
||||||
|
message: websiteValidationMessage
|
||||||
|
} = this.getValidationStateFor(website);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<SectionHeader>Your Internet Presence</SectionHeader>
|
<SectionHeader>Your Internet Presence</SectionHeader>
|
||||||
|
@ -95,55 +128,59 @@ class InternetSettings extends Component {
|
||||||
<form id='internet-presence' onSubmit={this.handleSubmit}>
|
<form id='internet-presence' onSubmit={this.handleSubmit}>
|
||||||
<FormGroup
|
<FormGroup
|
||||||
controlId='internet-github'
|
controlId='internet-github'
|
||||||
validationState={this.getValidationStateFor(githubProfile)}
|
validationState={githubProfileValidation}
|
||||||
>
|
>
|
||||||
<ControlLabel>
|
<ControlLabel>GitHub</ControlLabel>
|
||||||
<strong>GitHub</strong>
|
|
||||||
</ControlLabel>
|
|
||||||
<FormControl
|
<FormControl
|
||||||
onChange={this.createHandleChange('githubProfile')}
|
onChange={this.createHandleChange('githubProfile')}
|
||||||
type='url'
|
type='url'
|
||||||
value={githubProfile}
|
value={githubProfile}
|
||||||
/>
|
/>
|
||||||
|
{githubProfileValidationMessage ? (
|
||||||
|
<HelpBlock>{githubProfileValidationMessage}</HelpBlock>
|
||||||
|
) : null}
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
<FormGroup
|
<FormGroup
|
||||||
controlId='internet-linkedin'
|
controlId='internet-linkedin'
|
||||||
validationState={this.getValidationStateFor(linkedin)}
|
validationState={linkedinValidation}
|
||||||
>
|
>
|
||||||
<ControlLabel>
|
<ControlLabel>LinkedIn</ControlLabel>
|
||||||
<strong>LinkedIn</strong>
|
|
||||||
</ControlLabel>
|
|
||||||
<FormControl
|
<FormControl
|
||||||
onChange={this.createHandleChange('linkedin')}
|
onChange={this.createHandleChange('linkedin')}
|
||||||
type='url'
|
type='url'
|
||||||
value={linkedin}
|
value={linkedin}
|
||||||
/>
|
/>
|
||||||
|
{linkedinValidationMessage ? (
|
||||||
|
<HelpBlock>{linkedinValidationMessage}</HelpBlock>
|
||||||
|
) : null}
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
<FormGroup
|
<FormGroup
|
||||||
controlId='internet-picture'
|
controlId='internet-picture'
|
||||||
validationState={this.getValidationStateFor(twitter)}
|
validationState={twitterValidation}
|
||||||
>
|
>
|
||||||
<ControlLabel>
|
<ControlLabel>Twitter</ControlLabel>
|
||||||
<strong>Twitter</strong>
|
|
||||||
</ControlLabel>
|
|
||||||
<FormControl
|
<FormControl
|
||||||
onChange={this.createHandleChange('twitter')}
|
onChange={this.createHandleChange('twitter')}
|
||||||
type='url'
|
type='url'
|
||||||
value={twitter}
|
value={twitter}
|
||||||
/>
|
/>
|
||||||
|
{twitterValidationMessage ? (
|
||||||
|
<HelpBlock>{twitterValidationMessage}</HelpBlock>
|
||||||
|
) : null}
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
<FormGroup
|
<FormGroup
|
||||||
controlId='internet-website'
|
controlId='internet-website'
|
||||||
validationState={this.getValidationStateFor(website)}
|
validationState={websiteValidation}
|
||||||
>
|
>
|
||||||
<ControlLabel>
|
<ControlLabel>Personal Website</ControlLabel>
|
||||||
<strong>Personal Website</strong>
|
|
||||||
</ControlLabel>
|
|
||||||
<FormControl
|
<FormControl
|
||||||
onChange={this.createHandleChange('website')}
|
onChange={this.createHandleChange('website')}
|
||||||
type='url'
|
type='url'
|
||||||
value={website}
|
value={website}
|
||||||
/>
|
/>
|
||||||
|
{websiteValidationMessage ? (
|
||||||
|
<HelpBlock>{websiteValidationMessage}</HelpBlock>
|
||||||
|
) : null}
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
<BlockSaveButton
|
<BlockSaveButton
|
||||||
disabled={
|
disabled={
|
||||||
|
|
Loading…
Reference in New Issue