Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | import { useMemo } from 'react'; import { type CurrencyValue } from '@amalia/kernel/monetary/types'; import { useLeaderboardWidget } from '@amalia/reporting/dashboards/state'; import { type UserContract } from '@amalia/tenants/users/types'; import { type DataLeaderboard } from '../dashboard.utils'; export const useLeaderBoardData = ( periodId: string, selectedUserIds: string[], selectedTeamIds: string[], selectedPlanIds: string[], allUsers: Pick<UserContract, 'email' | 'firstName' | 'lastName' | 'pictureURL'>[], ) => { const { data: leaderBoard, isLoading: isLeaderBoardLoading } = useLeaderboardWidget({ periodId, userIds: selectedUserIds, planIds: selectedPlanIds, teamIds: selectedTeamIds, }); const dataLeaderBoard: DataLeaderboard[] = useMemo( () => (leaderBoard?.records ?? []).map((r) => ({ stats: { plan: r['PAYMENT__value'] as CurrencyValue }, user: allUsers.find((u) => u.email === r['paymentOwner__email']) || { firstName: `${r['paymentOwner__firstName'] as string}`, lastName: `${r['paymentOwner__lastName'] as string}`, email: `${r['paymentOwner__email'] as string}`, pictureURL: null, }, })), [allUsers, leaderBoard], ); return { dataLeaderBoard, isLeaderBoardLoading, }; }; |