fix(fiel/csd): usa contribuyente seleccionado sin depender de isDespachoTenant
Problema: isDespachoTenant(user?.tenantRfc) compara contra prefijo 'DESPACHO_' que ningun tenant real usa. Esto hacia que sat/page.tsx siempre usara el endpoint legacy a nivel tenant, ignorando el contribuyente seleccionado y mostrando datos del tenant en lugar del contribuyente. Cambios: - sat/page.tsx: elimina isDespachoTenant, usa selectedContribuyenteId directamente para determinar contribId. Muestra banner cuando no hay contribuyente seleccionado. - csd/page.tsx: agrega banner de contribuyente seleccionado y oculta la UI de CSD cuando no hay contribuyente seleccionado. - tenant-selector.tsx: limpia selectedContribuyenteId al cambiar de tenant para evitar stale state.
This commit is contained in:
@@ -4,6 +4,7 @@ import { useState, useEffect } from 'react';
|
||||
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import { getTenants, type Tenant } from '@/lib/api/tenants';
|
||||
import { useTenantViewStore } from '@/stores/tenant-view-store';
|
||||
import { useContribuyenteStore } from '@/stores/contribuyente-store';
|
||||
import { useAuthStore } from '@/stores/auth-store';
|
||||
import { Building, ChevronDown, Check, X } from 'lucide-react';
|
||||
import { cn } from '@horux/shared-ui';
|
||||
@@ -14,6 +15,7 @@ export function TenantSelector() {
|
||||
const { user } = useAuthStore();
|
||||
const queryClient = useQueryClient();
|
||||
const { viewingTenantId, viewingTenantName, setViewingTenant, clearViewingTenant } = useTenantViewStore();
|
||||
const { clearSelectedContribuyente } = useContribuyenteStore();
|
||||
const isGlobalAdmin = isGlobalAdminRfc(user?.tenantRfc, user?.role, user?.platformRoles);
|
||||
|
||||
const { data: tenants, isLoading } = useQuery({
|
||||
@@ -66,12 +68,14 @@ export function TenantSelector() {
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
clearViewingTenant();
|
||||
clearSelectedContribuyente();
|
||||
queryClient.invalidateQueries();
|
||||
}}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' || e.key === ' ') {
|
||||
e.stopPropagation();
|
||||
clearViewingTenant();
|
||||
clearSelectedContribuyente();
|
||||
queryClient.invalidateQueries();
|
||||
}
|
||||
}}
|
||||
@@ -98,6 +102,7 @@ export function TenantSelector() {
|
||||
<button
|
||||
onClick={() => {
|
||||
clearViewingTenant();
|
||||
clearSelectedContribuyente();
|
||||
setOpen(false);
|
||||
queryClient.invalidateQueries();
|
||||
}}
|
||||
@@ -126,6 +131,7 @@ export function TenantSelector() {
|
||||
key={tenant.id}
|
||||
onClick={() => {
|
||||
setViewingTenant(tenant.id, tenant.nombre, tenant.rfc);
|
||||
clearSelectedContribuyente();
|
||||
setOpen(false);
|
||||
queryClient.invalidateQueries();
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user