feat(MED-50): use account_params in dashboard

This commit is contained in:
2025-07-24 08:38:12 +03:00
parent 66760adc06
commit 349e3e3143
5 changed files with 57 additions and 18 deletions

View File

@@ -37,7 +37,7 @@ async function UserHomePage() {
}
/>
<PageBody>
<Dashboard />
<Dashboard account={account} />
</PageBody>
</>
);

View File

@@ -15,6 +15,7 @@ import {
TrendingUp,
User,
} from 'lucide-react';
import Isikukood from 'isikukood';
import { Button } from '@kit/ui/button';
import {
@@ -27,29 +28,40 @@ import {
} from '@kit/ui/card';
import { Trans } from '@kit/ui/trans';
import { cn } from '@kit/ui/utils';
import type { AccountWithParams } from '@/packages/features/accounts/src/server/api';
const dummyCards = [
const cards = ({
gender,
age,
height,
weight,
}: {
gender?: string;
age?: number;
height?: number | null;
weight?: number | null;
}) => [
{
title: 'dashboard:gender',
description: 'dashboard:male',
description: gender ?? 'dashboard:male',
icon: <User />,
iconBg: 'bg-success',
},
{
title: 'dashboard:age',
description: '43',
description: age ? `${age}` : '-',
icon: <Clock9 />,
iconBg: 'bg-success',
},
{
title: 'dashboard:height',
description: '183',
description: height ? `${height}cm` : '-',
icon: <RulerHorizontalIcon className="size-4" />,
iconBg: 'bg-success',
},
{
title: 'dashboard:weight',
description: '92kg',
description: weight ? `${weight}kg` : '-',
icon: <Scale />,
iconBg: 'bg-warning',
},
@@ -128,11 +140,31 @@ const dummyRecommendations = [
},
];
export default function Dashboard() {
const getPersonParameters = (personalCode: string) => {
try {
const person = new Isikukood(personalCode);
return {
gender: person.getGender(),
age: person.getAge(),
};
} catch (error) {
console.error(error);
return null;
}
};
export default function Dashboard({ account }: { account: AccountWithParams }) {
const params = getPersonParameters(account.personal_code!);
return (
<>
<div className="grid auto-rows-fr grid-cols-2 gap-3 sm:grid-cols-4 lg:grid-cols-5">
{dummyCards.map(
{cards({
gender: params?.gender,
age: params?.age,
height: account.account_params?.height,
weight: account.account_params?.weight,
}).map(
({
title,
description,

View File

@@ -4,6 +4,10 @@ import { Database } from '@kit/supabase/database';
import { UserAnalysis } from '../types/accounts';
export type AccountWithParams = Database['medreport']['Tables']['accounts']['Row'] & {
account_params: Pick<Database['medreport']['Tables']['account_params']['Row'], 'weight' | 'height'> | null;
};
/**
* Class representing an API for interacting with user accounts.
* @constructor
@@ -17,11 +21,11 @@ class AccountsApi {
* @description Get the account data for the given ID.
* @param id
*/
async getAccount(id: string) {
async getAccount(id: string): Promise<AccountWithParams> {
const { data, error } = await this.client
.schema('medreport')
.from('accounts')
.select('*')
.select('*, account_params: account_params (weight, height)')
.eq('id', id)
.single();

View File

@@ -203,7 +203,15 @@ export type Database = {
recorded_at?: string
weight?: number | null
}
Relationships: []
Relationships: [
{
foreignKeyName: "account_params_account_id_fkey"
columns: ["account_id"]
isOneToOne: true
referencedRelation: "accounts"
referencedColumns: ["id"]
},
]
}
accounts: {
Row: {
@@ -297,13 +305,7 @@ export type Database = {
user_id?: string
}
Relationships: [
{
foreignKeyName: "accounts_memberships_account_id_fkey"
columns: ["account_id"]
isOneToOne: false
referencedRelation: "accounts"
referencedColumns: ["id"]
},
{
foreignKeyName: "accounts_memberships_account_id_fkey"
columns: ["account_id"]

View File

@@ -0,0 +1 @@
alter table "medreport"."account_params" add constraint "account_params_account_id_fkey" FOREIGN KEY (account_id) REFERENCES medreport.accounts(id) ON DELETE CASCADE not valid;