diff --git a/app/home/(user)/(dashboard)/page.tsx b/app/home/(user)/(dashboard)/page.tsx
index 75b3d20..2f8b287 100644
--- a/app/home/(user)/(dashboard)/page.tsx
+++ b/app/home/(user)/(dashboard)/page.tsx
@@ -37,7 +37,7 @@ async function UserHomePage() {
}
/>
-
+
>
);
diff --git a/app/home/(user)/_components/dashboard.tsx b/app/home/(user)/_components/dashboard.tsx
index 0498cdb..e93ce86 100644
--- a/app/home/(user)/_components/dashboard.tsx
+++ b/app/home/(user)/_components/dashboard.tsx
@@ -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: ,
iconBg: 'bg-success',
},
{
title: 'dashboard:age',
- description: '43',
+ description: age ? `${age}` : '-',
icon: ,
iconBg: 'bg-success',
},
{
title: 'dashboard:height',
- description: '183',
+ description: height ? `${height}cm` : '-',
icon: ,
iconBg: 'bg-success',
},
{
title: 'dashboard:weight',
- description: '92kg',
+ description: weight ? `${weight}kg` : '-',
icon: ,
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 (
<>
- {dummyCards.map(
+ {cards({
+ gender: params?.gender,
+ age: params?.age,
+ height: account.account_params?.height,
+ weight: account.account_params?.weight,
+ }).map(
({
title,
description,
diff --git a/packages/features/accounts/src/server/api.ts b/packages/features/accounts/src/server/api.ts
index 62c25d9..dba85a8 100644
--- a/packages/features/accounts/src/server/api.ts
+++ b/packages/features/accounts/src/server/api.ts
@@ -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
| 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 {
const { data, error } = await this.client
.schema('medreport')
.from('accounts')
- .select('*')
+ .select('*, account_params: account_params (weight, height)')
.eq('id', id)
.single();
diff --git a/packages/supabase/src/database.types.ts b/packages/supabase/src/database.types.ts
index 9a735ee..0e0daf6 100644
--- a/packages/supabase/src/database.types.ts
+++ b/packages/supabase/src/database.types.ts
@@ -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"]
diff --git a/supabase/migrations/20250724082606_account_params_relation_fix.sql b/supabase/migrations/20250724082606_account_params_relation_fix.sql
new file mode 100644
index 0000000..2dd76b2
--- /dev/null
+++ b/supabase/migrations/20250724082606_account_params_relation_fix.sql
@@ -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;