fleet/frontend/components/forms/LoginForm/validate.js
Jacob Shandling 6b70d11bc6
UI: Login page bugs (#11520)
## Addresses #11338 

-  Validate emails on login page
- Fix jumping error state for no email provided ("Email field must be
completed")
- Fix jumping error state for password field
- Fix jumping error state for Forgot password > email field

https://www.loom.com/share/92a238fcd2614d6e8d2655d571aa2757

# Checklist for submitter

If some of the following don't apply, delete the relevant line.

- [x] Changes file added for user-visible changes in `changes/`
- [x] Added/updated tests
- [x] Manual QA for all new/changed functionality

---------

Co-authored-by: Jacob Shandling <[email protected]>
2023-05-09 10:12:29 -07:00

24 lines
650 B
JavaScript

import { size } from "lodash";
import validatePresence from "components/forms/validators/validate_presence";
import validateEmail from "components/forms/validators/valid_email";
const validate = (formData) => {
const errors = {};
const { password, email } = formData;
if (!validatePresence(email)) {
errors.email = "Email field must be completed";
} else if (!validateEmail(email)) {
errors.email = "Email must be a valid email address";
}
if (!validatePresence(password)) {
errors.password = "Password field must be completed";
}
const valid = !size(errors);
return { valid, errors };
};
export default validate;