mirror of
https://github.com/opensupports/opensupports.git
synced 2025-07-31 01:35:15 +02:00
Revert "[Ivan Diaz] - OS-#10 - Add validations [skip ci]"
This reverts commit 8d7d0a93bfbc228b02a2df1d6e12dcc62867d4d5.
This commit is contained in:
parent
8d7d0a93bf
commit
3c22a2e8af
@ -33,7 +33,7 @@ let MainHomePageLoginWidget = React.createClass({
|
|||||||
<Widget className="main-home-page--widget" title="Login">
|
<Widget className="main-home-page--widget" title="Login">
|
||||||
<Form className="login-widget--form" onSubmit={this.handleLoginFormSubmit}>
|
<Form className="login-widget--form" onSubmit={this.handleLoginFormSubmit}>
|
||||||
<div className="login-widget--inputs">
|
<div className="login-widget--inputs">
|
||||||
<Input placeholder="email" name="email" className="login-widget--input" validation="EMAIL"/>
|
<Input placeholder="email" name="email" className="login-widget--input"/>
|
||||||
<Input placeholder="password" name="password" className="login-widget--input" password/>
|
<Input placeholder="password" name="password" className="login-widget--input" password/>
|
||||||
<Checkbox name="remember" label="Remember Me" className="login-widget--input"/>
|
<Checkbox name="remember" label="Remember Me" className="login-widget--input"/>
|
||||||
</div>
|
</div>
|
||||||
@ -53,7 +53,7 @@ let MainHomePageLoginWidget = React.createClass({
|
|||||||
<Widget className="main-home-page--widget main-home-page--password-widget" title="Password Recovery">
|
<Widget className="main-home-page--widget main-home-page--password-widget" title="Password Recovery">
|
||||||
<Form className="login-widget--form" onSubmit={this.handleSubmit}>
|
<Form className="login-widget--form" onSubmit={this.handleSubmit}>
|
||||||
<div className="login-widget--inputs">
|
<div className="login-widget--inputs">
|
||||||
<Input placeholder="email" name="email" className="login-widget--input" validation="EMAIL"/>
|
<Input placeholder="email" name="email" className="login-widget--input"/>
|
||||||
</div>
|
</div>
|
||||||
<div className="login-widget--submit-button">
|
<div className="login-widget--submit-button">
|
||||||
<Button type="primary">Recover my password</Button>
|
<Button type="primary">Recover my password</Button>
|
||||||
|
@ -1,40 +1,35 @@
|
|||||||
const React = require('react');
|
import React from 'react';
|
||||||
const _ = require('lodash');
|
import _ from 'lodash';
|
||||||
|
|
||||||
const {reactDFS, renderChildrenWithProps} = require('lib-core/react-dfs');
|
import {reactDFS, renderChildrenWithProps} from 'lib-core/react-dfs';
|
||||||
const ValidationFactory = require('lib-app/validations/validations-factory');
|
|
||||||
|
|
||||||
const Input = require('core-components/input');
|
import Input from 'core-components/input';
|
||||||
const Checkbox = require('core-components/checkbox');
|
import Checkbox from 'core-components/checkbox';
|
||||||
|
|
||||||
const Form = React.createClass({
|
let Form = React.createClass({
|
||||||
|
|
||||||
|
validations: {},
|
||||||
|
|
||||||
getInitialState() {
|
getInitialState() {
|
||||||
return {
|
return {
|
||||||
form: {},
|
form: {}
|
||||||
validations: {},
|
|
||||||
errors: {}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
let formState = {};
|
let formState = {};
|
||||||
let validations = {};
|
|
||||||
|
|
||||||
reactDFS(this.props.children, function (child) {
|
reactDFS(this.props.children, (child) => {
|
||||||
if (child.type === Input) {
|
if (child.type === Input) {
|
||||||
formState[child.props.name] = child.props.value || '';
|
formState[child.props.name] = child.props.value || '';
|
||||||
validations[child.props.name] = ValidationFactory.getValidator(child.props.validation || 'DEFAULT');
|
|
||||||
}
|
}
|
||||||
else if (child.type === Checkbox) {
|
else if (child.type === Checkbox) {
|
||||||
formState[child.props.name] = child.props.checked || false;
|
formState[child.props.name] = child.props.checked || false;
|
||||||
validations[child.props.name] = ValidationFactory.getValidator(child.props.validation || 'DEFAULT');
|
|
||||||
}
|
}
|
||||||
}.bind(this));
|
});
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
form: formState,
|
form: formState
|
||||||
validations: validations
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -60,65 +55,37 @@ const Form = React.createClass({
|
|||||||
if (type === Input || type === Checkbox) {
|
if (type === Input || type === Checkbox) {
|
||||||
let inputName = props.name;
|
let inputName = props.name;
|
||||||
|
|
||||||
|
this.validations[inputName] = props.validation;
|
||||||
|
|
||||||
additionalProps = {
|
additionalProps = {
|
||||||
ref: inputName,
|
onChange: this.handleInputChange.bind(this, inputName, type),
|
||||||
value: this.state.form[inputName] || props.value,
|
value: this.state.form[inputName] || props.value
|
||||||
error: this.state.errors[inputName],
|
|
||||||
onChange: this.handleInputChange.bind(this, inputName, type)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return additionalProps;
|
return additionalProps;
|
||||||
},
|
},
|
||||||
|
|
||||||
handleSubmit(event) {
|
handleSubmit (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
if (this.hasFormErrors()) {
|
if (this.props.onSubmit) {
|
||||||
this.focusFirstErrorField();
|
|
||||||
} else if (this.props.onSubmit) {
|
|
||||||
this.props.onSubmit(this.state.form);
|
this.props.onSubmit(this.state.form);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
handleInputChange(inputName, type, event) {
|
handleInputChange(inputName, type, event) {
|
||||||
let form = _.clone(this.state.form);
|
let form = _.clone(this.state.form);
|
||||||
let errors = _.clone(this.state.errors);
|
|
||||||
let inputValue = event.target.value;
|
|
||||||
|
|
||||||
form[inputName] = inputValue;
|
form[inputName] = event.target.value;
|
||||||
errors[inputName] = this.state.validations[inputName].validate(inputValue, form);
|
|
||||||
|
|
||||||
if (type === Checkbox) {
|
if (type === Checkbox) {
|
||||||
form[inputName] = event.target.checked || false;
|
form[inputName] = event.target.checked || false;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(errors);
|
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
form: form,
|
form: form
|
||||||
errors: errors
|
|
||||||
});
|
});
|
||||||
},
|
|
||||||
|
|
||||||
hasFormErrors() {
|
|
||||||
return _.some(this.validateAllFields(), (error) => error);
|
|
||||||
},
|
|
||||||
|
|
||||||
focusFirstErrorField() {
|
|
||||||
let firstErrorField = this.getFirstErrorField();
|
|
||||||
|
|
||||||
if (firstErrorField) {
|
|
||||||
this.refs[firstErrorField].focus();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
getFirstErrorField() {
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
validateAllFields: function () {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
const React = require('react');
|
import React from 'react';
|
||||||
const classNames = require('classnames');
|
import classNames from 'classnames';
|
||||||
const _ = require('lodash');
|
import _ from 'lodash';
|
||||||
|
|
||||||
const Input = React.createClass({
|
let Input = React.createClass({
|
||||||
|
|
||||||
propTypes: {
|
propTypes: {
|
||||||
value: React.PropTypes.string,
|
value: React.PropTypes.string,
|
||||||
validation: React.PropTypes.string,
|
validation: React.PropTypes.func,
|
||||||
onChange: React.PropTypes.func,
|
onChange: React.PropTypes.func,
|
||||||
inputType: React.PropTypes.string,
|
inputType: React.PropTypes.string,
|
||||||
password: React.PropTypes.bool
|
password: React.PropTypes.bool
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
const englishLanguage = require('data/languages/en');
|
import keys from 'data/i18n-keys'
|
||||||
const spanishLanguage = require('data/languages/es');
|
|
||||||
|
|
||||||
const languages = {
|
let languages = [
|
||||||
'us': englishLanguage,
|
'us',
|
||||||
'es': spanishLanguage
|
'es'
|
||||||
};
|
];
|
||||||
|
|
||||||
const i18nData = function (key, lang) {
|
|
||||||
return languages[lang][key];
|
let i18nData = function (key, lang) {
|
||||||
|
let langIndex = languages.indexOf(lang);
|
||||||
|
|
||||||
|
return keys[key][langIndex];
|
||||||
};
|
};
|
||||||
|
|
||||||
export default i18nData
|
export default i18nData
|
||||||
|
5
client/src/data/i18n-keys.js
Normal file
5
client/src/data/i18n-keys.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
export default {
|
||||||
|
'SUBMIT': ['Submit', 'Enviar'],
|
||||||
|
'LOG_IN': ['Log in', 'Ingresar'],
|
||||||
|
'SIGN_UP': ['Sign up', 'Registrarse']
|
||||||
|
};
|
@ -1,7 +0,0 @@
|
|||||||
export default {
|
|
||||||
'SUBMIT': 'Submit',
|
|
||||||
'LOG_IN': 'Log in',
|
|
||||||
'SIGN_UP': 'Sign up',
|
|
||||||
'ERROR_EMPTY': 'Invalid value',
|
|
||||||
'ERROR_EMAIL': 'Invalid email'
|
|
||||||
};
|
|
@ -1,7 +0,0 @@
|
|||||||
export default {
|
|
||||||
'SUBMIT': 'Enviar',
|
|
||||||
'LOG_IN': 'Ingresar',
|
|
||||||
'SIGN_UP': 'Registrarse',
|
|
||||||
'ERROR_EMPTY': 'Valor invalido',
|
|
||||||
'ERROR_EMAIL': 'Email invalido'
|
|
||||||
};
|
|
@ -1,11 +0,0 @@
|
|||||||
const Validator = require('lib-app/validations/validator');
|
|
||||||
|
|
||||||
class EmailValidator extends Validator {
|
|
||||||
|
|
||||||
validate(value, form) {
|
|
||||||
if (!value.length) return this.getError('ERROR_EMPTY');
|
|
||||||
if (value.indexOf('@') === -1) return this.getError('ERROR_EMAIL');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default EmailValidator;
|
|
@ -1,16 +0,0 @@
|
|||||||
const Validator = require('lib-app/validations/validator');
|
|
||||||
const EmailValidator = require('lib-app/validations/email-validator');
|
|
||||||
|
|
||||||
let validators = {
|
|
||||||
'DEFAULT': new Validator(),
|
|
||||||
'EMAIL': new EmailValidator()
|
|
||||||
};
|
|
||||||
|
|
||||||
class ValidatorFactory {
|
|
||||||
|
|
||||||
static getValidator(validatorKey) {
|
|
||||||
return validators[validatorKey];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default ValidatorFactory;
|
|
@ -1,13 +0,0 @@
|
|||||||
const i18n = require('lib-app/i18n');
|
|
||||||
|
|
||||||
class Validator {
|
|
||||||
validate(value, form) {
|
|
||||||
if (!value.length) return this.getError('ERROR_EMPTY');
|
|
||||||
}
|
|
||||||
|
|
||||||
getError(errorKey) {
|
|
||||||
return i18n(errorKey);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Validator
|
|
Loading…
x
Reference in New Issue
Block a user