mirror of
https://github.com/bluewave-labs/Checkmate.git
synced 2026-01-29 13:19:33 -06:00
26 lines
613 B
JavaScript
26 lines
613 B
JavaScript
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;
|