diff --git a/frontend/src/components/pages/home/HomeRoomCard.tsx b/frontend/src/components/pages/home/HomeRoomCard.tsx index 47870709..19cd933e 100644 --- a/frontend/src/components/pages/home/HomeRoomCard.tsx +++ b/frontend/src/components/pages/home/HomeRoomCard.tsx @@ -6,9 +6,16 @@ import { Flex, Heading, Text, Box, Circle } from "@chakra-ui/react"; type Props = { room: string | number; residentId: number; + pendingTasks: number; + assignedTasks: number; }; -const RoomCard = ({ room, residentId }: Props): React.ReactElement => { +const RoomCard = ({ + room, + residentId, + pendingTasks, + assignedTasks, +}: Props): React.ReactElement => { return ( { padding={2.5} > - 1 + {pendingTasks} { padding={2.5} > - 2 + {assignedTasks} { + const { data: residentData } = useQuery(GET_ACTIVE_RESIDENTS); + + const { data: pending } = useQuery(GET_TASKS_BY_STATUS, { + variables: { status: "PENDING_APPROVAL" }, + }); + + const { data: assigned } = useQuery(GET_TASKS_BY_STATUS, { + variables: { status: "ASSIGNED" }, + }); + + const fetchTasksForResident = (assigneeId: number) => { + const assignedTasks = + assigned?.getTasksByStatus?.filter( + (task: { assigneeId: number }) => task.assigneeId === assigneeId, + ).length || 0; + const pendingTasks = + pending?.getTasksByStatus?.filter( + (task: { assigneeId: number }) => task.assigneeId === assigneeId, + ).length || 0; + return { assignedTasks, pendingTasks, loading: false, error: null }; + }; -function RoomGrid() { return ( - {rooms.map((room) => ( - - ))} + {residentData?.getAllResidents?.map( + (room: { + roomNumber: string; + residentId: number; + userId: number; + }) => { + const { assignedTasks, pendingTasks } = fetchTasksForResident( + room.userId, + ); + + return ( + + ); + }, + )} ); -} +}; export default RoomGrid;