feat(dashboard, api): enhance dashboard card calculations and add team membership check
This commit is contained in:
@@ -40,73 +40,80 @@ const cards = ({
|
|||||||
age?: number;
|
age?: number;
|
||||||
height?: number | null;
|
height?: number | null;
|
||||||
weight?: number | null;
|
weight?: number | null;
|
||||||
}) => [
|
}) => {
|
||||||
{
|
const heightInMeters = height ? height / 100 : null;
|
||||||
title: 'dashboard:gender',
|
const bmi =
|
||||||
description: gender ?? 'dashboard:male',
|
heightInMeters && weight
|
||||||
icon: <User />,
|
? (weight / (heightInMeters * heightInMeters)).toFixed(1)
|
||||||
iconBg: 'bg-success',
|
: null;
|
||||||
},
|
return [
|
||||||
{
|
{
|
||||||
title: 'dashboard:age',
|
title: 'dashboard:gender',
|
||||||
description: age ? `${age}` : '-',
|
description: gender ?? 'dashboard:male',
|
||||||
icon: <Clock9 />,
|
icon: <User />,
|
||||||
iconBg: 'bg-success',
|
iconBg: 'bg-success',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'dashboard:height',
|
title: 'dashboard:age',
|
||||||
description: height ? `${height}cm` : '-',
|
description: age ? `${age}` : '-',
|
||||||
icon: <RulerHorizontalIcon className="size-4" />,
|
icon: <Clock9 />,
|
||||||
iconBg: 'bg-success',
|
iconBg: 'bg-success',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'dashboard:weight',
|
title: 'dashboard:height',
|
||||||
description: weight ? `${weight}kg` : '-',
|
description: height ? `${height}cm` : '-',
|
||||||
icon: <Scale />,
|
icon: <RulerHorizontalIcon className="size-4" />,
|
||||||
iconBg: 'bg-warning',
|
iconBg: 'bg-success',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'dashboard:bmi',
|
title: 'dashboard:weight',
|
||||||
description: '27.5',
|
description: weight ? `${weight}kg` : '-',
|
||||||
icon: <TrendingUp />,
|
icon: <Scale />,
|
||||||
iconBg: 'bg-warning',
|
iconBg: 'bg-success',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'dashboard:bloodPressure',
|
title: 'dashboard:bmi',
|
||||||
description: '160/98',
|
description: bmi,
|
||||||
icon: <Activity />,
|
icon: <TrendingUp />,
|
||||||
iconBg: 'bg-warning',
|
iconBg: 'bg-success',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'dashboard:cholesterol',
|
title: 'dashboard:bloodPressure',
|
||||||
description: '5',
|
description: '-',
|
||||||
icon: <BlendingModeIcon className="size-4" />,
|
icon: <Activity />,
|
||||||
iconBg: 'bg-destructive',
|
iconBg: 'bg-warning',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'dashboard:ldlCholesterol',
|
title: 'dashboard:cholesterol',
|
||||||
description: '3,6',
|
description: '-',
|
||||||
icon: <Pill />,
|
icon: <BlendingModeIcon className="size-4" />,
|
||||||
iconBg: 'bg-warning',
|
iconBg: 'bg-destructive',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'Score 2',
|
title: 'dashboard:ldlCholesterol',
|
||||||
description: 'Normis',
|
description: '-',
|
||||||
icon: <LineChart />,
|
icon: <Pill />,
|
||||||
iconBg: 'bg-success',
|
iconBg: 'bg-warning',
|
||||||
},
|
},
|
||||||
{
|
// {
|
||||||
title: 'dashboard:smoking',
|
// title: 'Score 2',
|
||||||
description: 'dashboard:respondToQuestion',
|
// description: 'Normis',
|
||||||
descriptionColor: 'text-primary',
|
// icon: <LineChart />,
|
||||||
icon: (
|
// iconBg: 'bg-success',
|
||||||
<Button size="icon" variant="outline" className="px-2 text-black">
|
// },
|
||||||
<ChevronRight className="size-4 stroke-2" />
|
// {
|
||||||
</Button>
|
// title: 'dashboard:smoking',
|
||||||
),
|
// description: 'dashboard:respondToQuestion',
|
||||||
cardVariant: 'gradient-success' as CardProps['variant'],
|
// descriptionColor: 'text-primary',
|
||||||
},
|
// icon: (
|
||||||
];
|
// <Button size="icon" variant="outline" className="px-2 text-black">
|
||||||
|
// <ChevronRight className="size-4 stroke-2" />
|
||||||
|
// </Button>
|
||||||
|
// ),
|
||||||
|
// 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,
|
||||||
|
|||||||
@@ -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:
|
||||||
Database['medreport']['Tables']['account_params']['Row'],
|
| Pick<
|
||||||
'weight' | 'height'
|
Database['medreport']['Tables']['account_params']['Row'],
|
||||||
> | null;
|
'weight' | 'height'
|
||||||
|
>[]
|
||||||
|
| 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>) {
|
||||||
|
|||||||
Reference in New Issue
Block a user