mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 21:47:20 +00:00
## For #24486 - Check invite validity before rendering form, error if invalid - Use data returned from validity check to pre-populate form - Remove dependence of flow on URL params other than token - Remove other URL params from link generated in invite confirmation email - Refactor form from JS to TS - Refactor form from class to functional components - Cleanup unused logic - Improve error handling **Invalid invite**  **Valid invite**  - [x] Changes file added for user-visible changes in `changes/` - [x] Updated tests - [ ] A detailed QA plan exists on the associated ticket (if it isn't there, work with the product group's QA engineer to add it) - [x] Manual QA for all new/changed functionality --------- Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
38 lines
816 B
JavaScript
38 lines
816 B
JavaScript
import { size } from "lodash";
|
|
import validateEquality from "components/forms/validators/validate_equality";
|
|
|
|
const validate = (formData) => {
|
|
const errors = {};
|
|
const {
|
|
name,
|
|
password,
|
|
password_confirmation: passwordConfirmation,
|
|
} = formData;
|
|
|
|
if (!name) {
|
|
errors.name = "Full name must be present";
|
|
}
|
|
|
|
if (
|
|
password &&
|
|
passwordConfirmation &&
|
|
!validateEquality(password, passwordConfirmation)
|
|
) {
|
|
errors.password_confirmation =
|
|
"Password confirmation does not match password";
|
|
}
|
|
|
|
if (!password) {
|
|
errors.password = "Password must be present";
|
|
}
|
|
|
|
if (!passwordConfirmation) {
|
|
errors.password_confirmation = "Password confirmation must be present";
|
|
}
|
|
|
|
const valid = !size(errors);
|
|
|
|
return { valid, errors };
|
|
};
|
|
|
|
export default { validate };
|