Skip to content

Commit

Permalink
Merge branch 'main' into feature/admin-change-urgency
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickwebsdev authored Nov 8, 2024
2 parents 0536e0e + 61af723 commit 5b0e538
Show file tree
Hide file tree
Showing 27 changed files with 312 additions and 420 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,6 @@ node_modules/
/playwright-report/
/blob-report/
/playwright/.cache/

# Snaplet
/.snaplet/
39 changes: 0 additions & 39 deletions src/app/casos-activos/layout.js

This file was deleted.

41 changes: 41 additions & 0 deletions src/app/casos-activos/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { createClient } from '@/lib/supabase/server';
import TabNavigation from '@/components/TabNavigation';
import { PropsWithChildren } from 'react';
import { SupabaseClient } from '@supabase/supabase-js';
import { Database } from '@/types/database';
const getCount = async (supabase: SupabaseClient<Database>) => {
const { count: solicitaCount, error: solicitaError } = await supabase
.from('help_requests')
.select('id', { count: 'exact' })
.eq('type', 'necesita');

const { count: ofreceCount, error: ofreceError } = await supabase
.from('help_requests')
.select('id', { count: 'exact' })
.eq('type', 'ofrece');

if (solicitaError) {
throw new Error('Error fetching solicita:', solicitaError);
}
if (ofreceError) {
throw new Error('Error fetching ofrece:', ofreceError);
}

return {
solicitudes: solicitaCount || 0,
ofertas: ofreceCount || 0,
};
};

export default async function CasosActivosLayout({ children }: PropsWithChildren) {
const supabase = await createClient();
const count = await getCount(supabase);
return (
<>
<div className="space-y-6 mx-auto max-w-7xl px-4 sm:px-6">
<TabNavigation count={count} />
{children}
</div>
</>
);
}
2 changes: 2 additions & 0 deletions src/app/casos-activos/mapa/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Suspense>
Expand Down
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -18,42 +19,41 @@ 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<boolean>(true);
const [error, setError] = useState<string | null>(null);

const [data, setData] = useState([]);
const [currentPage, setCurrentPage] = useState(Number(searchParams.get('page')) || 1);
const [currentCount, setCurrentCount] = useState(0);
const [data, setData] = useState<HelpRequestData[]>([]);
const [currentPage, setCurrentPage] = useState<number>(Number(searchParams.get('page')) || 1);
const [currentCount, setCurrentCount] = useState<number>(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()}`);
};

const [filtroData, setFiltroData] = useState({
ayuda: searchParams.get('acepta') || 'todas',
});

const changeDataFilter = (type, newFilter) => {
const changeDataFilter = (type: 'ayuda', newFilter: string) => {
setFiltroData((prev) => ({
...prev,
[type]: newFilter,
}));
updateFilter(type, newFilter);
};

function changePage(newPage) {
function changePage(newPage: number) {
setCurrentPage(newPage);
updateFilter('page', newPage);
}
Expand Down Expand Up @@ -83,7 +83,7 @@ function Ofertas() {
setData([]);
} else {
setData(data || []);
setCurrentCount(count);
setCurrentCount(count ?? 0);
}
} catch (err) {
console.log('Error general:', err);
Expand Down Expand Up @@ -136,21 +136,11 @@ function Ofertas() {
{data.length === 0 ? (
<div className="bg-white rounded-lg shadow-lg border border-gray-300 text-center flex justify-center items-center p-10 flex-col gap-5">
<p className="text-gray-700 text-lg font-medium">
No se encontraron solicitudes que coincidan con los filtros.
No se encontraron ofertas que coincidan con los filtros.
</p>

<button
onClick={() => {
setShowModal(true);
}}
className="bg-green-500 text-white px-4 py-2 rounded hover:bg-green-600 flex items-center gap-2 whitespace-nowrap"
>
<HeartHandshake className="w-5 h-5" />
Ofrecer ayuda
</button>
</div>
) : (
data.map((caso) => <OfferCard caso={caso} towns={towns} showLink={true} key={caso.id} />)
data.map((caso) => <OfferCard caso={caso} showLink={true} key={caso.id} />)
)}
</div>
<div className="flex items-center justify-center">
Expand Down
6 changes: 0 additions & 6 deletions src/app/casos-activos/page.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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<boolean>(true);
const [error, setError] = useState<string | null>(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<HelpRequestData[]>([]);
const [currentPage, setCurrentPage] = useState<number>(Number(searchParams.get('page')) || 1);
const [currentCount, setCurrentCount] = useState<number>(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()}`);
};

Expand All @@ -55,15 +48,15 @@ function Solicitudes() {
pueblo: searchParams.get('pueblo') || 'todos',
});

const changeDataFilter = (type, newFilter) => {
const changeDataFilter = (type: 'urgencia' | 'tipoAyuda' | 'pueblo', newFilter: string) => {
setFiltroData((prev) => ({
...prev,
[type]: newFilter,
}));
updateFilter(type, newFilter);
};

function changePage(newPage) {
function changePage(newPage: number) {
setCurrentPage(newPage);
updateFilter('page', newPage);
}
Expand Down Expand Up @@ -102,7 +95,7 @@ function Solicitudes() {
setData([]);
} else {
setData(data || []);
setCurrentCount(count);
setCurrentCount(count ?? 0);
}
} catch (err) {
console.log('Error general:', err);
Expand Down Expand Up @@ -131,8 +124,6 @@ function Solicitudes() {
);
}

const puebloSeleccionado = getTownById(Number(filtroData.pueblo));

return (
<>
{/* FILTROS */}
Expand Down Expand Up @@ -181,16 +172,6 @@ function Solicitudes() {
<p className="text-gray-700 text-lg font-medium">
No se encontraron solicitudes que coincidan con los filtros.
</p>

<button
onClick={() => {
toggleModal(MODAL_NAME, true);
}}
className="bg-green-500 text-white px-4 py-2 rounded hover:bg-green-600 flex items-center gap-2 whitespace-nowrap"
>
<HeartHandshake className="w-5 h-5" />
Ofrecer ayuda {filtroData.pueblo === 'todos' ? '' : ' a ' + getTownById(Number(filtroData.pueblo))?.name}
</button>
</div>
) : (
data.map((caso) => <SolicitudCard showLink={true} showEdit={true} key={caso.id} caso={caso} />)
Expand All @@ -199,10 +180,6 @@ function Solicitudes() {
<div className="flex items-center justify-center">
<Pagination currentPage={currentPage} totalPages={numPages(currentCount)} onPageChange={changePage} />
</div>

<Modal id={MODAL_NAME}>
<OfferHelp town={puebloSeleccionado?.name} onClose={closeModal} isModal={true} />
</Modal>
</>
);
}
4 changes: 2 additions & 2 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import PhoneNumberDialog from '@/components/auth/PhoneNumberDialog';
import Image from 'next/image';
import { CallCenterLink } from '@/components/CallCenterLink';

export default function Home() {
export default async function Home() {
const emergencyNumbers = [
{ name: 'Emergencias', number: '112', description: 'Para situaciones de peligro inmediato' },
{ name: 'Policía Local', number: '092', description: 'Asistencia y seguridad local' },
Expand Down Expand Up @@ -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',
},
{
Expand Down
Loading

0 comments on commit 5b0e538

Please sign in to comment.