From e0b4607603280469e89f652a7098da0ffd8ada1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Ben=C3=ADtez?= Date: Tue, 7 Jul 2026 21:06:39 -0300 Subject: [PATCH] =?UTF-8?q?feat(workspace):=20selector=20de=20=C3=A1rea=20?= =?UTF-8?q?en=20GlobalSettingsPanel=20reemplaza=20campo=20libre=20"Cliente?= =?UTF-8?q?"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 4.6 --- .../workspace/GlobalSettingsPanel.tsx | 59 ++++++++++++++----- 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/src/features/workspace/GlobalSettingsPanel.tsx b/src/features/workspace/GlobalSettingsPanel.tsx index 9f74faf..ac8d562 100644 --- a/src/features/workspace/GlobalSettingsPanel.tsx +++ b/src/features/workspace/GlobalSettingsPanel.tsx @@ -11,6 +11,8 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@ import { useProcessStore } from '@/store/process-store' import { useAuth } from '@/auth/AuthContext' import { formatPercent } from '@/lib/format' +import { supabaseAreaRepo } from '@/persistence/supabase/area-repo' +import type { Area } from '@/domain/types' const CURRENCIES = [ { code: 'USD', label: 'USD — Dólar estadounidense' }, @@ -28,7 +30,9 @@ export function GlobalSettingsPanel() { const { user } = useAuth() const isClientRole = user?.platformRole === 'client_editor' || user?.platformRole === 'client_viewer' const [localName, setLocalName] = useState('') - const [localClient, setLocalClient] = useState('') + const [localAreaId, setLocalAreaId] = useState('') + const [areas, setAreas] = useState([]) + const [areasLoading, setAreasLoading] = useState(false) const [localCurrency, setLocalCurrency] = useState('USD') const [localOverhead, setLocalOverhead] = useState(20) const [localFrequency, setLocalFrequency] = useState(1000) @@ -39,7 +43,18 @@ export function GlobalSettingsPanel() { useEffect(() => { if (!currentProcess) return setLocalName(currentProcess.name) - setLocalClient(currentProcess.clientName) + setLocalAreaId(currentProcess.areaId ?? '') + + // Cargar áreas de la org del proceso + if (currentProcess.orgId) { + setAreasLoading(true) + supabaseAreaRepo.getByOrg(currentProcess.orgId) + .then(setAreas) + .catch(() => setAreas([])) + .finally(() => setAreasLoading(false)) + } else { + setAreas([]) + } setLocalCurrency(currentProcess.currency) setLocalOverhead(Math.round(currentProcess.overheadPercentage * 100)) setLocalFrequency(currentProcess.annualFrequency) @@ -54,7 +69,7 @@ export function GlobalSettingsPanel() { const clampedHorizon = Math.min(10, Math.max(1, localHorizon)) await updateProcess({ name: localName.trim() || 'Proceso sin nombre', - clientName: localClient.trim(), + areaId: localAreaId === '' ? null : localAreaId, currency: localCurrency, overheadPercentage: localOverhead / 100, annualFrequency: Math.max(1, localFrequency), @@ -82,19 +97,35 @@ export function GlobalSettingsPanel() { /> - {/* Cliente */} + {/* Área */}
- - {isClientRole ? ( -

{localClient || '—'}

+ + {areasLoading ? ( +
+ ) : !currentProcess.orgId ? ( +

Sin organización asignada

+ ) : isClientRole && user?.platformRole === 'client_viewer' ? ( +

{currentProcess.areaName || '—'}

) : ( - { setLocalClient(e.target.value); markDirty() }} - placeholder="ej. Empresa ABC" - className="h-8 text-sm" - /> + )}