feat: UI no-admin (vistas mis/asignados/sin-asignar, config solo admin)
This commit is contained in:
1 parent
3a1fee74e7
commit
a68999eca7
6 files changed
+124
-13
No files matched your search
@@ -8,9 +8,11 @@ import {
|
||||
deleteGroup,
|
||||
type Group,
|
||||
} from "@/lib/api";
|
||||
import { useAuth } from "@/lib/auth";
|
||||
import Modal from "@/components/Modal";
|
||||
|
||||
export default function DepartmentsPage() {
|
||||
const { user, isLoading: authLoading } = useAuth();
|
||||
const [groups, setGroups] = useState<Group[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState("");
|
||||
@@ -36,8 +38,13 @@ export default function DepartmentsPage() {
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (authLoading) return;
|
||||
if (user?.role !== "admin") {
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
fetchGroups();
|
||||
}, [fetchGroups]);
|
||||
}, [fetchGroups, authLoading, user?.role]);
|
||||
|
||||
const openCreate = () => {
|
||||
setEditing(null);
|
||||
@@ -94,6 +101,20 @@ export default function DepartmentsPage() {
|
||||
}
|
||||
};
|
||||
|
||||
if (!authLoading && user?.role !== "admin") {
|
||||
return (
|
||||
<div>
|
||||
<div className="page-header">
|
||||
<h1>Departamentos</h1>
|
||||
</div>
|
||||
<div className="alert alert-warning" role="alert">
|
||||
<i className="bi bi-shield-lock me-2"></i>
|
||||
Solo los administradores pueden gestionar departamentos.
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="page-header">
|
||||
|
||||
Reference in new issue
Block a user