Merge pull request #728 from bluewave-labs/feat/team-table
Feat/team table, #725
This commit is contained in:
21 files changed
+289
-87
No files matched your search
@@ -290,7 +290,7 @@ function Sidebar() {
|
||||
if (
|
||||
child.name === "Team" &&
|
||||
authState.user?.role &&
|
||||
!authState.user.role.includes("admin")
|
||||
!authState.user.role.includes("superadmin")
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
@@ -350,7 +350,7 @@ function Sidebar() {
|
||||
if (
|
||||
child.name === "Team" &&
|
||||
authState.user?.role &&
|
||||
!authState.user.role.includes("admin")
|
||||
!authState.user.role.includes("superadmin")
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -32,6 +32,12 @@ import Select from "../../Inputs/Select";
|
||||
*/
|
||||
|
||||
const TeamPanel = () => {
|
||||
const roleMap = {
|
||||
superadmin: "Super admin",
|
||||
admin: "Admin",
|
||||
user: "Team member",
|
||||
};
|
||||
|
||||
const theme = useTheme();
|
||||
|
||||
const { authToken, user } = useSelector((state) => state.auth);
|
||||
@@ -78,6 +84,7 @@ const TeamPanel = () => {
|
||||
// { id: 4, name: "ACTION" },
|
||||
],
|
||||
rows: team?.map((member, idx) => {
|
||||
const roles = member.role.map((role) => roleMap[role]).join(",");
|
||||
return {
|
||||
id: member._id,
|
||||
data: [
|
||||
@@ -100,7 +107,7 @@ const TeamPanel = () => {
|
||||
{
|
||||
// TODO - Add select dropdown
|
||||
id: idx + 2,
|
||||
data: member.role.includes("admin") ? "Administrator" : "Member",
|
||||
data: roles,
|
||||
},
|
||||
// FEATURE STILL TO BE IMPLEMENTED
|
||||
// {
|
||||
|
||||
@@ -10,7 +10,7 @@ const withAdminCheck = (WrappedComponent) => {
|
||||
|
||||
useEffect(() => {
|
||||
networkService
|
||||
.doesAdminExist()
|
||||
.doesSuperAdminExist()
|
||||
.then((response) => {
|
||||
if (response.data.data === true) {
|
||||
navigate("/login");
|
||||
@@ -20,7 +20,7 @@ const withAdminCheck = (WrappedComponent) => {
|
||||
logger.error(error);
|
||||
});
|
||||
}, [navigate]);
|
||||
return <WrappedComponent {...props} isAdmin={true} />;
|
||||
return <WrappedComponent {...props} isSuperAdmin={true} />;
|
||||
};
|
||||
const wrappedComponentName =
|
||||
WrappedComponent.displayName || WrappedComponent.name || "Component";
|
||||
|
||||
@@ -25,7 +25,11 @@ const Account = ({ open = "profile" }) => {
|
||||
|
||||
let tabList = ["Profile", "Password", "Team"];
|
||||
const { user } = useSelector((state) => state.auth);
|
||||
if (!user.role.includes("admin")) tabList = ["Profile", "Password"];
|
||||
const requiredRoles = ["superadmin", "admin"];
|
||||
const hideTeams = !requiredRoles.some((role) => user.role.includes(role));
|
||||
if (hideTeams) {
|
||||
tabList = ["Profile", "Password"];
|
||||
}
|
||||
|
||||
return (
|
||||
<Box
|
||||
@@ -71,7 +75,7 @@ const Account = ({ open = "profile" }) => {
|
||||
</Box>
|
||||
<ProfilePanel />
|
||||
<PasswordPanel />
|
||||
{user.role.includes("admin") && <TeamPanel />}
|
||||
{!hideTeams && <TeamPanel />}
|
||||
</TabContext>
|
||||
</Box>
|
||||
);
|
||||
|
||||
@@ -301,7 +301,7 @@ const Login = () => {
|
||||
return;
|
||||
}
|
||||
networkService
|
||||
.doesAdminExist()
|
||||
.doesSuperAdminExist()
|
||||
.then((response) => {
|
||||
if (response.data.data === false) {
|
||||
navigate("/register");
|
||||
|
||||
@@ -23,11 +23,11 @@ import { logger } from "../../../Utils/Logger";
|
||||
* Displays the initial landing page.
|
||||
*
|
||||
* @param {Object} props
|
||||
* @param {boolean} props.isAdmin - Whether the user is creating and admin account
|
||||
* @param {boolean} props.isSuperAdmin - Whether the user is creating and admin account
|
||||
* @param {Function} props.onContinue - Callback function to handle "Continue with Email" button click.
|
||||
* @returns {JSX.Element}
|
||||
*/
|
||||
const LandingPage = ({ isAdmin, onSignup }) => {
|
||||
const LandingPage = ({ isSuperAdmin, onSignup }) => {
|
||||
const theme = useTheme();
|
||||
|
||||
return (
|
||||
@@ -40,7 +40,8 @@ const LandingPage = ({ isAdmin, onSignup }) => {
|
||||
<Box>
|
||||
<Typography component="h1">Sign Up</Typography>
|
||||
<Typography>
|
||||
Create your {isAdmin ? "admin " : ""}account to get started.
|
||||
Create your {isSuperAdmin ? "Super admin " : ""}account to get
|
||||
started.
|
||||
</Typography>
|
||||
</Box>
|
||||
<Box width="100%">
|
||||
@@ -93,7 +94,7 @@ const LandingPage = ({ isAdmin, onSignup }) => {
|
||||
};
|
||||
|
||||
LandingPage.propTypes = {
|
||||
isAdmin: PropTypes.bool,
|
||||
isSuperAdmin: PropTypes.bool,
|
||||
onSignup: PropTypes.func,
|
||||
};
|
||||
|
||||
@@ -422,7 +423,7 @@ StepThree.propTypes = {
|
||||
onBack: PropTypes.func,
|
||||
};
|
||||
|
||||
const Register = ({ isAdmin }) => {
|
||||
const Register = ({ isSuperAdmin }) => {
|
||||
const dispatch = useDispatch();
|
||||
const navigate = useNavigate();
|
||||
const { token } = useParams();
|
||||
@@ -443,6 +444,7 @@ const Register = ({ isAdmin }) => {
|
||||
password: "",
|
||||
confirm: "",
|
||||
role: [],
|
||||
teamId: "",
|
||||
});
|
||||
const [errors, setErrors] = useState({});
|
||||
const [step, setStep] = useState(0);
|
||||
@@ -452,15 +454,16 @@ const Register = ({ isAdmin }) => {
|
||||
if (token !== undefined) {
|
||||
try {
|
||||
const res = await networkService.verifyInvitationToken(token);
|
||||
const { role, email } = res.data.data;
|
||||
setForm({ ...form, email, role });
|
||||
const invite = res.data.data;
|
||||
const { role, email, teamId } = invite;
|
||||
setForm({ ...form, email, role, teamId });
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
navigate("/register", { replace: true });
|
||||
}
|
||||
}
|
||||
};
|
||||
fetchInvite();
|
||||
}, [token, form]);
|
||||
}, []);
|
||||
|
||||
/**
|
||||
* Validates the form data against the validation schema.
|
||||
@@ -493,7 +496,6 @@ const Register = ({ isAdmin }) => {
|
||||
|
||||
const handleStepOne = async (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
let error = validateForm({
|
||||
firstName: form.firstName,
|
||||
lastName: form.lastName,
|
||||
@@ -525,7 +527,10 @@ const Register = ({ isAdmin }) => {
|
||||
const handleStepThree = async (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
let registerForm = { ...form, role: isAdmin ? ["admin"] : form.role };
|
||||
let registerForm = {
|
||||
...form,
|
||||
role: isSuperAdmin ? ["superadmin"] : form.role,
|
||||
};
|
||||
let error = validateForm(registerForm, {
|
||||
context: { password: form.password },
|
||||
});
|
||||
@@ -616,7 +621,10 @@ const Register = ({ isAdmin }) => {
|
||||
}}
|
||||
>
|
||||
{step === 0 ? (
|
||||
<LandingPage isAdmin={isAdmin} onSignup={() => setStep(1)} />
|
||||
<LandingPage
|
||||
isSuperAdmin={isSuperAdmin}
|
||||
onSignup={() => setStep(1)}
|
||||
/>
|
||||
) : step === 1 ? (
|
||||
<StepOne
|
||||
form={form}
|
||||
@@ -664,6 +672,6 @@ const Register = ({ isAdmin }) => {
|
||||
);
|
||||
};
|
||||
Register.propTypes = {
|
||||
isAdmin: PropTypes.bool,
|
||||
isSuperAdmin: PropTypes.bool,
|
||||
};
|
||||
export default Register;
|
||||
@@ -293,8 +293,8 @@ class NetworkService {
|
||||
* @returns {Promise<AxiosResponse>} The response from the axios GET request.
|
||||
*
|
||||
*/
|
||||
async doesAdminExist() {
|
||||
return this.axiosInstance.get("/auth/users/admin");
|
||||
async doesSuperAdminExist() {
|
||||
return this.axiosInstance.get("/auth/users/superadmin");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -327,7 +327,7 @@ class NetworkService {
|
||||
*/
|
||||
async requestInvitationToken(authToken, email, role) {
|
||||
return this.axiosInstance.post(
|
||||
`/auth/invite`,
|
||||
`/invite`,
|
||||
{ email, role },
|
||||
{
|
||||
headers: { Authorization: `Bearer ${authToken}` },
|
||||
@@ -346,7 +346,7 @@ class NetworkService {
|
||||
*
|
||||
*/
|
||||
async verifyInvitationToken(token) {
|
||||
return this.axiosInstance.post(`/auth/invite/verify`, {
|
||||
return this.axiosInstance.post(`/invite/verify`, {
|
||||
token,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -76,6 +76,7 @@ const credentials = joi.object({
|
||||
return value;
|
||||
}),
|
||||
role: joi.array(),
|
||||
teamId: joi.string().allow("").optional(),
|
||||
});
|
||||
|
||||
const monitorValidation = joi.object({
|
||||
|
||||
Reference in new issue
Block a user