feat(dashboard, api): enhance dashboard card calculations and add team membership check

This commit is contained in:
Danel Kungla
2025-08-21 21:32:22 +03:00
parent 492327c5c7
commit b1b0846234
2 changed files with 100 additions and 73 deletions

View File

@@ -40,7 +40,13 @@ const cards = ({
age?: number; age?: number;
height?: number | null; height?: number | null;
weight?: number | null; weight?: number | null;
}) => [ }) => {
const heightInMeters = height ? height / 100 : null;
const bmi =
heightInMeters && weight
? (weight / (heightInMeters * heightInMeters)).toFixed(1)
: null;
return [
{ {
title: 'dashboard:gender', title: 'dashboard:gender',
description: gender ?? 'dashboard:male', description: gender ?? 'dashboard:male',
@@ -63,50 +69,51 @@ const cards = ({
title: 'dashboard:weight', title: 'dashboard:weight',
description: weight ? `${weight}kg` : '-', description: weight ? `${weight}kg` : '-',
icon: <Scale />, icon: <Scale />,
iconBg: 'bg-warning', iconBg: 'bg-success',
}, },
{ {
title: 'dashboard:bmi', title: 'dashboard:bmi',
description: '27.5', description: bmi,
icon: <TrendingUp />, icon: <TrendingUp />,
iconBg: 'bg-warning', iconBg: 'bg-success',
}, },
{ {
title: 'dashboard:bloodPressure', title: 'dashboard:bloodPressure',
description: '160/98', description: '-',
icon: <Activity />, icon: <Activity />,
iconBg: 'bg-warning', iconBg: 'bg-warning',
}, },
{ {
title: 'dashboard:cholesterol', title: 'dashboard:cholesterol',
description: '5', description: '-',
icon: <BlendingModeIcon className="size-4" />, icon: <BlendingModeIcon className="size-4" />,
iconBg: 'bg-destructive', iconBg: 'bg-destructive',
}, },
{ {
title: 'dashboard:ldlCholesterol', title: 'dashboard:ldlCholesterol',
description: '3,6', description: '-',
icon: <Pill />, icon: <Pill />,
iconBg: 'bg-warning', iconBg: 'bg-warning',
}, },
{ // {
title: 'Score 2', // title: 'Score 2',
description: 'Normis', // description: 'Normis',
icon: <LineChart />, // icon: <LineChart />,
iconBg: 'bg-success', // iconBg: 'bg-success',
}, // },
{ // {
title: 'dashboard:smoking', // title: 'dashboard:smoking',
description: 'dashboard:respondToQuestion', // description: 'dashboard:respondToQuestion',
descriptionColor: 'text-primary', // descriptionColor: 'text-primary',
icon: ( // icon: (
<Button size="icon" variant="outline" className="px-2 text-black"> // <Button size="icon" variant="outline" className="px-2 text-black">
<ChevronRight className="size-4 stroke-2" /> // <ChevronRight className="size-4 stroke-2" />
</Button> // </Button>
), // ),
cardVariant: 'gradient-success' as CardProps['variant'], // cardVariant: 'gradient-success' as CardProps['variant'],
}, // },
]; ];
};
const dummyRecommendations = [ const dummyRecommendations = [
{ {
@@ -162,8 +169,8 @@ export default function Dashboard({ account }: { account: AccountWithParams }) {
{cards({ {cards({
gender: params?.gender, gender: params?.gender,
age: params?.age, age: params?.age,
height: account.account_params?.height, height: account.account_params?.[0]?.height,
weight: account.account_params?.weight, weight: account.account_params?.[0]?.weight,
}).map( }).map(
({ ({
title, title,

View File

@@ -6,10 +6,12 @@ import { UserAnalysis } from '../types/accounts';
export type AccountWithParams = export type AccountWithParams =
Database['medreport']['Tables']['accounts']['Row'] & { Database['medreport']['Tables']['accounts']['Row'] & {
account_params: Pick< account_params:
| Pick<
Database['medreport']['Tables']['account_params']['Row'], Database['medreport']['Tables']['account_params']['Row'],
'weight' | 'height' 'weight' | 'height'
> | null; >[]
| null;
}; };
/** /**
@@ -222,6 +224,24 @@ class AccountsApi {
), ),
})); }));
} }
async hasAccountTeamMembership(accountId?: string) {
if (!accountId) {
return false;
}
const { count, error } = await this.client
.schema('medreport')
.from('accounts_memberships')
.select('account_id', { count: 'exact', head: true })
.eq('account_id', accountId);
if (error) {
throw error;
}
return (count ?? 0) > 0;
}
} }
export function createAccountsApi(client: SupabaseClient<Database>) { export function createAccountsApi(client: SupabaseClient<Database>) {