From 2d9e6f8df3dcca866557b46e417b736de2f6de00 Mon Sep 17 00:00:00 2001 From: Karli Date: Fri, 26 Sep 2025 16:34:10 +0300 Subject: [PATCH] feat(MED-97): display accounts count, usage total --- .../team-account-benefit-statistics.tsx | 50 ++++++++++++------- .../_components/team-account-statistics.tsx | 7 ++- .../load-team-account-benefit-statistics.ts | 2 +- app/home/[account]/page.tsx | 6 +++ public/locales/en/teams.json | 6 ++- public/locales/et/teams.json | 10 ++-- public/locales/ru/teams.json | 6 ++- 7 files changed, 58 insertions(+), 29 deletions(-) diff --git a/app/home/[account]/_components/team-account-benefit-statistics.tsx b/app/home/[account]/_components/team-account-benefit-statistics.tsx index 035ff9d..81f232d 100644 --- a/app/home/[account]/_components/team-account-benefit-statistics.tsx +++ b/app/home/[account]/_components/team-account-benefit-statistics.tsx @@ -1,13 +1,13 @@ import React from 'react'; import { formatCurrency } from '@/packages/shared/src/utils'; -import { PiggyBankIcon } from 'lucide-react'; import { useTranslation } from 'react-i18next'; import { Card, CardTitle } from '@kit/ui/card'; import { cn } from '@kit/ui/lib/utils'; import { Trans } from '@kit/ui/trans'; +import { TeamAccountBenefitExpensesOverview } from '../_lib/server/load-team-account-benefit-expenses-overview'; import { AccountBenefitStatistics } from '../_lib/server/load-team-account-benefit-statistics'; const StatisticsCard = ({ children }: { children: React.ReactNode }) => { @@ -38,8 +38,10 @@ const StatisticsValue = ({ children }: { children: React.ReactNode }) => { const TeamAccountBenefitStatistics = ({ accountBenefitStatistics, + expensesOverview, }: { accountBenefitStatistics: AccountBenefitStatistics; + expensesOverview: TeamAccountBenefitExpensesOverview; }) => { const { i18n: { language }, @@ -47,25 +49,16 @@ const TeamAccountBenefitStatistics = ({ return (
- -
-
- -
- - +
+ + + - {formatCurrency({ - value: accountBenefitStatistics.periodTotal, - locale: language, - currencyCode: 'EUR', - })} + {accountBenefitStatistics.companyAccountsCount} -
- + -
@@ -79,11 +72,30 @@ const TeamAccountBenefitStatistics = ({ + + + + + + {formatCurrency({ + value: expensesOverview.currentMonthUsageTotal, + locale: language, + currencyCode: 'EUR', + })} + + + - {accountBenefitStatistics.orders.analysesSum} € + + {formatCurrency({ + value: accountBenefitStatistics.orders.analysesSum, + locale: language, + currencyCode: 'EUR', + })} + diff --git a/app/home/[account]/_components/team-account-statistics.tsx b/app/home/[account]/_components/team-account-statistics.tsx index bae53a4..17a7466 100644 --- a/app/home/[account]/_components/team-account-statistics.tsx +++ b/app/home/[account]/_components/team-account-statistics.tsx @@ -20,6 +20,7 @@ import { AccountBenefitStatistics } from '../_lib/server/load-team-account-benef import TeamAccountBenefitStatistics from './team-account-benefit-statistics'; import TeamAccountHealthDetails from './team-account-health-details'; import type { Account, AccountParams, BmiThresholds } from '@/packages/features/accounts/src/types/accounts'; +import { TeamAccountBenefitExpensesOverview } from '../_lib/server/load-team-account-benefit-expenses-overview'; export interface TeamAccountStatisticsProps { teamAccount: Account; @@ -27,6 +28,7 @@ export interface TeamAccountStatisticsProps { bmiThresholds: Omit[]; members: Database['medreport']['Functions']['get_account_members']['Returns']; accountBenefitStatistics: AccountBenefitStatistics; + expensesOverview: TeamAccountBenefitExpensesOverview; } export default function TeamAccountStatistics({ @@ -35,6 +37,7 @@ export default function TeamAccountStatistics({ bmiThresholds, members, accountBenefitStatistics, + expensesOverview, }: TeamAccountStatisticsProps) { const currentDate = new Date(); const [date, setDate] = useState({ @@ -50,7 +53,7 @@ export default function TeamAccountStatistics({ return ( <> -
+

- +
diff --git a/app/home/[account]/_lib/server/load-team-account-benefit-statistics.ts b/app/home/[account]/_lib/server/load-team-account-benefit-statistics.ts index 4de4be5..f61f350 100644 --- a/app/home/[account]/_lib/server/load-team-account-benefit-statistics.ts +++ b/app/home/[account]/_lib/server/load-team-account-benefit-statistics.ts @@ -29,7 +29,7 @@ export const loadCompanyPersonalAccountsBalanceEntries = async ({ const { count, data: accountMemberships } = await supabase .schema('medreport') .from('accounts_memberships') - .select('user_id') + .select('user_id', { count: 'exact' }) .eq('account_id', accountId) .throwOnError(); diff --git a/app/home/[account]/page.tsx b/app/home/[account]/page.tsx index 5cff5d3..e8eb7ba 100644 --- a/app/home/[account]/page.tsx +++ b/app/home/[account]/page.tsx @@ -18,6 +18,7 @@ import { import { Dashboard } from './_components/dashboard'; import { loadAccountBenefitStatistics } from './_lib/server/load-team-account-benefit-statistics'; +import { loadTeamAccountBenefitExpensesOverview } from './_lib/server/load-team-account-benefit-expenses-overview'; interface TeamAccountHomePageProps { params: Promise<{ account: string }>; @@ -41,6 +42,10 @@ function TeamAccountHomePage({ params }: TeamAccountHomePageProps) { const { memberParams, members } = use(teamAccountsApi.getMembers(account)); const bmiThresholds = use(userAnalysesApi.fetchBmiThresholds()); const accountBenefitStatistics = use(loadAccountBenefitStatistics(teamAccount.id)); + const expensesOverview = use(loadTeamAccountBenefitExpensesOverview({ + companyId: teamAccount.id, + employeeCount: members.length, + })); use( createPageViewLog({ @@ -57,6 +62,7 @@ function TeamAccountHomePage({ params }: TeamAccountHomePageProps) { bmiThresholds={bmiThresholds} members={members} accountBenefitStatistics={accountBenefitStatistics} + expensesOverview={expensesOverview} /> ); diff --git a/public/locales/en/teams.json b/public/locales/en/teams.json index f0a728b..8af264f 100644 --- a/public/locales/en/teams.json +++ b/public/locales/en/teams.json @@ -28,7 +28,8 @@ "budget": { "title": "Company Health Account Balance", "balance": "Budget Balance {{balance}}", - "volume": "Budget Volume" + "volume": "Budget Volume", + "membersCount": "Members Count" }, "data": { "reservations": "{{value}} services", @@ -38,7 +39,8 @@ "analysisPackages": "Health Analysis Packages", "analysisPackagesCount": "{{value}} service usage", "totalSum": "Total Sum", - "eclinic": "E-Clinic" + "eclinic": "E-Clinic", + "currentMonthUsageTotal": "Current Month Usage" } }, "healthDetails": { diff --git a/public/locales/et/teams.json b/public/locales/et/teams.json index f506595..884923d 100644 --- a/public/locales/et/teams.json +++ b/public/locales/et/teams.json @@ -28,17 +28,19 @@ "budget": { "title": "Ettevõtte Tervisekassa seis", "balance": "Eelarve jääk {{balance}}", - "volume": "Eelarve maht" + "volume": "Eelarve maht", + "membersCount": "Töötajate arv" }, "data": { - "reservations": "{{value}} teenust", + "reservations": "{{value}} tellimus(t)", "analysis": "Analüüsid", "doctorsAndSpecialists": "Eriarstid ja spetsialistid", "researches": "Uuringud", "analysisPackages": "Terviseuuringute paketid", - "analysisPackagesCount": "{{value}} teenuse kasutust", + "analysisPackagesCount": "{{value}} tellimus(t)", "totalSum": "Tellitud teenuste summa", - "eclinic": "Digikliinik" + "eclinic": "Digikliinik", + "currentMonthUsageTotal": "Kasutatud eelarve" } }, "healthDetails": { diff --git a/public/locales/ru/teams.json b/public/locales/ru/teams.json index aa61b70..74111f1 100644 --- a/public/locales/ru/teams.json +++ b/public/locales/ru/teams.json @@ -28,7 +28,8 @@ "budget": { "title": "Баланс Tervisekassa компании", "balance": "Остаток бюджета {{balance}}", - "volume": "Объем бюджета" + "volume": "Объем бюджета", + "membersCount": "Количество сотрудников" }, "data": { "reservations": "{{value}} услуги", @@ -38,7 +39,8 @@ "analysisPackages": "Пакеты медицинских исследований", "analysisPackagesCount": "{{value}} использование услуг", "totalSum": "Сумма услуг", - "eclinic": "Дигиклиника" + "eclinic": "Дигиклиника", + "currentMonthUsageTotal": "Текущее использование бюджета" } }, "healthDetails": {