Add conditional rendering for admin account

This commit is contained in:
Alex Holliday committed 2024-07-19 10:29:43 -07:00
1 parent 61b16147cb
commit dcb7ccee80
2 files changed
+8 -7

No files matched your search

+1 -1
View File
@@ -19,7 +19,7 @@ const withAdminCheck = (WrappedComponent) => {
console.log(error); console.log(error);
}); });
}, [navigate]); }, [navigate]);
return <WrappedComponent {...props} />; return <WrappedComponent {...props} isAdmin={true} />;
}; };
const wrappedComponentName = const wrappedComponentName =
WrappedComponent.displayName || WrappedComponent.name || "Component"; WrappedComponent.displayName || WrappedComponent.name || "Component";
+7 -6
View File
@@ -15,7 +15,8 @@ import Field from "../../../Components/Inputs/Field";
import withAdminCheck from "../../../HOC/withAdminCheck"; import withAdminCheck from "../../../HOC/withAdminCheck";
import { register } from "../../../Features/Auth/authSlice"; import { register } from "../../../Features/Auth/authSlice";
const Register = () => { const Register = ({ isAdmin }) => {
console.log(isAdmin);
const dispatch = useDispatch(); const dispatch = useDispatch();
const navigate = useNavigate(); const navigate = useNavigate();
const theme = useTheme(); const theme = useTheme();
@@ -42,8 +43,8 @@ const Register = () => {
const handleSubmit = async (e) => { const handleSubmit = async (e) => {
e.preventDefault(); e.preventDefault();
const adminForm = { ...form, role: "admin" }; const form = { ...form, role: isAdmin ? "admin" : "user" };
const { error } = credentials.validate(adminForm, { const { error } = credentials.validate(form, {
abortEarly: false, abortEarly: false,
context: { password: form.password }, context: { password: form.password },
}); });
@@ -62,8 +63,8 @@ const Register = () => {
: "Error validating data.", : "Error validating data.",
}); });
} else { } else {
delete adminForm.confirm; delete form.confirm;
const action = await dispatch(register(adminForm)); const action = await dispatch(register(form));
if (action.payload.success) { if (action.payload.success) {
const token = action.payload.data; const token = action.payload.data;
localStorage.setItem("token", token); localStorage.setItem("token", token);
@@ -119,7 +120,7 @@ const Register = () => {
<Stack gap={theme.gap.small} alignItems="center"> <Stack gap={theme.gap.small} alignItems="center">
<Logomark alt="BlueWave Uptime Icon" /> <Logomark alt="BlueWave Uptime Icon" />
<Typography component="h1" sx={{ mt: theme.gap.xl }}> <Typography component="h1" sx={{ mt: theme.gap.xl }}>
Create admin account Create{isAdmin ? " admin " : " "}account
</Typography> </Typography>
</Stack> </Stack>
<Stack gap={theme.gap.large} sx={{ mt: `calc(${theme.gap.ml}*2)` }}> <Stack gap={theme.gap.large} sx={{ mt: `calc(${theme.gap.ml}*2)` }}>