Skip to content

Commit

Permalink
Merge pull request #218 from j8seangel/solicitudes-minor-fixes
Browse files Browse the repository at this point in the history
Solicitudes minor fixes
  • Loading branch information
j8seangel authored Nov 16, 2024
2 parents 0bcc252 + 64d01f3 commit 5c12afd
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
22 changes: 14 additions & 8 deletions src/app/casos-activos/solicitudes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function Solicitudes({ data, count }: SolicitudesProps) {
urgencia: searchParams.get('urgencia') || 'todas',
tipoAyuda: searchParams.get('tipoAyuda') || 'todas',
pueblo: searchParams.get('pueblo') || 'todos',
soloSinAsignar: searchParams.get('soloSinAsignar') || 'false',
soloSinAsignar: searchParams.get('soloSinAsignar') || 'true',
});

const updateFilter = useCallback(
Expand All @@ -71,25 +71,31 @@ export function Solicitudes({ data, count }: SolicitudesProps) {

useEffect(() => {
const filters: DataFilter[] = [];
let preFilteredData = data;
if (filtersData.search) {
filters.push({
keys: ['description'],
value: filtersData.search,
});
}
if (filtersData.pueblo && filtersData.pueblo !== 'todos') {
const town = towns.find((t) => t.id === parseInt(filtersData.pueblo));
filters.push({ keys: ['location'], value: town?.name || '' });
}
if (filtersData.urgencia && filtersData.urgencia !== 'todas') {
filters.push({ keys: ['urgency'], value: filtersData.urgencia });
}
if (filtersData.tipoAyuda && filtersData.tipoAyuda !== 'todas') {
filters.push({ keys: ['help_type'], value: filtersData.tipoAyuda });
}
const preFilteredData = isStringTrue(filtersData.soloSinAsignar)
? data.filter((d) => d.asignees_count === 0)
: data;

if (filtersData.pueblo && filtersData.pueblo !== 'todos') {
const town = towns.find((t) => t.id === parseInt(filtersData.pueblo));
if(town) {
preFilteredData = preFilteredData.filter((d) => d.town_id === town.id);
}
}

if(isStringTrue(filtersData.soloSinAsignar)) {
preFilteredData = preFilteredData.filter((d) => d.asignees_count === 0);
}

setDataFiltered(getDataFiltered(preFilteredData, filters));
}, [data, filtersData, towns]);

Expand Down
21 changes: 12 additions & 9 deletions src/app/casos-activos/solicitudes/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ const getData = async (supabase: SupabaseClient<Database>, filters: FiltersData)
.eq('type', 'necesita')
.neq('status', 'finished');

// Solo agregar filtro si es true
if (filters.soloSinAsignar !== undefined && filters.soloSinAsignar === 'true') {
// Solo agregar filtro si es true o no se especificó
if (filters.soloSinAsignar === undefined || filters.soloSinAsignar === 'true') {
query.eq('assignments_count', 0);
}

Expand All @@ -44,19 +44,22 @@ const getData = async (supabase: SupabaseClient<Database>, filters: FiltersData)

const getCount = async (supabase: SupabaseClient<Database>, filters: FiltersData) => {
const query = supabase
.from('help_requests_with_assignment_count')
.select('id', { count: 'exact' })
.eq('type', 'necesita');
// Solo agregar filtro si es true
if (filters.soloSinAsignar !== undefined && filters.soloSinAsignar === 'true') {
query.eq('assignments_count', 0);
.from('help_requests_with_assignment_count')
.select('id', { count: 'exact' })
.eq('type', 'necesita')
.neq('status', 'finished');

// Solo agregar filtro si es true o no se especificó
if (filters.soloSinAsignar === undefined || filters.soloSinAsignar === 'true') {
query.eq('assignments_count', 0);
}
const { count: solicitaCount, error: solicitaError } = await query;

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

if (solicitaError) {
throw new Error('Error fetching solicita:', solicitaError);
Expand Down
4 changes: 2 additions & 2 deletions src/app/solicitudes/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default function CasoDetalle() {
<div className="space-y-6 mx-auto max-w-7xl px-4 sm:px-6">
<div className="flex justify-start">
<button
className="flex flex-row items-center px-4 py-2 bg-gray-200 text-gray-700 rounded hover:bg-gray-300"
className="ml-10 sm:ml-4 flex flex-row items-center px-4 py-2 bg-gray-200 text-gray-700 rounded hover:bg-gray-300"
onClick={() => history.back()}
>
<ArrowLeft className="w-4 h-4 mr-2" />
Expand All @@ -60,7 +60,7 @@ export default function CasoDetalle() {
<div className="space-y-6 mx-auto max-w-7xl px-4 sm:px-6">
<div className="flex justify-start">
<button
className="flex flex-row items-center px-4 py-2 bg-gray-200 text-gray-700 rounded hover:bg-gray-300"
className="ml-10 sm:ml-4 flex flex-row items-center px-4 py-2 bg-gray-200 text-gray-700 rounded hover:bg-gray-300"
onClick={() => history.back()}
>
<ArrowLeft className="w-4 h-4 mr-2" />
Expand Down

0 comments on commit 5c12afd

Please sign in to comment.