2021-04-12 13:32:25 +00:00
|
|
|
import { size } from "lodash";
|
|
|
|
|
import validateEquality from "components/forms/validators/validate_equality";
|
2016-12-29 20:27:43 +00:00
|
|
|
|
|
|
|
|
const validate = (formData) => {
|
|
|
|
|
const errors = {};
|
|
|
|
|
const {
|
|
|
|
|
name,
|
|
|
|
|
password,
|
|
|
|
|
password_confirmation: passwordConfirmation,
|
|
|
|
|
} = formData;
|
|
|
|
|
|
|
|
|
|
if (!name) {
|
2021-04-12 13:32:25 +00:00
|
|
|
errors.name = "Full name must be present";
|
2016-12-29 20:27:43 +00:00
|
|
|
}
|
|
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
if (
|
|
|
|
|
password &&
|
|
|
|
|
passwordConfirmation &&
|
|
|
|
|
!validateEquality(password, passwordConfirmation)
|
|
|
|
|
) {
|
|
|
|
|
errors.password_confirmation =
|
|
|
|
|
"Password confirmation does not match password";
|
2016-12-29 20:27:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!password) {
|
2021-04-12 13:32:25 +00:00
|
|
|
errors.password = "Password must be present";
|
2016-12-29 20:27:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!passwordConfirmation) {
|
2021-04-12 13:32:25 +00:00
|
|
|
errors.password_confirmation = "Password confirmation must be present";
|
2016-12-29 20:27:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const valid = !size(errors);
|
|
|
|
|
|
|
|
|
|
return { valid, errors };
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default { validate };
|