diff --git a/Elecciones-Web/frontend-admin/src/components/CandidatoOverridesManager.tsx b/Elecciones-Web/frontend-admin/src/components/CandidatoOverridesManager.tsx index f5456ef..8356b36 100644 --- a/Elecciones-Web/frontend-admin/src/components/CandidatoOverridesManager.tsx +++ b/Elecciones-Web/frontend-admin/src/components/CandidatoOverridesManager.tsx @@ -7,6 +7,7 @@ import type { MunicipioSimple, AgrupacionPolitica, CandidatoOverride, ProvinciaS import { CATEGORIAS_NACIONALES_OPTIONS, CATEGORIAS_PROVINCIALES_OPTIONS } from '../constants/categorias'; const ELECCION_OPTIONS = [ + { value: 0, label: 'General (Todas las elecciones)' }, { value: 2, label: 'Elecciones Nacionales' }, { value: 1, label: 'Elecciones Provinciales' } ]; @@ -31,12 +32,17 @@ export const CandidatoOverridesManager = () => { const { data: provincias = [] } = useQuery({ queryKey: ['provinciasForAdmin'], queryFn: getProvinciasForAdmin }); const { data: municipios = [] } = useQuery({ queryKey: ['municipiosForAdmin'], queryFn: getMunicipiosForAdmin }); const { data: agrupaciones = [] } = useQuery({ queryKey: ['agrupaciones'], queryFn: getAgrupaciones }); + const { data: candidatos = [] } = useQuery({ - queryKey: ['candidatos', selectedEleccion.value], - queryFn: () => getCandidatos(selectedEleccion.value), + queryKey: ['allCandidatos'], + queryFn: () => Promise.all([getCandidatos(0), getCandidatos(1), getCandidatos(2)]).then(res => res.flat()), }); - const categoriaOptions = selectedEleccion.value === 2 ? CATEGORIAS_NACIONALES_OPTIONS : CATEGORIAS_PROVINCIALES_OPTIONS; + const categoriaOptions = useMemo(() => { + if (selectedEleccion.value === 2) return CATEGORIAS_NACIONALES_OPTIONS; + if (selectedEleccion.value === 1) return CATEGORIAS_PROVINCIALES_OPTIONS; + return [...CATEGORIAS_NACIONALES_OPTIONS, ...CATEGORIAS_PROVINCIALES_OPTIONS]; + }, [selectedEleccion]); const getAmbitoId = () => { if (selectedAmbitoLevel.value === 'municipio' && selectedMunicipio) return parseInt(selectedMunicipio.id); @@ -48,11 +54,12 @@ export const CandidatoOverridesManager = () => { if (!selectedAgrupacion || !selectedCategoria) return ''; const ambitoId = getAmbitoId(); return candidatos.find(c => + c.eleccionId === selectedEleccion.value && c.ambitoGeograficoId === ambitoId && c.agrupacionPoliticaId === selectedAgrupacion.id && c.categoriaId === selectedCategoria.value )?.nombreCandidato || ''; - }, [candidatos, selectedAmbitoLevel, selectedProvincia, selectedMunicipio, selectedAgrupacion, selectedCategoria]); + }, [candidatos, selectedEleccion, selectedAmbitoLevel, selectedProvincia, selectedMunicipio, selectedAgrupacion, selectedCategoria]); useEffect(() => { setNombreCandidato(currentCandidato || ''); }, [currentCandidato]); @@ -64,11 +71,11 @@ export const CandidatoOverridesManager = () => { agrupacionPoliticaId: selectedAgrupacion.id, categoriaId: selectedCategoria.value, ambitoGeograficoId: getAmbitoId(), - nombreCandidato: nombreCandidato || null + nombreCandidato: nombreCandidato.trim() || null }; try { await updateCandidatos([newCandidatoEntry]); - queryClient.invalidateQueries({ queryKey: ['candidatos', selectedEleccion.value] }); + queryClient.invalidateQueries({ queryKey: ['allCandidatos'] }); alert('Override de candidato guardado.'); } catch (error) { console.error(error); @@ -82,7 +89,7 @@ export const CandidatoOverridesManager = () => {

Configure un nombre de candidato específico para un partido en un contexto determinado.

+ ({ value: a.id, label: a.nombre, ...a }))} getOptionValue={opt => opt.id} diff --git a/Elecciones-Web/frontend-admin/src/components/LogoOverridesManager.tsx b/Elecciones-Web/frontend-admin/src/components/LogoOverridesManager.tsx index 336fb4a..e72761a 100644 --- a/Elecciones-Web/frontend-admin/src/components/LogoOverridesManager.tsx +++ b/Elecciones-Web/frontend-admin/src/components/LogoOverridesManager.tsx @@ -21,7 +21,6 @@ const AMBITO_LEVEL_OPTIONS = [ export const LogoOverridesManager = () => { const queryClient = useQueryClient(); - // --- ESTADOS --- const [selectedEleccion, setSelectedEleccion] = useState(ELECCION_OPTIONS[0]); const [selectedAmbitoLevel, setSelectedAmbitoLevel] = useState(AMBITO_LEVEL_OPTIONS[0]); const [selectedProvincia, setSelectedProvincia] = useState(null); @@ -30,33 +29,37 @@ export const LogoOverridesManager = () => { const [selectedAgrupacion, setSelectedAgrupacion] = useState(null); const [logoUrl, setLogoUrl] = useState(''); - // --- QUERIES --- const { data: provincias = [] } = useQuery({ queryKey: ['provinciasForAdmin'], queryFn: getProvinciasForAdmin }); const { data: municipios = [] } = useQuery({ queryKey: ['municipiosForAdmin'], queryFn: getMunicipiosForAdmin }); const { data: agrupaciones = [] } = useQuery({ queryKey: ['agrupaciones'], queryFn: getAgrupaciones }); + const { data: logos = [] } = useQuery({ - queryKey: ['logos', selectedEleccion.value], - queryFn: () => getLogos(selectedEleccion.value) + queryKey: ['allLogos'], + queryFn: () => Promise.all([getLogos(0), getLogos(1), getLogos(2)]).then(res => res.flat()), }); - // --- LÓGICA DE SELECTORES DINÁMICOS --- - const categoriaOptions = selectedEleccion.value === 2 ? CATEGORIAS_NACIONALES_OPTIONS : CATEGORIAS_PROVINCIALES_OPTIONS; + const categoriaOptions = useMemo(() => { + if (selectedEleccion.value === 2) return CATEGORIAS_NACIONALES_OPTIONS; + if (selectedEleccion.value === 1) return CATEGORIAS_PROVINCIALES_OPTIONS; + return [...CATEGORIAS_NACIONALES_OPTIONS, ...CATEGORIAS_PROVINCIALES_OPTIONS]; + }, [selectedEleccion]); const getAmbitoId = () => { if (selectedAmbitoLevel.value === 'municipio' && selectedMunicipio) return parseInt(selectedMunicipio.id); if (selectedAmbitoLevel.value === 'provincia' && selectedProvincia) return parseInt(selectedProvincia.id); - return 0; + return null; }; const currentLogo = useMemo(() => { if (!selectedAgrupacion || !selectedCategoria) return ''; const ambitoId = getAmbitoId(); return logos.find(l => + l.eleccionId === selectedEleccion.value && l.ambitoGeograficoId === ambitoId && l.agrupacionPoliticaId === selectedAgrupacion.id && l.categoriaId === selectedCategoria.value )?.logoUrl || ''; - }, [logos, selectedAmbitoLevel, selectedProvincia, selectedMunicipio, selectedAgrupacion, selectedCategoria]); + }, [logos, selectedEleccion, selectedAmbitoLevel, selectedProvincia, selectedMunicipio, selectedAgrupacion, selectedCategoria]); useEffect(() => { setLogoUrl(currentLogo || ''); }, [currentLogo]); @@ -68,11 +71,11 @@ export const LogoOverridesManager = () => { agrupacionPoliticaId: selectedAgrupacion.id, categoriaId: selectedCategoria.value, ambitoGeograficoId: getAmbitoId(), - logoUrl: logoUrl || null + logoUrl: logoUrl.trim() || null }; try { await updateLogos([newLogoEntry]); - queryClient.invalidateQueries({ queryKey: ['logos', selectedEleccion.value] }); + queryClient.invalidateQueries({ queryKey: ['allLogos'] }); alert('Override de logo guardado.'); } catch { alert('Error al guardar.'); } }; @@ -83,7 +86,7 @@ export const LogoOverridesManager = () => {

Configure una imagen específica para un partido en un contexto determinado.

+ ({ value: a.id, label: a.nombre, ...a }))} getOptionValue={opt => opt.id} diff --git a/Elecciones-Web/frontend-admin/src/constants/categorias.ts b/Elecciones-Web/frontend-admin/src/constants/categorias.ts index b27b80d..eff42ba 100644 --- a/Elecciones-Web/frontend-admin/src/constants/categorias.ts +++ b/Elecciones-Web/frontend-admin/src/constants/categorias.ts @@ -3,8 +3,8 @@ // Opciones para los selectores en el panel de administración export const CATEGORIAS_ADMIN_OPTIONS = [ // Nacionales - { value: 1, label: 'Senadores Nacionales' }, - { value: 2, label: 'Diputados Nacionales' }, + { value: 2, label: 'Senadores Nacionales' }, + { value: 3, label: 'Diputados Nacionales' }, // Provinciales { value: 5, label: 'Senadores Provinciales' }, { value: 6, label: 'Diputados Provinciales' }, @@ -12,8 +12,8 @@ export const CATEGORIAS_ADMIN_OPTIONS = [ ]; export const CATEGORIAS_NACIONALES_OPTIONS = [ - { value: 1, label: 'Senadores Nacionales' }, - { value: 2, label: 'Diputados Nacionales' }, + { value: 2, label: 'Senadores Nacionales' }, + { value: 3, label: 'Diputados Nacionales' }, ]; export const CATEGORIAS_PROVINCIALES_OPTIONS = [