-
-
-
-
-
-
-
- {currentCompanyParams.benefit_amount || 0} €
-
-
-
-
-
-
-
-
-
-
-
);
};
diff --git a/app/home/[account]/billing/_components/yearly-expenses-overview.tsx b/app/home/[account]/billing/_components/yearly-expenses-overview.tsx
index 36a42be..afd3d21 100644
--- a/app/home/[account]/billing/_components/yearly-expenses-overview.tsx
+++ b/app/home/[account]/billing/_components/yearly-expenses-overview.tsx
@@ -1,50 +1,19 @@
-import { useMemo } from 'react';
-
-import { Database } from '@/packages/supabase/src/database.types';
+'use client';
import { Trans } from '@kit/ui/makerkit/trans';
import { Separator } from '@kit/ui/separator';
+import { formatCurrency } from '@/packages/shared/src/utils';
+import { useTranslation } from 'react-i18next';
+import { TeamAccountBenefitExpensesOverview } from '../../_lib/server/load-team-account-benefit-expenses-overview';
const YearlyExpensesOverview = ({
employeeCount = 0,
- companyParams,
+ expensesOverview,
}: {
employeeCount?: number;
- companyParams: Database['medreport']['Tables']['company_params']['Row'];
+ expensesOverview: TeamAccountBenefitExpensesOverview;
}) => {
- const monthlyExpensePerEmployee = useMemo(() => {
- if (!companyParams.benefit_amount) {
- return '0.00';
- }
-
- switch (companyParams.benefit_occurance) {
- case 'yearly':
- return (companyParams.benefit_amount / 12).toFixed(2);
- case 'quarterly':
- return (companyParams.benefit_amount / 3).toFixed(2);
- case 'monthly':
- return companyParams.benefit_amount.toFixed(2);
- default:
- return '0.00';
- }
- }, [companyParams]);
-
- const maxYearlyExpensePerEmployee = useMemo(() => {
- if (!companyParams.benefit_amount) {
- return '0.00';
- }
-
- switch (companyParams.benefit_occurance) {
- case 'yearly':
- return companyParams.benefit_amount.toFixed(2);
- case 'quarterly':
- return (companyParams.benefit_amount * 3).toFixed(2);
- case 'monthly':
- return (companyParams.benefit_amount * 12).toFixed(2);
- default:
- return '0.00';
- }
- }, [companyParams]);
+ const { i18n: { language } } = useTranslation();
return (
@@ -53,41 +22,56 @@ const YearlyExpensesOverview = ({
-
+
- {monthlyExpensePerEmployee} €
+ {employeeCount}
-
-
-
-
- {maxYearlyExpensePerEmployee} €
-
-
-
- {(Number(maxYearlyExpensePerEmployee) * employeeCount).toFixed(2)} €
+ {formatCurrency({
+ value: expensesOverview.managementFeeTotal,
+ locale: language,
+ currencyCode: 'EUR',
+ })}
+
+
+
+
+
+
+
+ {formatCurrency({
+ value: expensesOverview.currentMonthUsageTotal,
+ locale: language,
+ currencyCode: 'EUR',
+ })}
-
+
- {companyParams.benefit_amount
- ? companyParams.benefit_amount * employeeCount
- : 0}{' '}
- €
+ {formatCurrency({
+ value: expensesOverview.total,
+ locale: language,
+ currencyCode: 'EUR',
+ })}
diff --git a/app/home/[account]/billing/page.tsx b/app/home/[account]/billing/page.tsx
index bc8288b..ed06890 100644
--- a/app/home/[account]/billing/page.tsx
+++ b/app/home/[account]/billing/page.tsx
@@ -7,6 +7,7 @@ import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
import { withI18n } from '~/lib/i18n/with-i18n';
import HealthBenefitForm from './_components/health-benefit-form';
+import { loadTeamAccountBenefitExpensesOverview } from '../_lib/server/load-team-account-benefit-expenses-overview';
interface TeamAccountBillingPageProps {
params: Promise<{ account: string }>;
@@ -27,8 +28,14 @@ async function TeamAccountBillingPage({ params }: TeamAccountBillingPageProps) {
const api = createTeamAccountsApi(client);
const account = await api.getTeamAccount(accountSlug);
- const companyParams = await api.getTeamAccountParams(account.id);
const { members } = await api.getMembers(accountSlug);
+ const [expensesOverview, companyParams] = await Promise.all([
+ loadTeamAccountBenefitExpensesOverview({
+ companyId: account.id,
+ employeeCount: members.length,
+ }),
+ api.getTeamAccountParams(account.id),
+ ]);
return (
@@ -36,6 +43,7 @@ async function TeamAccountBillingPage({ params }: TeamAccountBillingPageProps) {
account={account}
companyParams={companyParams}
employeeCount={members.length}
+ expensesOverview={expensesOverview}
/>
);
diff --git a/app/home/[account]/members/page.tsx b/app/home/[account]/members/page.tsx
index 324e6b0..fc11cea 100644
--- a/app/home/[account]/members/page.tsx
+++ b/app/home/[account]/members/page.tsx
@@ -54,7 +54,7 @@ async function TeamAccountMembersPage({ params }: TeamAccountMembersPageProps) {
return (
<>
}
+ title={
}
description={
}
/>
diff --git a/app/home/[account]/page.tsx b/app/home/[account]/page.tsx
index 7283798..5cff5d3 100644
--- a/app/home/[account]/page.tsx
+++ b/app/home/[account]/page.tsx
@@ -17,6 +17,7 @@ import {
} from '~/lib/services/audit/pageView.service';
import { Dashboard } from './_components/dashboard';
+import { loadAccountBenefitStatistics } from './_lib/server/load-team-account-benefit-statistics';
interface TeamAccountHomePageProps {
params: Promise<{ account: string }>;
@@ -39,9 +40,7 @@ function TeamAccountHomePage({ params }: TeamAccountHomePageProps) {
const teamAccount = use(teamAccountsApi.getTeamAccount(account));
const { memberParams, members } = use(teamAccountsApi.getMembers(account));
const bmiThresholds = use(userAnalysesApi.fetchBmiThresholds());
- const companyParams = use(
- teamAccountsApi.getTeamAccountParams(teamAccount.id),
- );
+ const accountBenefitStatistics = use(loadAccountBenefitStatistics(teamAccount.id));
use(
createPageViewLog({
@@ -57,7 +56,7 @@ function TeamAccountHomePage({ params }: TeamAccountHomePageProps) {
memberParams={memberParams}
bmiThresholds={bmiThresholds}
members={members}
- companyParams={companyParams}
+ accountBenefitStatistics={accountBenefitStatistics}
/>
);
diff --git a/lib/types/account-balance-entry.ts b/lib/types/account-balance-entry.ts
deleted file mode 100644
index 434e5e6..0000000
--- a/lib/types/account-balance-entry.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-import type { Database } from "@/packages/supabase/src/database.types";
-
-export type AccountBalanceEntry = Database['medreport']['Tables']['account_balance_entries']['Row'];
diff --git a/lib/utils.ts b/lib/utils.ts
index d9d0f96..7d2f9ad 100644
--- a/lib/utils.ts
+++ b/lib/utils.ts
@@ -1,9 +1,9 @@
-import { Database } from '@/packages/supabase/src/database.types';
import { type ClassValue, clsx } from 'clsx';
import Isikukood, { Gender } from 'isikukood';
import { twMerge } from 'tailwind-merge';
import { BmiCategory } from './types/bmi';
+import type { BmiThresholds } from '@kit/accounts/types/accounts';
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
@@ -45,10 +45,7 @@ export const bmiFromMetric = (kg: number, cm: number) => {
};
export function getBmiStatus(
- thresholds: Omit<
- Database['medreport']['Tables']['bmi_thresholds']['Row'],
- 'id'
- >[],
+ thresholds: Omit
[],
params: { age: number; height: number; weight: number },
): BmiCategory | null {
const age = params.age;
diff --git a/packages/features/accounts/src/types/accounts.ts b/packages/features/accounts/src/types/accounts.ts
index bc305c0..430c898 100644
--- a/packages/features/accounts/src/types/accounts.ts
+++ b/packages/features/accounts/src/types/accounts.ts
@@ -1,23 +1,25 @@
import { Database } from '@kit/supabase/database';
-export type ApplicationRole =
- Database['medreport']['Tables']['accounts']['Row']['application_role'];
+export type ApplicationRole = Account['application_role'];
export enum ApplicationRoleEnum {
User = 'user',
Doctor = 'doctor',
SuperAdmin = 'super_admin',
}
-export type AccountWithParams =
- Database['medreport']['Tables']['accounts']['Row'] & {
- accountParams:
- | (Pick<
- Database['medreport']['Tables']['account_params']['Row'],
- 'weight' | 'height'
- > & {
- isSmoker:
- | Database['medreport']['Tables']['account_params']['Row']['is_smoker']
- | null;
- })
- | null;
- };
+export type AccountParams =
+ Database['medreport']['Tables']['account_params']['Row'];
+
+export type Account = Database['medreport']['Tables']['accounts']['Row'];
+export type AccountWithParams = Account & {
+ accountParams:
+ | (Pick & {
+ isSmoker: AccountParams['is_smoker'] | null;
+ })
+ | null;
+};
+
+export type CompanyParams =
+ Database['medreport']['Tables']['company_params']['Row'];
+
+export type BmiThresholds = Database['medreport']['Tables']['bmi_thresholds']['Row'];
diff --git a/packages/features/admin/package.json b/packages/features/admin/package.json
index 72da143..d07673d 100644
--- a/packages/features/admin/package.json
+++ b/packages/features/admin/package.json
@@ -9,6 +9,7 @@
"devDependencies": {
"@hookform/resolvers": "^5.0.1",
"@kit/next": "workspace:*",
+ "@kit/accounts": "workspace:*",
"@kit/shared": "workspace:*",
"@kit/supabase": "workspace:*",
"@kit/tsconfig": "workspace:*",
diff --git a/packages/features/admin/src/components/admin-accounts-table.tsx b/packages/features/admin/src/components/admin-accounts-table.tsx
index ab7f0c1..d993ab7 100644
--- a/packages/features/admin/src/components/admin-accounts-table.tsx
+++ b/packages/features/admin/src/components/admin-accounts-table.tsx
@@ -11,7 +11,7 @@ import { EllipsisVertical } from 'lucide-react';
import { useForm } from 'react-hook-form';
import { z } from 'zod';
-import { Database } from '@kit/supabase/database';
+import type { Account } from '@kit/accounts/types/accounts';
import { Button } from '@kit/ui/button';
import { Checkbox } from '@kit/ui/checkbox';
import {
@@ -44,8 +44,6 @@ import { AdminDeleteUserDialog } from './admin-delete-user-dialog';
import { AdminImpersonateUserDialog } from './admin-impersonate-user-dialog';
import { AdminResetPasswordDialog } from './admin-reset-password-dialog';
-type Account = Database['medreport']['Tables']['accounts']['Row'];
-
const FiltersSchema = z.object({
type: z.enum(['all', 'team', 'personal']),
query: z.string().optional(),
diff --git a/packages/features/admin/src/lib/server/schema/admin-actions.schema.ts b/packages/features/admin/src/lib/server/schema/admin-actions.schema.ts
index 8edd356..aa5d86d 100644
--- a/packages/features/admin/src/lib/server/schema/admin-actions.schema.ts
+++ b/packages/features/admin/src/lib/server/schema/admin-actions.schema.ts
@@ -1,6 +1,6 @@
import { z } from 'zod';
-import { Database } from '@kit/supabase/database';
+import { ApplicationRole } from '@kit/accounts/types/accounts';
const ConfirmationSchema = z.object({
confirmation: z.custom((value) => value === 'CONFIRM'),
@@ -19,9 +19,7 @@ export const DeleteAccountSchema = ConfirmationSchema.extend({
accountId: z.string().uuid(),
});
-type ApplicationRoleType =
- Database['medreport']['Tables']['accounts']['Row']['application_role'];
export const UpdateAccountRoleSchema = z.object({
accountId: z.string().uuid(),
- role: z.string() as z.ZodType,
+ role: z.string() as z.ZodType,
});
diff --git a/packages/features/admin/src/lib/server/services/admin-accounts.service.ts b/packages/features/admin/src/lib/server/services/admin-accounts.service.ts
index c46bc03..6f26b58 100644
--- a/packages/features/admin/src/lib/server/services/admin-accounts.service.ts
+++ b/packages/features/admin/src/lib/server/services/admin-accounts.service.ts
@@ -3,6 +3,7 @@ import 'server-only';
import { SupabaseClient } from '@supabase/supabase-js';
import { Database } from '@kit/supabase/database';
+import type { ApplicationRole } from '@kit/accounts/types/accounts';
export function createAdminAccountsService(client: SupabaseClient) {
return new AdminAccountsService(client);
@@ -25,7 +26,7 @@ class AdminAccountsService {
async updateRole(
accountId: string,
- role: Database['medreport']['Tables']['accounts']['Row']['application_role'],
+ role: ApplicationRole,
) {
const { error } = await this.adminClient
.schema('medreport')
diff --git a/packages/features/team-accounts/src/server/services/webhooks/account-webhooks.service.ts b/packages/features/team-accounts/src/server/services/webhooks/account-webhooks.service.ts
index 9bdc5a3..d1d6aa4 100644
--- a/packages/features/team-accounts/src/server/services/webhooks/account-webhooks.service.ts
+++ b/packages/features/team-accounts/src/server/services/webhooks/account-webhooks.service.ts
@@ -1,9 +1,7 @@
import { z } from 'zod';
import { getLogger } from '@kit/shared/logger';
-import { Database } from '@kit/supabase/database';
-
-type Account = Database['medreport']['Tables']['accounts']['Row'];
+import type { Account } from '@kit/accounts/types/accounts';
export function createAccountWebhooksService() {
return new AccountWebhooksService();
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 2c396f6..b000d26 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -647,6 +647,9 @@ importers:
'@hookform/resolvers':
specifier: ^5.0.1
version: 5.2.1(react-hook-form@7.62.0(react@19.1.0))
+ '@kit/accounts':
+ specifier: workspace:*
+ version: link:../accounts
'@kit/next':
specifier: workspace:*
version: link:../../next