-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add button to assign to a help request and show a badge with th…
…e count
- Loading branch information
Showing
3 changed files
with
85 additions
and
53 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,33 @@ | ||
import { HelpRequestAssignmentData } from '@/types/Requests'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { helpRequestService } from '@/lib/service'; | ||
import { Spinner } from '@/components/Spinner'; | ||
|
||
type SolicitudHelpCountProps = { | ||
id: number; | ||
}; | ||
|
||
export default function SolicitudHelpCount({ id }: SolicitudHelpCountProps) { | ||
const { | ||
data: assignments, | ||
isLoading, | ||
error, | ||
} = useQuery<HelpRequestAssignmentData[]>({ | ||
queryKey: ['help_request_assignments', { id: id }], | ||
queryFn: () => helpRequestService.getAssignments(id), | ||
}); | ||
|
||
if (isLoading) return <Spinner />; | ||
|
||
if (error || assignments === undefined) return <></>; | ||
|
||
const volunteers = assignments.length; | ||
|
||
return ( | ||
<span | ||
className={`px-3 py-1 rounded-full text-sm font-medium whitespace-nowrap mr-2 ${volunteers === 0 ? 'bg-red-300' : 'bg-green-300'}`} | ||
> | ||
Voluntarios: {volunteers} | ||
</span> | ||
); | ||
} |