fix(web): reservar ficha avanzada al administrador
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useParams, useSearchParams } from 'react-router';
|
||||
import { useAuth } from '../auth/AuthContext';
|
||||
import { hasAdministratorRole } from '../auth/adminAccess';
|
||||
import { Alert, LoadingBlock, errorMessage } from '../components/Feedback';
|
||||
import { getAsset } from '../lib/api';
|
||||
import type { AssetDetail } from '../lib/api';
|
||||
@@ -10,6 +12,7 @@ import { TerritorialInventoryPage, isTerritorialInventoryAsset } from './Territo
|
||||
export function InventoryDetailPage() {
|
||||
const { id } = useParams();
|
||||
const [params] = useSearchParams();
|
||||
const { user } = useAuth();
|
||||
const [asset, setAsset] = useState<AssetDetail | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState('');
|
||||
@@ -31,8 +34,11 @@ export function InventoryDetailPage() {
|
||||
if (loading) return <LoadingBlock label="Cargando registro…" />;
|
||||
if (!asset) return <Alert>{error || 'No se pudo cargar el registro.'}</Alert>;
|
||||
|
||||
const advanced = params.get('advanced') === '1';
|
||||
const advancedRequested = params.get('advanced') === '1';
|
||||
const advancedAllowed = hasAdministratorRole(user);
|
||||
const advanced = advancedRequested && advancedAllowed;
|
||||
const isCompany = asset.type.code.toLowerCase() === 'empresa';
|
||||
|
||||
if (isCompany && !advanced) {
|
||||
return <CompanyInventoryPage initialAsset={asset} />;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user