From a88783bdaf660eec5d5d0906b48a3577b10580b6 Mon Sep 17 00:00:00 2001 From: j8seangel Date: Fri, 15 Nov 2024 09:17:13 +0100 Subject: [PATCH] wip: avoid extra request on SolicitudesCard --- src/app/solicitudes/[id]/page.tsx | 2 +- src/components/solicitudes/SolicitudCard.tsx | 19 +++++---- .../solicitudes/SolicitudHelpCount.tsx | 40 +++++++++++++++++++ 3 files changed, 50 insertions(+), 11 deletions(-) create mode 100644 src/components/solicitudes/SolicitudHelpCount.tsx diff --git a/src/app/solicitudes/[id]/page.tsx b/src/app/solicitudes/[id]/page.tsx index 037fc3b..ef02e2a 100644 --- a/src/app/solicitudes/[id]/page.tsx +++ b/src/app/solicitudes/[id]/page.tsx @@ -68,7 +68,7 @@ export default function CasoDetalle() { - + {/* */} ); } diff --git a/src/components/solicitudes/SolicitudCard.tsx b/src/components/solicitudes/SolicitudCard.tsx index f79f587..a4f6f4d 100644 --- a/src/components/solicitudes/SolicitudCard.tsx +++ b/src/components/solicitudes/SolicitudCard.tsx @@ -23,7 +23,7 @@ import { UserRoles } from '@/helpers/constants'; import CRMNotes from '@/components/CRMNotes'; type SolicitudCardProps = { - caso: HelpRequestDataWAssignmentCount; + caso: SelectedHelpData | HelpRequestData | HelpRequestDataWAssignmentCount; showLink?: boolean; showEdit?: boolean; format?: 'small' | 'large'; @@ -78,11 +78,10 @@ export default function SolicitudCard({
-
- {caso.help_request_assignment_count} VOLUNTARIOS -
+ {/* */}
- Pueblo: {getTownById(caso.town_id)?.name || ''} + {/* Pueblo: {getTownById(caso.town_id)?.name || ''} */}
)} {caso.contact_info && (
- - + {/* */} + {/* */}
)} {caso.help_type && ( @@ -201,7 +200,7 @@ export default function SolicitudCard({ Ver solicitud )} - {!isCrmUser && } + {/* {!isCrmUser && } */} {isAdmin && ( ({ + queryKey: ['help_request_assignments', { id: id }], + queryFn: () => getAssignments(id), + enabled: false //count === undefined, + }); + + if (!count && isLoading) return ; + + if (error || assignments === undefined) return <>; + + const volunteers = count || assignments.length; + + let colorClass: string; + + if (volunteers === 0) { + colorClass = 'bg-red-100 text-red-800'; + } else { + colorClass = 'bg-green-100 text-green-800'; + } + return ( +
+ {volunteers} VOLUNTARIOS +
+ ); +}