2024-11-07 04:21:32 -05:00
|
|
|
import { useEffect } from "react";
|
2024-07-19 10:24:01 -07:00
|
|
|
import { useNavigate } from "react-router-dom";
|
2024-08-19 19:02:30 -07:00
|
|
|
|
2024-11-07 04:21:32 -05:00
|
|
|
import { logger } from "../../Utils/Logger";
|
|
|
|
|
import { networkService } from "../../main";
|
2024-07-19 10:24:01 -07:00
|
|
|
|
|
|
|
|
const withAdminCheck = (WrappedComponent) => {
|
2024-10-17 12:05:06 +08:00
|
|
|
const WithAdminCheck = (props) => {
|
|
|
|
|
const navigate = useNavigate();
|
2024-07-19 10:24:01 -07:00
|
|
|
|
2024-10-17 12:05:06 +08:00
|
|
|
useEffect(() => {
|
|
|
|
|
networkService
|
|
|
|
|
.doesSuperAdminExist()
|
|
|
|
|
.then((response) => {
|
|
|
|
|
if (response.data.data === true) {
|
|
|
|
|
navigate("/login");
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
logger.error(error);
|
|
|
|
|
});
|
|
|
|
|
}, [navigate]);
|
|
|
|
|
return (
|
|
|
|
|
<WrappedComponent
|
|
|
|
|
{...props}
|
|
|
|
|
isSuperAdmin={true}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
const wrappedComponentName =
|
|
|
|
|
WrappedComponent.displayName || WrappedComponent.name || "Component";
|
|
|
|
|
WithAdminCheck.displayName = `WithAdminCheck(${wrappedComponentName})`;
|
2024-07-19 10:24:01 -07:00
|
|
|
|
2024-10-17 12:05:06 +08:00
|
|
|
return WithAdminCheck;
|
2024-07-19 10:24:01 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default withAdminCheck;
|