feat(MED-50): use account_params in dashboard
This commit is contained in:
@@ -37,7 +37,7 @@ async function UserHomePage() {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<PageBody>
|
<PageBody>
|
||||||
<Dashboard />
|
<Dashboard account={account} />
|
||||||
</PageBody>
|
</PageBody>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import {
|
|||||||
TrendingUp,
|
TrendingUp,
|
||||||
User,
|
User,
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
|
import Isikukood from 'isikukood';
|
||||||
|
|
||||||
import { Button } from '@kit/ui/button';
|
import { Button } from '@kit/ui/button';
|
||||||
import {
|
import {
|
||||||
@@ -27,29 +28,40 @@ import {
|
|||||||
} from '@kit/ui/card';
|
} from '@kit/ui/card';
|
||||||
import { Trans } from '@kit/ui/trans';
|
import { Trans } from '@kit/ui/trans';
|
||||||
import { cn } from '@kit/ui/utils';
|
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',
|
title: 'dashboard:gender',
|
||||||
description: 'dashboard:male',
|
description: gender ?? 'dashboard:male',
|
||||||
icon: <User />,
|
icon: <User />,
|
||||||
iconBg: 'bg-success',
|
iconBg: 'bg-success',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'dashboard:age',
|
title: 'dashboard:age',
|
||||||
description: '43',
|
description: age ? `${age}` : '-',
|
||||||
icon: <Clock9 />,
|
icon: <Clock9 />,
|
||||||
iconBg: 'bg-success',
|
iconBg: 'bg-success',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'dashboard:height',
|
title: 'dashboard:height',
|
||||||
description: '183',
|
description: height ? `${height}cm` : '-',
|
||||||
icon: <RulerHorizontalIcon className="size-4" />,
|
icon: <RulerHorizontalIcon className="size-4" />,
|
||||||
iconBg: 'bg-success',
|
iconBg: 'bg-success',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'dashboard:weight',
|
title: 'dashboard:weight',
|
||||||
description: '92kg',
|
description: weight ? `${weight}kg` : '-',
|
||||||
icon: <Scale />,
|
icon: <Scale />,
|
||||||
iconBg: 'bg-warning',
|
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 (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="grid auto-rows-fr grid-cols-2 gap-3 sm:grid-cols-4 lg:grid-cols-5">
|
<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,
|
title,
|
||||||
description,
|
description,
|
||||||
|
|||||||
@@ -4,6 +4,10 @@ import { Database } from '@kit/supabase/database';
|
|||||||
|
|
||||||
import { UserAnalysis } from '../types/accounts';
|
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.
|
* Class representing an API for interacting with user accounts.
|
||||||
* @constructor
|
* @constructor
|
||||||
@@ -17,11 +21,11 @@ class AccountsApi {
|
|||||||
* @description Get the account data for the given ID.
|
* @description Get the account data for the given ID.
|
||||||
* @param id
|
* @param id
|
||||||
*/
|
*/
|
||||||
async getAccount(id: string) {
|
async getAccount(id: string): Promise<AccountWithParams> {
|
||||||
const { data, error } = await this.client
|
const { data, error } = await this.client
|
||||||
.schema('medreport')
|
.schema('medreport')
|
||||||
.from('accounts')
|
.from('accounts')
|
||||||
.select('*')
|
.select('*, account_params: account_params (weight, height)')
|
||||||
.eq('id', id)
|
.eq('id', id)
|
||||||
.single();
|
.single();
|
||||||
|
|
||||||
|
|||||||
@@ -203,7 +203,15 @@ export type Database = {
|
|||||||
recorded_at?: string
|
recorded_at?: string
|
||||||
weight?: number | null
|
weight?: number | null
|
||||||
}
|
}
|
||||||
Relationships: []
|
Relationships: [
|
||||||
|
{
|
||||||
|
foreignKeyName: "account_params_account_id_fkey"
|
||||||
|
columns: ["account_id"]
|
||||||
|
isOneToOne: true
|
||||||
|
referencedRelation: "accounts"
|
||||||
|
referencedColumns: ["id"]
|
||||||
|
},
|
||||||
|
]
|
||||||
}
|
}
|
||||||
accounts: {
|
accounts: {
|
||||||
Row: {
|
Row: {
|
||||||
@@ -297,13 +305,7 @@ export type Database = {
|
|||||||
user_id?: string
|
user_id?: string
|
||||||
}
|
}
|
||||||
Relationships: [
|
Relationships: [
|
||||||
{
|
|
||||||
foreignKeyName: "accounts_memberships_account_id_fkey"
|
|
||||||
columns: ["account_id"]
|
|
||||||
isOneToOne: false
|
|
||||||
referencedRelation: "accounts"
|
|
||||||
referencedColumns: ["id"]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
foreignKeyName: "accounts_memberships_account_id_fkey"
|
foreignKeyName: "accounts_memberships_account_id_fkey"
|
||||||
columns: ["account_id"]
|
columns: ["account_id"]
|
||||||
|
|||||||
@@ -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;
|
||||||
Reference in New Issue
Block a user