import * as React from "react"; import { Box, Paper, Typography } from "@mui/material"; import ProgressCardView from "./ProgressCard.view"; import { extractTopPayees } from "./TopPayees.adapter"; import { ProgressCardProps } from "./ProgressCard.props"; export default function TopPayees(props: ProgressCardProps) { const { title, reportData, state, stateSetters, isFetching, } = props const { flow, selectedPeriodId, selectedGroupKey } = state; const { setSelectedGroupKey } = stateSetters; const { items, total } = React.useMemo(() => { return extractTopPayees(reportData, flow, selectedPeriodId, selectedGroupKey); }, [reportData, flow, selectedPeriodId, selectedGroupKey]); return ( {title} {items.map((item) => { const isSelected = !!selectedGroupKey?.payee?.includes(item.name); return ( { if (setSelectedGroupKey) { let newKey = selectedGroupKey ? { ...selectedGroupKey } : {}; if (isSelected) { delete newKey.payee; } else { newKey.payee = [item.name]; } setSelectedGroupKey(Object.keys(newKey).length ? newKey : null); } }} /> ); })} ); }