fleet/frontend/components/forms/ConfirmInviteForm/helpers.jsx
jacobshandling 55fd95d760
UI – Updates to confirm invite flow (#25583)
## 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**

![invalid](https://github.com/user-attachments/assets/c42c47ca-6a0d-4112-89ea-68b77e748d12)


**Valid invite**

![valid-login-flow](https://github.com/user-attachments/assets/f2b97306-a1bd-47be-9725-968a3c4ad8a8)



- [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>
2025-01-24 10:55:39 -08:00

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 };