Files
medreport_mrb2b/app/home/[account]/_lib/server/load-team-account-health-details.ts
Danel Kungla 2b79a9e401 Refactor team account statistics and health details
- Simplified the TeamAccountStatistics component by removing unused code and integrating translation for health details.
- Updated the load-team-account-health-details to calculate average BMI based on member parameters.
- Adjusted the billing page to correctly reference the number of team members.
- Enhanced the main account page to pass member parameters to the Dashboard component.
- Modified the admin account page to destructure member data from the API response.
- Updated the TeamAccountsApi to return member parameters alongside member data.
- Added new translations for health details in Estonian locale.
2025-08-18 16:50:26 +03:00

80 lines
1.8 KiB
TypeScript

import React from 'react';
import { Clock, TrendingUp, User } from 'lucide-react';
import { TeamAccountStatisticsProps } from '../../_components/team-account-statistics';
interface AccountHealthDetailsField {
title: string;
value: string | number;
Icon: React.ComponentType<{
size?: number;
color?: string;
className?: string;
}>;
normStatus: NormStatus;
}
export enum NormStatus {
CRITICAL = 'CRITICAL',
WARNING = 'WARNING',
NORMAL = 'NORMAL',
}
export const getAccountHealthDetailsFields = (
memberParams: TeamAccountStatisticsProps['memberParams'],
): AccountHealthDetailsField[] => {
const averageBMI = (
memberParams.reduce((sum, { height, weight }) => {
const hMeters = height! / 100;
const bmi = weight! / (hMeters * hMeters);
return sum + bmi;
}, 0) / memberParams.length
).toFixed(0);
return [
{
title: 'teams:healthDetails.women',
value: `50% (${memberParams.length})`,
Icon: User,
normStatus: NormStatus.NORMAL,
},
{
title: 'teams:healthDetails.men',
value: `50% (${memberParams.length})`,
Icon: User,
normStatus: NormStatus.NORMAL,
},
{
title: 'teams:healthDetails.avgAge',
value: '56',
Icon: Clock,
normStatus: NormStatus.NORMAL,
},
{
title: 'teams:healthDetails.bmi',
value: averageBMI,
Icon: TrendingUp,
normStatus: NormStatus.WARNING,
},
{
title: 'teams:healthDetails.cholesterol',
value: '6.1',
Icon: TrendingUp,
normStatus: NormStatus.WARNING,
},
{
title: 'teams:healthDetails.vitaminD',
value: '76',
Icon: TrendingUp,
normStatus: NormStatus.NORMAL,
},
{
title: 'teams:healthDetails.smokers',
value: '22%',
Icon: TrendingUp,
normStatus: NormStatus.CRITICAL,
},
];
};