-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: avoid extra request on SolicitudesCard
- Loading branch information
Showing
3 changed files
with
50 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { HelpRequestAssignmentData } from '@/types/Requests'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { Spinner } from '@/components/Spinner'; | ||
import { getAssignments } from '@/lib/actions'; | ||
|
||
type SolicitudHelpCountProps = { | ||
id: number; | ||
count?: number; | ||
}; | ||
|
||
export default function SolicitudHelpCount({ id, count }: SolicitudHelpCountProps) { | ||
const { | ||
data: assignments, | ||
isLoading, | ||
error, | ||
} = useQuery<HelpRequestAssignmentData[]>({ | ||
queryKey: ['help_request_assignments', { id: id }], | ||
queryFn: () => getAssignments(id), | ||
enabled: false //count === undefined, | ||
}); | ||
|
||
if (!count && isLoading) return <Spinner />; | ||
|
||
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 ( | ||
<div className={`flex items-center justify-center rounded-full px-4 py-2 ${colorClass}`}> | ||
<span className={`text-sm font-bold`}>{volunteers} VOLUNTARIOS</span> | ||
</div> | ||
); | ||
} |