diff --git a/src/app/casos-activos/layout.js b/src/app/casos-activos/layout.tsx similarity index 88% rename from src/app/casos-activos/layout.js rename to src/app/casos-activos/layout.tsx index b23c4515..4944cf4f 100644 --- a/src/app/casos-activos/layout.js +++ b/src/app/casos-activos/layout.tsx @@ -1,5 +1,6 @@ import { supabase } from '@/lib/supabase/client'; import TabNavigation from '@/components/TabNavigation'; +import { PropsWithChildren } from 'react'; const getCount = async () => { const { data: solicitaData, @@ -26,7 +27,7 @@ const getCount = async () => { }; }; -export default async function CasosActivosLayout({ children }) { +export default async function CasosActivosLayout({ children }: PropsWithChildren) { const count = await getCount(); return ( <> diff --git a/src/app/casos-activos/mapa/page.tsx b/src/app/casos-activos/mapa/page.tsx index 64333c9e..23822f74 100644 --- a/src/app/casos-activos/mapa/page.tsx +++ b/src/app/casos-activos/mapa/page.tsx @@ -8,6 +8,8 @@ import { tiposAyudaOptions } from '@/helpers/constants'; import Map, { PinMapa } from '@/components/map/map'; import PickupPoint from '@/components/PickupPoint'; +export const dynamic = 'force-dynamic'; + export default function MapaPage() { return ( diff --git a/src/app/casos-activos/ofertas/page.js b/src/app/casos-activos/ofertas/page.tsx similarity index 77% rename from src/app/casos-activos/ofertas/page.js rename to src/app/casos-activos/ofertas/page.tsx index 3d7a58e7..d1b8f5de 100644 --- a/src/app/casos-activos/ofertas/page.js +++ b/src/app/casos-activos/ofertas/page.tsx @@ -1,13 +1,14 @@ 'use client'; import { Suspense, useEffect, useState } from 'react'; -import { HeartHandshake } from 'lucide-react'; import { supabase } from '@/lib/supabase/client'; import Pagination from '@/components/Pagination'; import { tiposAyudaOptions } from '@/helpers/constants'; import { useRouter, useSearchParams } from 'next/navigation'; -import { useTowns } from '@/context/TownProvider'; import OfferCard from '@/components/OfferCard'; +import { HelpRequestData } from '@/types/Requests'; + +export const dynamic = 'force-dynamic'; export default function OfertasPage() { return ( @@ -18,26 +19,25 @@ export default function OfertasPage() { } function Ofertas() { - const { towns } = useTowns(); const searchParams = useSearchParams(); const router = useRouter(); const {} = router; - const [loading, setLoading] = useState(true); - const [error, setError] = useState(null); + const [loading, setLoading] = useState(true); + const [error, setError] = useState(null); - const [data, setData] = useState([]); - const [currentPage, setCurrentPage] = useState(Number(searchParams.get('page')) || 1); - const [currentCount, setCurrentCount] = useState(0); + const [data, setData] = useState([]); + const [currentPage, setCurrentPage] = useState(Number(searchParams.get('page')) || 1); + const [currentCount, setCurrentCount] = useState(0); const itemsPerPage = 10; - const numPages = (count) => { + const numPages = (count: number) => { return Math.ceil(count / itemsPerPage) || 0; }; - const updateFilter = (filter, value) => { + const updateFilter = (filter: 'ayuda' | 'page', value: string | number) => { const params = new URLSearchParams(searchParams.toString()); - params.set(filter, value); + params.set(filter, value.toString()); router.push(`?${params.toString()}`); }; @@ -45,7 +45,7 @@ function Ofertas() { ayuda: searchParams.get('acepta') || 'todas', }); - const changeDataFilter = (type, newFilter) => { + const changeDataFilter = (type: 'ayuda', newFilter: string) => { setFiltroData((prev) => ({ ...prev, [type]: newFilter, @@ -53,7 +53,7 @@ function Ofertas() { updateFilter(type, newFilter); }; - function changePage(newPage) { + function changePage(newPage: number) { setCurrentPage(newPage); updateFilter('page', newPage); } @@ -83,7 +83,7 @@ function Ofertas() { setData([]); } else { setData(data || []); - setCurrentCount(count); + setCurrentCount(count ?? 0); } } catch (err) { console.log('Error general:', err); @@ -136,21 +136,11 @@ function Ofertas() { {data.length === 0 ? (

- No se encontraron solicitudes que coincidan con los filtros. + No se encontraron ofertas que coincidan con los filtros.

- -
) : ( - data.map((caso) => ) + data.map((caso) => ) )}
diff --git a/src/app/casos-activos/page.js b/src/app/casos-activos/page.js deleted file mode 100644 index bf9d287e..00000000 --- a/src/app/casos-activos/page.js +++ /dev/null @@ -1,6 +0,0 @@ -import CasosActivosLayout from './layout'; -import Solicitudes from './solicitudes/page'; - -export default function CasosActivos() { - return ; -} diff --git a/src/app/casos-activos/solicitudes/page.js b/src/app/casos-activos/solicitudes/page.tsx similarity index 78% rename from src/app/casos-activos/solicitudes/page.js rename to src/app/casos-activos/solicitudes/page.tsx index e1b8acf0..725493eb 100644 --- a/src/app/casos-activos/solicitudes/page.js +++ b/src/app/casos-activos/solicitudes/page.tsx @@ -1,18 +1,15 @@ 'use client'; import { Suspense, useEffect, useState } from 'react'; -import { HeartHandshake } from 'lucide-react'; import { supabase } from '@/lib/supabase/client'; import SolicitudCard from '@/components/SolicitudCard'; import Pagination from '@/components/Pagination'; -import OfferHelp from '@/components/OfferHelp'; import { useRouter, useSearchParams } from 'next/navigation'; import { tiposAyudaOptions } from '@/helpers/constants'; -import Modal from '@/components/Modal'; -import { useModal } from '@/context/ModalProvider'; import { useTowns } from '@/context/TownProvider'; +import { HelpRequestData } from '@/types/Requests'; -const MODAL_NAME = 'solicitudes'; +export const dynamic = 'force-dynamic'; export default function SolicitudesPage() { return ( @@ -23,29 +20,25 @@ export default function SolicitudesPage() { } function Solicitudes() { - const { getTownById, towns } = useTowns(); + const { towns } = useTowns(); const searchParams = useSearchParams(); const router = useRouter(); - const [loading, setLoading] = useState(true); - const [error, setError] = useState(null); + const [loading, setLoading] = useState(true); + const [error, setError] = useState(null); - const [data, setData] = useState([]); - const [currentPage, setCurrentPage] = useState(Number(searchParams.get('page')) || 1); - const [currentCount, setCurrentCount] = useState(0); - const { toggleModal } = useModal(); + const [data, setData] = useState([]); + const [currentPage, setCurrentPage] = useState(Number(searchParams.get('page')) || 1); + const [currentCount, setCurrentCount] = useState(0); - const closeModal = () => { - toggleModal(MODAL_NAME, false); - }; const itemsPerPage = 10; - const numPages = (count) => { + const numPages = (count: number) => { return Math.ceil(count / itemsPerPage) || 0; }; - const updateFilter = (filter, value) => { + const updateFilter = (filter: 'urgencia' | 'tipoAyuda' | 'pueblo' | 'page', value: string | number) => { const params = new URLSearchParams(searchParams.toString()); - params.set(filter, value); + params.set(filter, value.toString()); router.push(`?${params.toString()}`); }; @@ -55,7 +48,7 @@ function Solicitudes() { pueblo: searchParams.get('pueblo') || 'todos', }); - const changeDataFilter = (type, newFilter) => { + const changeDataFilter = (type: 'urgencia' | 'tipoAyuda' | 'pueblo', newFilter: string) => { setFiltroData((prev) => ({ ...prev, [type]: newFilter, @@ -63,7 +56,7 @@ function Solicitudes() { updateFilter(type, newFilter); }; - function changePage(newPage) { + function changePage(newPage: number) { setCurrentPage(newPage); updateFilter('page', newPage); } @@ -102,7 +95,7 @@ function Solicitudes() { setData([]); } else { setData(data || []); - setCurrentCount(count); + setCurrentCount(count ?? 0); } } catch (err) { console.log('Error general:', err); @@ -131,8 +124,6 @@ function Solicitudes() { ); } - const puebloSeleccionado = getTownById(Number(filtroData.pueblo)); - return ( <> {/* FILTROS */} @@ -181,16 +172,6 @@ function Solicitudes() {

No se encontraron solicitudes que coincidan con los filtros.

- -
) : ( data.map((caso) => ) @@ -199,10 +180,6 @@ function Solicitudes() {
- - - - ); } diff --git a/src/app/page.tsx b/src/app/page.tsx index 17213357..6d4c2685 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -132,7 +132,7 @@ export default function Home() { title: 'Casos activos', description: 'Observa los casos activos', icon: AlertCircle, - path: '/casos-activos', + path: '/casos-activos/solicitudes', color: 'orange', }, { diff --git a/src/app/punto-recogida/page.js b/src/app/punto-recogida/page.tsx similarity index 90% rename from src/app/punto-recogida/page.js rename to src/app/punto-recogida/page.tsx index e61daec3..c0122674 100644 --- a/src/app/punto-recogida/page.js +++ b/src/app/punto-recogida/page.tsx @@ -1,11 +1,14 @@ 'use client'; -import { useState, useCallback, useEffect } from 'react'; +import { useState, useCallback, useEffect, FormEvent } from 'react'; import { supabase } from '@/lib/supabase/client'; import { MapPin, Phone, Package, House, Contact, Megaphone } from 'lucide-react'; import AddressAutocomplete from '@/components/AddressAutocomplete'; import { isValidPhone } from '@/helpers/utils'; import { PhoneInput } from '@/components/PhoneInput'; +import { CollectionPointData, CollectionPointInsert } from '@/types/DataPoints'; + +export const dynamic = 'force-dynamic'; export default function PuntosRecogida() { const initialFormData = { @@ -20,16 +23,16 @@ export default function PuntosRecogida() { status: 'active', }; - const [formData, setFormData] = useState(initialFormData); + const [formData, setFormData] = useState(initialFormData); const [showForm, setShowForm] = useState(false); const [loading, setLoading] = useState(false); - const [collectionPoints, setCollectionPoints] = useState([]); - const [error, setError] = useState(null); + const [collectionPoints, setCollectionPoints] = useState([]); + const [error, setError] = useState(null); const [success, setSuccess] = useState(false); const tiposAyuda = ['Alimentos', 'Agua', 'Ropa', 'Mantas', 'Medicamentos', 'Productos de higiene']; - const handlePhoneChange = useCallback((phoneNumber) => { + const handlePhoneChange = useCallback((phoneNumber: string) => { setFormData((formData) => ({ ...formData, contact_phone: phoneNumber })); }, []); @@ -52,20 +55,20 @@ export default function PuntosRecogida() { } } - async function handleSubmit(e) { + async function handleSubmit(e: FormEvent) { e.preventDefault(); setLoading(true); setError(null); try { - const requiredFields = ['name', 'location', 'contact_phone']; + const requiredFields = ['name', 'location', 'contact_phone'] as const; const missingFields = requiredFields.filter((field) => !formData[field]); if (missingFields.length > 0) { throw new Error('Por favor completa todos los campos obligatorios'); } - if (!isValidPhone(formData.contact_phone)) { + if (!isValidPhone(formData.contact_phone ?? '')) { alert('El teléfono de contacto no es válido.'); return; } @@ -92,7 +95,7 @@ export default function PuntosRecogida() { setFormData(initialFormData); setTimeout(() => setSuccess(false), 3000); - } catch (error) { + } catch (error: any) { console.error('Error al registrar punto de recogida:', error); setError(error.message || 'Error al registrar el punto de recogida'); } finally { @@ -208,7 +211,7 @@ export default function PuntosRecogida() { setFormData({ ...formData, name: e.target.value })} className="w-full p-2 border rounded" required @@ -217,7 +220,7 @@ export default function PuntosRecogida() {
{ + onSelect={(address: any) => { setFormData((prev) => ({ ...prev, location: address.fullAddress, @@ -240,18 +243,18 @@ export default function PuntosRecogida() {
- +