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({
+1 -1
View File
@@ -44,7 +44,7 @@ const registerValidation = joi.object({
/^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*()])[A-Za-z0-9!@#$%^&*()]+$/
),
profileImage: joi.any(),
role: joi.string().required(),
role: joi.array().required(),
});
const editUserParamValidation = joi.object({
+62
View File
@@ -0,0 +1,62 @@
diff --git a/Client/src/Pages/Auth/Register/Register.jsx b/Client/src/Pages/Auth/Register/Register.jsx
index 1eaa99f..a5db763 100644
--- a/Client/src/Pages/Auth/Register/Register.jsx
+++ b/Client/src/Pages/Auth/Register/Register.jsx
@@ -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 },
diff --git a/Client/src/Validation/validation.js b/Client/src/Validation/validation.js
index 779b7c5..00d5a1d 100644
--- a/Client/src/Validation/validation.js
+++ b/Client/src/Validation/validation.js
@@ -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({
diff --git a/Server/validation/joi.js b/Server/validation/joi.js
index a0c5857..ec77363 100644
--- a/Server/validation/joi.js
+++ b/Server/validation/joi.js
@@ -44,7 +44,7 @@ const registerValidation = joi.object({
/^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*()])[A-Za-z0-9!@#$%^&*()]+$/
),
profileImage: joi.any(),
- role: joi.string().required(),
+ role: joi.array().required(),
});

const editUserParamValidation = joi.object({