mirror of
https://github.com/bluewave-labs/Checkmate.git
synced 2026-05-07 00:59:29 -05:00
Merge pull request #432 from bluewave-labs/feat/invite-registration
Feat/invite_registration
This commit is contained in:
@@ -185,7 +185,7 @@ const TeamPanel = () => {
|
||||
"/auth/invite",
|
||||
{
|
||||
email: toInvite.email,
|
||||
role: [toInvite.role],
|
||||
role: toInvite.role,
|
||||
},
|
||||
{ headers: { Authorization: `Bearer ${authToken}` } }
|
||||
);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useState } from "react";
|
||||
import { useState, useEffect } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useTheme } from "@emotion/react";
|
||||
import { Stack, Typography } from "@mui/material";
|
||||
@@ -15,13 +15,13 @@ import { createToast } from "../../../Utils/toastUtils";
|
||||
import Field from "../../../Components/Inputs/Field";
|
||||
import { register } from "../../../Features/Auth/authSlice";
|
||||
import { useParams } from "react-router-dom";
|
||||
import axiosInstance from "../../../Utils/axiosConfig";
|
||||
|
||||
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
|
||||
const idMap = {
|
||||
"register-firstname-input": "firstName",
|
||||
@@ -41,10 +41,27 @@ const Register = ({ isAdmin }) => {
|
||||
});
|
||||
const [errors, setErrors] = useState({});
|
||||
|
||||
useEffect(() => {
|
||||
const fetchInvite = async () => {
|
||||
if (token !== undefined) {
|
||||
try {
|
||||
const res = await axiosInstance.post(`/auth/invite/verify`, {
|
||||
token,
|
||||
});
|
||||
const { role, email } = res.data.data;
|
||||
console.log(role);
|
||||
setForm({ ...form, email, role });
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
};
|
||||
fetchInvite();
|
||||
}, [token]);
|
||||
|
||||
const handleSubmit = async (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
const registerForm = { ...form, role: isAdmin ? ["admin"] : [] };
|
||||
const registerForm = { ...form, role: isAdmin ? ["admin"] : form.role };
|
||||
const { error } = credentials.validate(registerForm, {
|
||||
abortEarly: false,
|
||||
context: { password: form.password },
|
||||
|
||||
@@ -68,7 +68,7 @@ const credentials = joi.object({
|
||||
}
|
||||
return value;
|
||||
}),
|
||||
role: joi.array().required(),
|
||||
role: joi.array(),
|
||||
});
|
||||
|
||||
const monitorValidation = joi.object({
|
||||
|
||||
Reference in New Issue
Block a user