Updated register page and validation to new role schema

This commit is contained in:
Alex Holliday committed 2024-07-23 11:25:25 -07:00
1 parent 59f5c05b3e
commit 3b7f1b876f
4 files changed
+68 -6

No files matched your search

+4 -2
View File
@@ -14,10 +14,12 @@ import { credentials } from "../../../Validation/validation";
import { createToast } from "../../../Utils/toastUtils";
import Field from "../../../Components/Inputs/Field";
import { register } from "../../../Features/Auth/authSlice";
import { useParams } from "react-router-dom";
const Register = ({ isAdmin }) => {
const dispatch = useDispatch();
const navigate = useNavigate();
const { token } = useParams();
const theme = useTheme();
// TODO If possible, change the IDs of these fields to match the backend
@@ -35,14 +37,14 @@ const Register = ({ isAdmin }) => {
email: "",
password: "",
confirm: "",
role: "",
role: [],
});
const [errors, setErrors] = useState({});
const handleSubmit = async (e) => {
e.preventDefault();
const registerForm = { ...form, role: isAdmin ? "admin" : "user" };
const registerForm = { ...form, role: isAdmin ? ["admin"] : [] };
const { error } = credentials.validate(registerForm, {
abortEarly: false,
context: { password: form.password },
+1 -3
View File
@@ -68,9 +68,7 @@ const credentials = joi.object({
}
return value;
}),
role: joi.string().messages({
"string.empty": "Role is required",
}),
role: joi.array().required(),
});
const monitorValidation = joi.object({