refactor(web): eliminar guards inline rol admin en páginas de roles/permisos [UDT-006]
This commit is contained in:
@@ -1,6 +1,4 @@
|
|||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { useNavigate } from 'react-router-dom'
|
|
||||||
import { useAuthStore } from '@/stores/authStore'
|
|
||||||
import {
|
import {
|
||||||
Card,
|
Card,
|
||||||
CardContent,
|
CardContent,
|
||||||
@@ -12,17 +10,10 @@ import { useRoles } from '../../roles/hooks/useRoles'
|
|||||||
import { RolPermisosEditor } from '../components/RolPermisosEditor'
|
import { RolPermisosEditor } from '../components/RolPermisosEditor'
|
||||||
|
|
||||||
export function RolPermisosPage() {
|
export function RolPermisosPage() {
|
||||||
const navigate = useNavigate()
|
|
||||||
const user = useAuthStore((s) => s.user)
|
|
||||||
const [selectedRol, setSelectedRol] = useState<string | null>(null)
|
const [selectedRol, setSelectedRol] = useState<string | null>(null)
|
||||||
|
|
||||||
const { data: roles, isLoading: loadingRoles } = useRoles()
|
const { data: roles, isLoading: loadingRoles } = useRoles()
|
||||||
|
|
||||||
if (!user || user.rol !== 'admin') {
|
|
||||||
void navigate('/', { replace: true })
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
const rolesActivos = roles?.filter((r) => r.activo) ?? []
|
const rolesActivos = roles?.filter((r) => r.activo) ?? []
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { useNavigate, useParams } from 'react-router-dom'
|
import { useNavigate, useParams } from 'react-router-dom'
|
||||||
import { useAuthStore } from '@/stores/authStore'
|
|
||||||
import {
|
import {
|
||||||
Card,
|
Card,
|
||||||
CardContent,
|
CardContent,
|
||||||
@@ -15,14 +14,8 @@ import { EditRolForm } from '../components/RolForm'
|
|||||||
export function EditRolPage() {
|
export function EditRolPage() {
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const { codigo } = useParams<{ codigo: string }>()
|
const { codigo } = useParams<{ codigo: string }>()
|
||||||
const user = useAuthStore((s) => s.user)
|
|
||||||
const { data: rol, isLoading, isError } = useRol(codigo)
|
const { data: rol, isLoading, isError } = useRol(codigo)
|
||||||
|
|
||||||
if (!user || user.rol !== 'admin') {
|
|
||||||
void navigate('/', { replace: true })
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex justify-center py-8">
|
<div className="flex justify-center py-8">
|
||||||
<Card className="w-full max-w-lg">
|
<Card className="w-full max-w-lg">
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { useNavigate } from 'react-router-dom'
|
import { useNavigate } from 'react-router-dom'
|
||||||
import { useAuthStore } from '@/stores/authStore'
|
|
||||||
import {
|
import {
|
||||||
Card,
|
Card,
|
||||||
CardContent,
|
CardContent,
|
||||||
@@ -11,12 +10,6 @@ import { CreateRolForm } from '../components/RolForm'
|
|||||||
|
|
||||||
export function NewRolPage() {
|
export function NewRolPage() {
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const user = useAuthStore((s) => s.user)
|
|
||||||
|
|
||||||
if (!user || user.rol !== 'admin') {
|
|
||||||
void navigate('/', { replace: true })
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex justify-center py-8">
|
<div className="flex justify-center py-8">
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { Link, useNavigate } from 'react-router-dom'
|
import { Link } from 'react-router-dom'
|
||||||
import { useAuthStore } from '@/stores/authStore'
|
|
||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
import {
|
import {
|
||||||
Card,
|
Card,
|
||||||
@@ -11,14 +10,6 @@ import {
|
|||||||
import { RolesList } from '../components/RolesList'
|
import { RolesList } from '../components/RolesList'
|
||||||
|
|
||||||
export function RolesPage() {
|
export function RolesPage() {
|
||||||
const navigate = useNavigate()
|
|
||||||
const user = useAuthStore((s) => s.user)
|
|
||||||
|
|
||||||
if (!user || user.rol !== 'admin') {
|
|
||||||
void navigate('/', { replace: true })
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex justify-center py-8">
|
<div className="flex justify-center py-8">
|
||||||
<Card className="w-full max-w-4xl">
|
<Card className="w-full max-w-4xl">
|
||||||
|
|||||||
Reference in New Issue
Block a user