feat(web): route companies to simplified profile
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useParams, useSearchParams } from 'react-router';
|
||||
import { Alert, LoadingBlock, errorMessage } from '../components/Feedback';
|
||||
import { getAsset } from '../lib/api';
|
||||
import type { AssetDetail } from '../lib/api';
|
||||
import { AssetEditorPage } from './AssetEditorPage';
|
||||
import { CompanyInventoryPage } from './CompanyInventoryPage';
|
||||
|
||||
export function InventoryDetailPage() {
|
||||
const { id } = useParams();
|
||||
const [params] = useSearchParams();
|
||||
const [asset, setAsset] = useState<AssetDetail | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
if (!id) {
|
||||
setError('No se encontró el registro solicitado.');
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
setLoading(true);
|
||||
setError('');
|
||||
getAsset(id)
|
||||
.then(setAsset)
|
||||
.catch((requestError) => setError(errorMessage(requestError)))
|
||||
.finally(() => setLoading(false));
|
||||
}, [id]);
|
||||
|
||||
if (loading) return <LoadingBlock label="Cargando registro…" />;
|
||||
if (!asset) return <Alert>{error || 'No se pudo cargar el registro.'}</Alert>;
|
||||
|
||||
const isCompany = asset.type.code.toLowerCase() === 'empresa';
|
||||
if (isCompany && params.get('advanced') !== '1') {
|
||||
return <CompanyInventoryPage initialAsset={asset} />;
|
||||
}
|
||||
|
||||
return <AssetEditorPage />;
|
||||
}
|
||||
Reference in New Issue
Block a user