refactor: removed withAdminProps HOC and changed for custom hook reducing component wrapping

This commit is contained in:
Caio Cabral committed 2024-12-12 09:07:11 -05:00
1 parent a70e96f1f3
commit 910080820b
10 files changed
+32 -77

No files matched your search

@@ -1,25 +0,0 @@
import { useSelector } from "react-redux";
const withAdminProp = (WrappedComponent) => {
const WithAdminProp = (props) => {
const { user } = useSelector((state) => state.auth);
const isAdmin =
(user?.role?.includes("admin") ?? false) ||
(user?.role?.includes("superadmin") ?? false);
return (
<WrappedComponent
{...props}
isAdmin={isAdmin}
/>
);
};
const wrappedComponentName =
WrappedComponent.displayName || WrappedComponent.name || "Component";
WithAdminProp.displayName = `WithAdminProp(${wrappedComponentName})`;
return WithAdminProp;
};
export default withAdminProp;
@@ -15,7 +15,6 @@ import PropTypes from "prop-types";
const ProtectedRoute = ({ Component, ...rest }) => {
const authState = useSelector((state) => state.auth);
console.log("Protected");
return authState.authToken ? (
<Component {...rest} />
) : (