fix(workspace): obtener orgName via JOIN en getById, eliminar fetch separado con race condition
Some checks failed
/ Deploy to Cloudflare Pages (push) Has been cancelled

This commit is contained in:
2026-07-07 15:26:52 -03:00
parent 6fee592e40
commit df5fb55696
3 changed files with 11 additions and 16 deletions

View File

@@ -22,7 +22,6 @@ import { useLibraryStore } from '@/store/library-store'
import { useAuth } from '@/auth/AuthContext'
import { AppHeader } from '@/components/AppHeader'
import { ErrorBoundary } from '@/components/ErrorBoundary'
import { supabase } from '@/lib/supabase'
type SelectedCategory = 'activity' | 'gateway' | null
@@ -68,18 +67,7 @@ export function WorkspacePage() {
}
}, [user, processId, navigate])
// Nombre de la organización dueña del proceso (para el back button contextual).
// undefined = todavía cargando, null = cargado sin resultado, string = nombre real.
const [orgName, setOrgName] = useState<string | null | undefined>(undefined)
useEffect(() => {
if (!currentProcess?.orgId) { setOrgName(null); return }
supabase
.from('organizations')
.select('name')
.eq('id', currentProcess.orgId)
.maybeSingle()
.then(({ data }) => setOrgName(data?.name ?? null))
}, [currentProcess?.orgId])
// orgName viene directamente del proceso cargado via JOIN en getById (sin fetch separado)
// Validación XOR: todos los gateways exclusivos deben sumar 1.0
const xorValidation = useMemo(() => {
@@ -198,10 +186,12 @@ export function WorkspacePage() {
}
// client_viewer ya fue redirigido antes de este punto; solo verificamos client_editor aquí
// eslint-disable-next-line no-console
console.log('[WorkspacePage] currentProcess:', { id: currentProcess.id, orgId: currentProcess.orgId })
const isClientRole = user?.platformRole === 'client_editor'
const backLabel = isClientRole
? 'Procesos'
: orgName ?? 'Biblioteca'
: currentProcess.orgName ?? 'Biblioteca'
function handleBack() {
const orgId = currentProcess?.orgId