refactor(web): eliminar guards inline rol admin en páginas de roles/permisos [UDT-006]

This commit is contained in:
2026-04-15 16:49:21 -03:00
parent f6cdd7650b
commit 96e7290fb7
4 changed files with 1 additions and 33 deletions

View File

@@ -1,6 +1,4 @@
import { useState } from 'react'
import { useNavigate } from 'react-router-dom'
import { useAuthStore } from '@/stores/authStore'
import {
Card,
CardContent,
@@ -12,17 +10,10 @@ import { useRoles } from '../../roles/hooks/useRoles'
import { RolPermisosEditor } from '../components/RolPermisosEditor'
export function RolPermisosPage() {
const navigate = useNavigate()
const user = useAuthStore((s) => s.user)
const [selectedRol, setSelectedRol] = useState<string | null>(null)
const { data: roles, isLoading: loadingRoles } = useRoles()
if (!user || user.rol !== 'admin') {
void navigate('/', { replace: true })
return null
}
const rolesActivos = roles?.filter((r) => r.activo) ?? []
return (

View File

@@ -1,5 +1,4 @@
import { useNavigate, useParams } from 'react-router-dom'
import { useAuthStore } from '@/stores/authStore'
import {
Card,
CardContent,
@@ -15,14 +14,8 @@ import { EditRolForm } from '../components/RolForm'
export function EditRolPage() {
const navigate = useNavigate()
const { codigo } = useParams<{ codigo: string }>()
const user = useAuthStore((s) => s.user)
const { data: rol, isLoading, isError } = useRol(codigo)
if (!user || user.rol !== 'admin') {
void navigate('/', { replace: true })
return null
}
return (
<div className="flex justify-center py-8">
<Card className="w-full max-w-lg">

View File

@@ -1,5 +1,4 @@
import { useNavigate } from 'react-router-dom'
import { useAuthStore } from '@/stores/authStore'
import {
Card,
CardContent,
@@ -11,12 +10,6 @@ import { CreateRolForm } from '../components/RolForm'
export function NewRolPage() {
const navigate = useNavigate()
const user = useAuthStore((s) => s.user)
if (!user || user.rol !== 'admin') {
void navigate('/', { replace: true })
return null
}
return (
<div className="flex justify-center py-8">

View File

@@ -1,5 +1,4 @@
import { Link, useNavigate } from 'react-router-dom'
import { useAuthStore } from '@/stores/authStore'
import { Link } from 'react-router-dom'
import { Button } from '@/components/ui/button'
import {
Card,
@@ -11,14 +10,6 @@ import {
import { RolesList } from '../components/RolesList'
export function RolesPage() {
const navigate = useNavigate()
const user = useAuthStore((s) => s.user)
if (!user || user.rol !== 'admin') {
void navigate('/', { replace: true })
return null
}
return (
<div className="flex justify-center py-8">
<Card className="w-full max-w-4xl">