Skip to content

Commit

Permalink
Add required fields validation
Browse files Browse the repository at this point in the history
  • Loading branch information
carolinesalib committed May 20, 2020
1 parent 7a2d024 commit e0d9674
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion app/javascript/containers/UserSettings/UserSettings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import changePictureImage from "../../images/user_settings_change_picture.svg";
import UserSettingsApi from "../../api/userSettingsApi";

// TODO: password min requirements validation
// TODO: required fields validation
// TODO: phone validation
// TODO: email validation

Expand Down Expand Up @@ -53,6 +52,15 @@ const UserSettings = (props) => {
const validateInput = (userSettings) => {
let errors = {};

['name', 'email', 'phone', 'password'].map((inputName) => {
if (userSettings[inputName].trim() === '') {
errors[inputName] = {
message: "Este campo é obrigatório"
}
}
})


if (userSettings.password !== userSettings.passwordConfirmation) {
errors['password'] = {
message: null
Expand Down Expand Up @@ -105,18 +113,21 @@ const UserSettings = (props) => {
className={classes.textInput}
label="Nome Completo"
value={userSettings.name}
error={formErrors['name']}
onChange={(event) => inputChangedHandler(event, 'name')}
/>
<TextInputWithLabel
className={classes.textInput}
label="Email"
value={userSettings.email}
error={formErrors['email']}
onChange={(event) => inputChangedHandler(event, 'email')}
/>
<TextInputWithLabel
className={classes.textInput}
label="Telefone"
value={userSettings.phone}
error={formErrors['phone']}
onChange={(event) => inputChangedHandler(event, 'phone')}
/>
</div>
Expand Down

0 comments on commit e0d9674

Please sign in to comment.