diff --git a/web-v2/src/pages/InventoryCreatePage.tsx b/web-v2/src/pages/InventoryCreatePage.tsx index bf72910..0bfe037 100644 --- a/web-v2/src/pages/InventoryCreatePage.tsx +++ b/web-v2/src/pages/InventoryCreatePage.tsx @@ -18,7 +18,7 @@ import type { InventoryStructureParent, } from '../lib/inventoryStructureApi'; -const KINDS: Array<{ kind: InventoryStructureKind; label: string; help: string; step: number }> = [ +const STRUCTURE_KINDS: Array<{ kind: InventoryStructureKind; label: string; help: string; step: number }> = [ { kind: 'AREA', label: 'Área', help: 'Nivel territorial raíz.', step: 1 }, { kind: 'YACIMIENTO', label: 'Yacimiento', help: 'Debe pertenecer a un Área.', step: 2 }, { kind: 'INSTALACION', label: 'Instalación', help: 'Debe pertenecer a un Yacimiento.', step: 3 }, @@ -32,7 +32,8 @@ const childKindByParentType: Record }; function kindLabel(kind: InventoryStructureKind): string { - return KINDS.find((item) => item.kind === kind)?.label ?? kind; + if (kind === 'EMPRESA') return 'Empresa'; + return STRUCTURE_KINDS.find((item) => item.kind === kind)?.label ?? kind; } export function InventoryCreatePage() { @@ -72,7 +73,7 @@ export function InventoryCreatePage() { }, [contextParentId]); useEffect(() => { - if (kind === 'AREA') { + if (kind === 'AREA' || kind === 'EMPRESA') { setParents([]); setParentId(''); return; @@ -130,7 +131,7 @@ export function InventoryCreatePage() { const save = async (event: FormEvent) => { event.preventDefault(); - const requiresParent = kind !== 'AREA'; + const requiresParent = kind !== 'AREA' && kind !== 'EMPRESA'; const requiresFamily = kind === 'INSTALACION' || kind === 'SUBINSTALACION'; if (requiresParent && !parentId) { setError(`Seleccioná el ${kind === 'YACIMIENTO' ? 'Área' : kind === 'INSTALACION' ? 'Yacimiento' : 'Instalación'} padre.`); @@ -160,10 +161,13 @@ export function InventoryCreatePage() { } }; - if (loading) return ; + if (loading) return ; + const isIndependentCompany = kind === 'EMPRESA'; const parentLabel = kind === 'YACIMIENTO' ? 'Área' : kind === 'INSTALACION' ? 'Yacimiento' : 'Instalación'; - const currentStep = KINDS.find((item) => item.kind === kind)?.step ?? 1; + const currentStep = STRUCTURE_KINDS.find((item) => item.kind === kind)?.step ?? 1; + const identificationStep = isIndependentCompany ? '2' : kind === 'AREA' ? '2' : kind === 'YACIMIENTO' ? '3' : '4'; + const requiresParent = kind !== 'AREA' && kind !== 'EMPRESA'; return