Skip to content

Commit

Permalink
Fixes #1903: User now notified if emailID is taken in real time
Browse files Browse the repository at this point in the history
  • Loading branch information
Pipe-Runner authored and akshatnitd committed Feb 11, 2019
1 parent 3a73a1e commit 60bcdbc
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
8 changes: 8 additions & 0 deletions src/api/index.js
Expand Up @@ -341,3 +341,11 @@ export function fetchUserSkill(payload) {
applyFilter: 'true',
});
}

export function getEmailExists(payload) {
const { email } = payload;
const url = `${API_URL}/${AUTH_API_PREFIX}/checkRegistration.json`;
return ajax.get(url, {
check_email: email,
});
}
35 changes: 29 additions & 6 deletions src/components/Auth/SignUp/SignUp.js
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
import zxcvbn from 'zxcvbn';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { debounce } from 'lodash';

/* Material-UI */
import PasswordField from 'material-ui-password-field';
Expand All @@ -17,6 +18,7 @@ import { colors, isEmail } from '../../../utils';
import Recaptcha from 'react-recaptcha';
import appActions from '../../../redux/actions/app';
import uiActions from '../../../redux/actions/ui';
import { getEmailExists } from '../../../api';

/* CSS */
import './SignUp.css';
Expand Down Expand Up @@ -94,6 +96,8 @@ class SignUp extends Component {
captchaVerifyErrorMessage: '',
loading: false,
};

this.debouncedIsEmailAvailable = debounce(this.isEmailAvailable, 700);
}

closeDialog = () => {
Expand Down Expand Up @@ -131,16 +135,35 @@ class SignUp extends Component {
}
};

isEmailAvailable = () => {
const { email, emailErrorMessage } = this.state;
if (!emailErrorMessage) {
getEmailExists({
email,
}).then(payload => {
const { exists } = payload;
this.setState({
emailErrorMessage: exists
? 'Email ID already taken, please use another account'
: '',
});
});
}
};

handleTextFieldChange = event => {
switch (event.target.name) {
case 'email': {
const email = event.target.value.trim();
this.setState({
email,
emailErrorMessage: !isEmail(email)
? 'Enter a valid Email Address'
: '',
});
this.setState(
{
email,
emailErrorMessage: !isEmail(email)
? 'Enter a valid Email Address'
: '',
},
this.debouncedIsEmailAvailable,
);
break;
}
case 'password': {
Expand Down

0 comments on commit 60bcdbc

Please sign in to comment.