Merge pull request #54 from MR-medreport/MED-57
MED-57: Team account dashboard
This commit is contained in:
@@ -1,896 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import { useMemo, useState } from 'react';
|
||||
|
||||
import { ArrowDown, ArrowUp, Menu, TrendingUp } from 'lucide-react';
|
||||
import {
|
||||
Area,
|
||||
AreaChart,
|
||||
Bar,
|
||||
BarChart,
|
||||
CartesianGrid,
|
||||
Line,
|
||||
LineChart,
|
||||
XAxis,
|
||||
} from 'recharts';
|
||||
|
||||
import { Badge } from '@kit/ui/badge';
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardDescription,
|
||||
CardFooter,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from '@kit/ui/card';
|
||||
import {
|
||||
ChartConfig,
|
||||
ChartContainer,
|
||||
ChartTooltip,
|
||||
ChartTooltipContent,
|
||||
} from '@kit/ui/chart';
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from '@kit/ui/table';
|
||||
|
||||
export default function DashboardDemo() {
|
||||
const mrr = useMemo(() => generateDemoData(), []);
|
||||
const netRevenue = useMemo(() => generateDemoData(), []);
|
||||
const fees = useMemo(() => generateDemoData(), []);
|
||||
const newCustomers = useMemo(() => generateDemoData(), []);
|
||||
|
||||
return (
|
||||
<div
|
||||
className={
|
||||
'animate-in fade-in flex flex-col space-y-4 pb-36 duration-500'
|
||||
}
|
||||
>
|
||||
<div
|
||||
className={
|
||||
'grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4'
|
||||
}
|
||||
>
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className={'flex items-center gap-2.5'}>
|
||||
<span>MRR</span>
|
||||
<Trend trend={'up'}>20%</Trend>
|
||||
</CardTitle>
|
||||
|
||||
<CardDescription>
|
||||
<span>Monthly recurring revenue</span>
|
||||
</CardDescription>
|
||||
|
||||
<div>
|
||||
<Figure>{`$${mrr[1]}`}</Figure>
|
||||
</div>
|
||||
</CardHeader>
|
||||
|
||||
<CardContent className={'space-y-4'}>
|
||||
<Chart data={mrr[0]} />
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className={'flex items-center gap-2.5'}>
|
||||
<span>Revenue</span>
|
||||
<Trend trend={'up'}>12%</Trend>
|
||||
</CardTitle>
|
||||
|
||||
<CardDescription>
|
||||
<span>Total revenue including fees</span>
|
||||
</CardDescription>
|
||||
|
||||
<div>
|
||||
<Figure>{`$${netRevenue[1]}`}</Figure>
|
||||
</div>
|
||||
</CardHeader>
|
||||
|
||||
<CardContent>
|
||||
<Chart data={netRevenue[0]} />
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className={'flex items-center gap-2.5'}>
|
||||
<span>Fees</span>
|
||||
<Trend trend={'up'}>9%</Trend>
|
||||
</CardTitle>
|
||||
|
||||
<CardDescription>
|
||||
<span>Total fees collected</span>
|
||||
</CardDescription>
|
||||
|
||||
<div>
|
||||
<Figure>{`$${fees[1]}`}</Figure>
|
||||
</div>
|
||||
</CardHeader>
|
||||
|
||||
<CardContent>
|
||||
<Chart data={fees[0]} />
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className={'flex items-center gap-2.5'}>
|
||||
<span>New Customers</span>
|
||||
<Trend trend={'down'}>-25%</Trend>
|
||||
</CardTitle>
|
||||
|
||||
<CardDescription>
|
||||
<span>Customers who signed up this month</span>
|
||||
</CardDescription>
|
||||
|
||||
<div>
|
||||
<Figure>{`${Number(newCustomers[1]).toFixed(0)}`}</Figure>
|
||||
</div>
|
||||
</CardHeader>
|
||||
|
||||
<CardContent>
|
||||
<Chart data={newCustomers[0]} />
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
<VisitorsChart />
|
||||
|
||||
<PageViewsChart />
|
||||
|
||||
<div>
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Best Customers</CardTitle>
|
||||
<CardDescription>Showing the top customers by MRR</CardDescription>
|
||||
</CardHeader>
|
||||
|
||||
<CardContent>
|
||||
<CustomersTable />
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function generateDemoData() {
|
||||
const today = new Date();
|
||||
const formatter = new Intl.DateTimeFormat('en-us', {
|
||||
month: 'long',
|
||||
year: '2-digit',
|
||||
});
|
||||
|
||||
const data: { value: string; name: string }[] = [];
|
||||
|
||||
for (let n = 8; n > 0; n -= 1) {
|
||||
const date = new Date(today.getFullYear(), today.getMonth() - n, 1);
|
||||
|
||||
data.push({
|
||||
name: formatter.format(date),
|
||||
value: (Math.random() * 10).toFixed(1),
|
||||
});
|
||||
}
|
||||
|
||||
const lastValue = data[data.length - 1]?.value;
|
||||
|
||||
return [data, lastValue] as [typeof data, string];
|
||||
}
|
||||
|
||||
function Chart(
|
||||
props: React.PropsWithChildren<{ data: { value: string; name: string }[] }>,
|
||||
) {
|
||||
const chartConfig = {
|
||||
desktop: {
|
||||
label: 'Desktop',
|
||||
color: 'var(--chart-1)',
|
||||
},
|
||||
mobile: {
|
||||
label: 'Mobile',
|
||||
color: 'var(--chart-2)',
|
||||
},
|
||||
} satisfies ChartConfig;
|
||||
|
||||
return (
|
||||
<ChartContainer config={chartConfig}>
|
||||
<LineChart accessibilityLayer data={props.data}>
|
||||
<CartesianGrid vertical={false} />
|
||||
<XAxis
|
||||
dataKey="name"
|
||||
tickLine={false}
|
||||
axisLine={false}
|
||||
tickMargin={8}
|
||||
/>
|
||||
<ChartTooltip
|
||||
cursor={false}
|
||||
content={<ChartTooltipContent hideLabel />}
|
||||
/>
|
||||
<Line
|
||||
dataKey="value"
|
||||
type="natural"
|
||||
stroke="var(--color-desktop)"
|
||||
strokeWidth={2}
|
||||
dot={false}
|
||||
/>
|
||||
</LineChart>
|
||||
</ChartContainer>
|
||||
);
|
||||
}
|
||||
|
||||
function CustomersTable() {
|
||||
const customers = [
|
||||
{
|
||||
name: 'John Doe',
|
||||
email: 'john@makerkit.dev',
|
||||
plan: 'Pro',
|
||||
mrr: '$120.5',
|
||||
logins: 1020,
|
||||
status: 'Healthy',
|
||||
trend: 'up',
|
||||
},
|
||||
{
|
||||
name: 'Emma Smith',
|
||||
email: 'emma@makerit.dev',
|
||||
plan: 'Basic',
|
||||
mrr: '$65.4',
|
||||
logins: 570,
|
||||
status: 'Possible Churn',
|
||||
trend: 'stale',
|
||||
},
|
||||
{
|
||||
name: 'Robert Johnson',
|
||||
email: 'robert@makerkit.dev',
|
||||
plan: 'Pro',
|
||||
mrr: '$500.1',
|
||||
logins: 2050,
|
||||
status: 'Healthy',
|
||||
trend: 'up',
|
||||
},
|
||||
{
|
||||
name: 'Olivia Brown',
|
||||
email: 'olivia@makerkit.dev',
|
||||
plan: 'Basic',
|
||||
mrr: '$10',
|
||||
logins: 50,
|
||||
status: 'Churn',
|
||||
trend: 'down',
|
||||
},
|
||||
{
|
||||
name: 'Michael Davis',
|
||||
email: 'michael@makerkit.dev',
|
||||
plan: 'Pro',
|
||||
mrr: '$300.2',
|
||||
logins: 1520,
|
||||
status: 'Healthy',
|
||||
trend: 'up',
|
||||
},
|
||||
{
|
||||
name: 'Emily Jones',
|
||||
email: 'emily@makerkit.dev',
|
||||
plan: 'Pro',
|
||||
mrr: '$75.7',
|
||||
logins: 780,
|
||||
status: 'Healthy',
|
||||
trend: 'up',
|
||||
},
|
||||
{
|
||||
name: 'Daniel Garcia',
|
||||
email: 'daniel@makerkit.dev',
|
||||
plan: 'Basic',
|
||||
mrr: '$50',
|
||||
logins: 320,
|
||||
status: 'Possible Churn',
|
||||
trend: 'stale',
|
||||
},
|
||||
{
|
||||
name: 'Liam Miller',
|
||||
email: 'liam@makerkit.dev',
|
||||
plan: 'Pro',
|
||||
mrr: '$90.8',
|
||||
logins: 1260,
|
||||
status: 'Healthy',
|
||||
trend: 'up',
|
||||
},
|
||||
{
|
||||
name: 'Emma Clark',
|
||||
email: 'emma@makerkit.dev',
|
||||
plan: 'Basic',
|
||||
mrr: '$0',
|
||||
logins: 20,
|
||||
status: 'Churn',
|
||||
trend: 'down',
|
||||
},
|
||||
{
|
||||
name: 'Elizabeth Rodriguez',
|
||||
email: 'liz@makerkit.dev',
|
||||
plan: 'Pro',
|
||||
mrr: '$145.3',
|
||||
logins: 1380,
|
||||
status: 'Healthy',
|
||||
trend: 'up',
|
||||
},
|
||||
{
|
||||
name: 'James Martinez',
|
||||
email: 'james@makerkit.dev',
|
||||
plan: 'Pro',
|
||||
mrr: '$120.5',
|
||||
logins: 940,
|
||||
status: 'Healthy',
|
||||
trend: 'up',
|
||||
},
|
||||
{
|
||||
name: 'Charlotte Ryan',
|
||||
email: 'carlotte@makerkit.dev',
|
||||
plan: 'Basic',
|
||||
mrr: '$80.6',
|
||||
logins: 460,
|
||||
status: 'Possible Churn',
|
||||
trend: 'stale',
|
||||
},
|
||||
{
|
||||
name: 'Lucas Evans',
|
||||
email: 'lucas@makerkit.dev',
|
||||
plan: 'Pro',
|
||||
mrr: '$210.3',
|
||||
logins: 1850,
|
||||
status: 'Healthy',
|
||||
trend: 'up',
|
||||
},
|
||||
{
|
||||
name: 'Sophia Wilson',
|
||||
email: 'sophia@makerkit.dev',
|
||||
plan: 'Basic',
|
||||
mrr: '$10',
|
||||
logins: 35,
|
||||
status: 'Churn',
|
||||
trend: 'down',
|
||||
},
|
||||
{
|
||||
name: 'William Kelly',
|
||||
email: 'will@makerkit.dev',
|
||||
plan: 'Pro',
|
||||
mrr: '$350.2',
|
||||
logins: 1760,
|
||||
status: 'Healthy',
|
||||
trend: 'up',
|
||||
},
|
||||
{
|
||||
name: 'Oliver Thomas',
|
||||
email: 'olly@makerkit.dev',
|
||||
plan: 'Pro',
|
||||
mrr: '$145.6',
|
||||
logins: 1350,
|
||||
status: 'Healthy',
|
||||
trend: 'up',
|
||||
},
|
||||
{
|
||||
name: 'Samantha White',
|
||||
email: 'sam@makerkit.dev',
|
||||
plan: 'Basic',
|
||||
mrr: '$60.3',
|
||||
logins: 425,
|
||||
status: 'Possible Churn',
|
||||
trend: 'stale',
|
||||
},
|
||||
{
|
||||
name: 'Benjamin Lewis',
|
||||
email: 'ben@makerkit.dev',
|
||||
plan: 'Pro',
|
||||
mrr: '$175.8',
|
||||
logins: 1600,
|
||||
status: 'Healthy',
|
||||
trend: 'up',
|
||||
},
|
||||
{
|
||||
name: 'Zoe Harris',
|
||||
email: 'zoe@makerkit.dev',
|
||||
plan: 'Basic',
|
||||
mrr: '$0',
|
||||
logins: 18,
|
||||
status: 'Churn',
|
||||
trend: 'down',
|
||||
},
|
||||
{
|
||||
name: 'Zachary Nelson',
|
||||
email: 'zac@makerkit.dev',
|
||||
plan: 'Pro',
|
||||
mrr: '$255.9',
|
||||
logins: 1785,
|
||||
status: 'Healthy',
|
||||
trend: 'up',
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Customer</TableHead>
|
||||
<TableHead>Plan</TableHead>
|
||||
<TableHead>MRR</TableHead>
|
||||
<TableHead>Logins</TableHead>
|
||||
<TableHead>Status</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{customers.map((customer) => (
|
||||
<TableRow key={customer.name}>
|
||||
<TableCell className={'flex flex-col'}>
|
||||
<span>{customer.name}</span>
|
||||
<span className={'text-muted-foreground text-sm'}>
|
||||
{customer.email}
|
||||
</span>
|
||||
</TableCell>
|
||||
<TableCell>{customer.plan}</TableCell>
|
||||
<TableCell>{customer.mrr}</TableCell>
|
||||
<TableCell>{customer.logins}</TableCell>
|
||||
<TableCell>
|
||||
<BadgeWithTrend trend={customer.trend}>
|
||||
{customer.status}
|
||||
</BadgeWithTrend>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
);
|
||||
}
|
||||
|
||||
function BadgeWithTrend(props: React.PropsWithChildren<{ trend: string }>) {
|
||||
const className = useMemo(() => {
|
||||
switch (props.trend) {
|
||||
case 'up':
|
||||
return 'text-green-500';
|
||||
case 'down':
|
||||
return 'text-destructive';
|
||||
case 'stale':
|
||||
return 'text-orange-500';
|
||||
}
|
||||
}, [props.trend]);
|
||||
|
||||
return (
|
||||
<Badge
|
||||
variant={'outline'}
|
||||
className={'border-transparent px-1.5 font-normal'}
|
||||
>
|
||||
<span className={className}>{props.children}</span>
|
||||
</Badge>
|
||||
);
|
||||
}
|
||||
|
||||
function Figure(props: React.PropsWithChildren) {
|
||||
return (
|
||||
<div className={'font-heading text-2xl font-semibold'}>
|
||||
{props.children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Trend(
|
||||
props: React.PropsWithChildren<{
|
||||
trend: 'up' | 'down' | 'stale';
|
||||
}>,
|
||||
) {
|
||||
const Icon = useMemo(() => {
|
||||
switch (props.trend) {
|
||||
case 'up':
|
||||
return <ArrowUp className={'h-3 w-3 text-green-500'} />;
|
||||
case 'down':
|
||||
return <ArrowDown className={'text-destructive h-3 w-3'} />;
|
||||
case 'stale':
|
||||
return <Menu className={'h-3 w-3 text-orange-500'} />;
|
||||
}
|
||||
}, [props.trend]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<BadgeWithTrend trend={props.trend}>
|
||||
<span className={'flex items-center space-x-1'}>
|
||||
{Icon}
|
||||
<span>{props.children}</span>
|
||||
</span>
|
||||
</BadgeWithTrend>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function VisitorsChart() {
|
||||
const chartData = useMemo(
|
||||
() => [
|
||||
{ date: '2024-04-01', desktop: 222, mobile: 150 },
|
||||
{ date: '2024-04-02', desktop: 97, mobile: 180 },
|
||||
{ date: '2024-04-03', desktop: 167, mobile: 120 },
|
||||
{ date: '2024-04-04', desktop: 242, mobile: 260 },
|
||||
{ date: '2024-04-05', desktop: 373, mobile: 290 },
|
||||
{ date: '2024-04-06', desktop: 301, mobile: 340 },
|
||||
{ date: '2024-04-07', desktop: 245, mobile: 180 },
|
||||
{ date: '2024-04-08', desktop: 409, mobile: 320 },
|
||||
{ date: '2024-04-09', desktop: 59, mobile: 110 },
|
||||
{ date: '2024-04-10', desktop: 261, mobile: 190 },
|
||||
{ date: '2024-04-11', desktop: 327, mobile: 350 },
|
||||
{ date: '2024-04-12', desktop: 292, mobile: 210 },
|
||||
{ date: '2024-04-13', desktop: 342, mobile: 380 },
|
||||
{ date: '2024-04-14', desktop: 137, mobile: 220 },
|
||||
{ date: '2024-04-15', desktop: 120, mobile: 170 },
|
||||
{ date: '2024-04-16', desktop: 138, mobile: 190 },
|
||||
{ date: '2024-04-17', desktop: 446, mobile: 360 },
|
||||
{ date: '2024-04-18', desktop: 364, mobile: 410 },
|
||||
{ date: '2024-04-19', desktop: 243, mobile: 180 },
|
||||
{ date: '2024-04-20', desktop: 89, mobile: 150 },
|
||||
{ date: '2024-04-21', desktop: 137, mobile: 200 },
|
||||
{ date: '2024-04-22', desktop: 224, mobile: 170 },
|
||||
{ date: '2024-04-23', desktop: 138, mobile: 230 },
|
||||
{ date: '2024-04-24', desktop: 387, mobile: 290 },
|
||||
{ date: '2024-04-25', desktop: 215, mobile: 250 },
|
||||
{ date: '2024-04-26', desktop: 75, mobile: 130 },
|
||||
{ date: '2024-04-27', desktop: 383, mobile: 420 },
|
||||
{ date: '2024-04-28', desktop: 122, mobile: 180 },
|
||||
{ date: '2024-04-29', desktop: 315, mobile: 240 },
|
||||
{ date: '2024-04-30', desktop: 454, mobile: 380 },
|
||||
{ date: '2024-05-01', desktop: 165, mobile: 220 },
|
||||
{ date: '2024-05-02', desktop: 293, mobile: 310 },
|
||||
{ date: '2024-05-03', desktop: 247, mobile: 190 },
|
||||
{ date: '2024-05-04', desktop: 385, mobile: 420 },
|
||||
{ date: '2024-05-05', desktop: 481, mobile: 390 },
|
||||
{ date: '2024-05-06', desktop: 498, mobile: 520 },
|
||||
{ date: '2024-05-07', desktop: 388, mobile: 300 },
|
||||
{ date: '2024-05-08', desktop: 149, mobile: 210 },
|
||||
{ date: '2024-05-09', desktop: 227, mobile: 180 },
|
||||
{ date: '2024-05-10', desktop: 293, mobile: 330 },
|
||||
{ date: '2024-05-11', desktop: 335, mobile: 270 },
|
||||
{ date: '2024-05-12', desktop: 197, mobile: 240 },
|
||||
{ date: '2024-05-13', desktop: 197, mobile: 160 },
|
||||
{ date: '2024-05-14', desktop: 448, mobile: 490 },
|
||||
{ date: '2024-05-15', desktop: 473, mobile: 380 },
|
||||
{ date: '2024-05-16', desktop: 338, mobile: 400 },
|
||||
{ date: '2024-05-17', desktop: 499, mobile: 420 },
|
||||
{ date: '2024-05-18', desktop: 315, mobile: 350 },
|
||||
{ date: '2024-05-19', desktop: 235, mobile: 180 },
|
||||
{ date: '2024-05-20', desktop: 177, mobile: 230 },
|
||||
{ date: '2024-05-21', desktop: 82, mobile: 140 },
|
||||
{ date: '2024-05-22', desktop: 81, mobile: 120 },
|
||||
{ date: '2024-05-23', desktop: 252, mobile: 290 },
|
||||
{ date: '2024-05-24', desktop: 294, mobile: 220 },
|
||||
{ date: '2024-05-25', desktop: 201, mobile: 250 },
|
||||
{ date: '2024-05-26', desktop: 213, mobile: 170 },
|
||||
{ date: '2024-05-27', desktop: 420, mobile: 460 },
|
||||
{ date: '2024-05-28', desktop: 233, mobile: 190 },
|
||||
{ date: '2024-05-29', desktop: 78, mobile: 130 },
|
||||
{ date: '2024-05-30', desktop: 340, mobile: 280 },
|
||||
{ date: '2024-05-31', desktop: 178, mobile: 230 },
|
||||
{ date: '2024-06-01', desktop: 178, mobile: 200 },
|
||||
{ date: '2024-06-02', desktop: 470, mobile: 410 },
|
||||
{ date: '2024-06-03', desktop: 103, mobile: 160 },
|
||||
{ date: '2024-06-04', desktop: 439, mobile: 380 },
|
||||
{ date: '2024-06-05', desktop: 88, mobile: 140 },
|
||||
{ date: '2024-06-06', desktop: 294, mobile: 250 },
|
||||
{ date: '2024-06-07', desktop: 323, mobile: 370 },
|
||||
{ date: '2024-06-08', desktop: 385, mobile: 320 },
|
||||
{ date: '2024-06-09', desktop: 438, mobile: 480 },
|
||||
{ date: '2024-06-10', desktop: 155, mobile: 200 },
|
||||
{ date: '2024-06-11', desktop: 92, mobile: 150 },
|
||||
{ date: '2024-06-12', desktop: 492, mobile: 420 },
|
||||
{ date: '2024-06-13', desktop: 81, mobile: 130 },
|
||||
{ date: '2024-06-14', desktop: 426, mobile: 380 },
|
||||
{ date: '2024-06-15', desktop: 307, mobile: 350 },
|
||||
{ date: '2024-06-16', desktop: 371, mobile: 310 },
|
||||
{ date: '2024-06-17', desktop: 475, mobile: 520 },
|
||||
{ date: '2024-06-18', desktop: 107, mobile: 170 },
|
||||
{ date: '2024-06-19', desktop: 341, mobile: 290 },
|
||||
{ date: '2024-06-20', desktop: 408, mobile: 450 },
|
||||
{ date: '2024-06-21', desktop: 169, mobile: 210 },
|
||||
{ date: '2024-06-22', desktop: 317, mobile: 270 },
|
||||
{ date: '2024-06-23', desktop: 480, mobile: 530 },
|
||||
{ date: '2024-06-24', desktop: 132, mobile: 180 },
|
||||
{ date: '2024-06-25', desktop: 141, mobile: 190 },
|
||||
{ date: '2024-06-26', desktop: 434, mobile: 380 },
|
||||
{ date: '2024-06-27', desktop: 448, mobile: 490 },
|
||||
{ date: '2024-06-28', desktop: 149, mobile: 200 },
|
||||
{ date: '2024-06-29', desktop: 103, mobile: 160 },
|
||||
{ date: '2024-06-30', desktop: 446, mobile: 400 },
|
||||
],
|
||||
[],
|
||||
);
|
||||
|
||||
const chartConfig = {
|
||||
visitors: {
|
||||
label: 'Visitors',
|
||||
},
|
||||
desktop: {
|
||||
label: 'Desktop',
|
||||
color: 'var(--chart-1)',
|
||||
},
|
||||
mobile: {
|
||||
label: 'Mobile',
|
||||
color: 'var(--chart-2)',
|
||||
},
|
||||
} satisfies ChartConfig;
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Visitors</CardTitle>
|
||||
<CardDescription>
|
||||
Showing total visitors for the last 6 months
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
|
||||
<CardContent>
|
||||
<ChartContainer className={'h-64 w-full'} config={chartConfig}>
|
||||
<AreaChart accessibilityLayer data={chartData}>
|
||||
<defs>
|
||||
<linearGradient id="fillDesktop" x1="0" y1="0" x2="0" y2="1">
|
||||
<stop
|
||||
offset="5%"
|
||||
stopColor="var(--color-desktop)"
|
||||
stopOpacity={0.8}
|
||||
/>
|
||||
<stop
|
||||
offset="95%"
|
||||
stopColor="var(--color-desktop)"
|
||||
stopOpacity={0.1}
|
||||
/>
|
||||
</linearGradient>
|
||||
<linearGradient id="fillMobile" x1="0" y1="0" x2="0" y2="1">
|
||||
<stop
|
||||
offset="5%"
|
||||
stopColor="var(--color-mobile)"
|
||||
stopOpacity={0.8}
|
||||
/>
|
||||
<stop
|
||||
offset="95%"
|
||||
stopColor="var(--color-mobile)"
|
||||
stopOpacity={0.1}
|
||||
/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<CartesianGrid vertical={false} />
|
||||
<XAxis
|
||||
dataKey="month"
|
||||
tickLine={false}
|
||||
axisLine={false}
|
||||
tickMargin={8}
|
||||
tickFormatter={(value: string) => value.slice(0, 3)}
|
||||
/>
|
||||
<ChartTooltip
|
||||
cursor={false}
|
||||
content={<ChartTooltipContent indicator="dot" />}
|
||||
/>
|
||||
<Area
|
||||
dataKey="mobile"
|
||||
type="natural"
|
||||
fill="url(#fillMobile)"
|
||||
fillOpacity={0.4}
|
||||
stroke="var(--color-mobile)"
|
||||
stackId="a"
|
||||
/>
|
||||
<Area
|
||||
dataKey="desktop"
|
||||
type="natural"
|
||||
fill="url(#fillDesktop)"
|
||||
fillOpacity={0.4}
|
||||
stroke="var(--color-desktop)"
|
||||
stackId="a"
|
||||
/>
|
||||
</AreaChart>
|
||||
</ChartContainer>
|
||||
</CardContent>
|
||||
|
||||
<CardFooter>
|
||||
<div className="flex w-full items-start gap-2 text-sm">
|
||||
<div className="grid gap-2">
|
||||
<div className="flex items-center gap-2 leading-none font-medium">
|
||||
Trending up by 5.2% this month <TrendingUp className="h-4 w-4" />
|
||||
</div>
|
||||
<div className="text-muted-foreground flex items-center gap-2 leading-none">
|
||||
January - June 2024
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</CardFooter>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
export function PageViewsChart() {
|
||||
const [activeChart, setActiveChart] =
|
||||
useState<keyof typeof chartConfig>('desktop');
|
||||
|
||||
const chartData = [
|
||||
{ date: '2024-04-01', desktop: 222, mobile: 150 },
|
||||
{ date: '2024-04-02', desktop: 97, mobile: 180 },
|
||||
{ date: '2024-04-03', desktop: 167, mobile: 120 },
|
||||
{ date: '2024-04-04', desktop: 242, mobile: 260 },
|
||||
{ date: '2024-04-05', desktop: 373, mobile: 290 },
|
||||
{ date: '2024-04-06', desktop: 301, mobile: 340 },
|
||||
{ date: '2024-04-07', desktop: 245, mobile: 180 },
|
||||
{ date: '2024-04-08', desktop: 409, mobile: 320 },
|
||||
{ date: '2024-04-09', desktop: 59, mobile: 110 },
|
||||
{ date: '2024-04-10', desktop: 261, mobile: 190 },
|
||||
{ date: '2024-04-11', desktop: 327, mobile: 350 },
|
||||
{ date: '2024-04-12', desktop: 292, mobile: 210 },
|
||||
{ date: '2024-04-13', desktop: 342, mobile: 380 },
|
||||
{ date: '2024-04-14', desktop: 137, mobile: 220 },
|
||||
{ date: '2024-04-15', desktop: 120, mobile: 170 },
|
||||
{ date: '2024-04-16', desktop: 138, mobile: 190 },
|
||||
{ date: '2024-04-17', desktop: 446, mobile: 360 },
|
||||
{ date: '2024-04-18', desktop: 364, mobile: 410 },
|
||||
{ date: '2024-04-19', desktop: 243, mobile: 180 },
|
||||
{ date: '2024-04-20', desktop: 89, mobile: 150 },
|
||||
{ date: '2024-04-21', desktop: 137, mobile: 200 },
|
||||
{ date: '2024-04-22', desktop: 224, mobile: 170 },
|
||||
{ date: '2024-04-23', desktop: 138, mobile: 230 },
|
||||
{ date: '2024-04-24', desktop: 387, mobile: 290 },
|
||||
{ date: '2024-04-25', desktop: 215, mobile: 250 },
|
||||
{ date: '2024-04-26', desktop: 75, mobile: 130 },
|
||||
{ date: '2024-04-27', desktop: 383, mobile: 420 },
|
||||
{ date: '2024-04-28', desktop: 122, mobile: 180 },
|
||||
{ date: '2024-04-29', desktop: 315, mobile: 240 },
|
||||
{ date: '2024-04-30', desktop: 454, mobile: 380 },
|
||||
{ date: '2024-05-01', desktop: 165, mobile: 220 },
|
||||
{ date: '2024-05-02', desktop: 293, mobile: 310 },
|
||||
{ date: '2024-05-03', desktop: 247, mobile: 190 },
|
||||
{ date: '2024-05-04', desktop: 385, mobile: 420 },
|
||||
{ date: '2024-05-05', desktop: 481, mobile: 390 },
|
||||
{ date: '2024-05-06', desktop: 498, mobile: 520 },
|
||||
{ date: '2024-05-07', desktop: 388, mobile: 300 },
|
||||
{ date: '2024-05-08', desktop: 149, mobile: 210 },
|
||||
{ date: '2024-05-09', desktop: 227, mobile: 180 },
|
||||
{ date: '2024-05-10', desktop: 293, mobile: 330 },
|
||||
{ date: '2024-05-11', desktop: 335, mobile: 270 },
|
||||
{ date: '2024-05-12', desktop: 197, mobile: 240 },
|
||||
{ date: '2024-05-13', desktop: 197, mobile: 160 },
|
||||
{ date: '2024-05-14', desktop: 448, mobile: 490 },
|
||||
{ date: '2024-05-15', desktop: 473, mobile: 380 },
|
||||
{ date: '2024-05-16', desktop: 338, mobile: 400 },
|
||||
{ date: '2024-05-17', desktop: 499, mobile: 420 },
|
||||
{ date: '2024-05-18', desktop: 315, mobile: 350 },
|
||||
{ date: '2024-05-19', desktop: 235, mobile: 180 },
|
||||
{ date: '2024-05-20', desktop: 177, mobile: 230 },
|
||||
{ date: '2024-05-21', desktop: 82, mobile: 140 },
|
||||
{ date: '2024-05-22', desktop: 81, mobile: 120 },
|
||||
{ date: '2024-05-23', desktop: 252, mobile: 290 },
|
||||
{ date: '2024-05-24', desktop: 294, mobile: 220 },
|
||||
{ date: '2024-05-25', desktop: 201, mobile: 250 },
|
||||
{ date: '2024-05-26', desktop: 213, mobile: 170 },
|
||||
{ date: '2024-05-27', desktop: 420, mobile: 460 },
|
||||
{ date: '2024-05-28', desktop: 233, mobile: 190 },
|
||||
{ date: '2024-05-29', desktop: 78, mobile: 130 },
|
||||
{ date: '2024-05-30', desktop: 340, mobile: 280 },
|
||||
{ date: '2024-05-31', desktop: 178, mobile: 230 },
|
||||
{ date: '2024-06-01', desktop: 178, mobile: 200 },
|
||||
{ date: '2024-06-02', desktop: 470, mobile: 410 },
|
||||
{ date: '2024-06-03', desktop: 103, mobile: 160 },
|
||||
{ date: '2024-06-04', desktop: 439, mobile: 380 },
|
||||
{ date: '2024-06-05', desktop: 88, mobile: 140 },
|
||||
{ date: '2024-06-06', desktop: 294, mobile: 250 },
|
||||
{ date: '2024-06-07', desktop: 323, mobile: 370 },
|
||||
{ date: '2024-06-08', desktop: 385, mobile: 320 },
|
||||
{ date: '2024-06-09', desktop: 438, mobile: 480 },
|
||||
{ date: '2024-06-10', desktop: 155, mobile: 200 },
|
||||
{ date: '2024-06-11', desktop: 92, mobile: 150 },
|
||||
{ date: '2024-06-12', desktop: 492, mobile: 420 },
|
||||
{ date: '2024-06-13', desktop: 81, mobile: 130 },
|
||||
{ date: '2024-06-14', desktop: 426, mobile: 380 },
|
||||
{ date: '2024-06-15', desktop: 307, mobile: 350 },
|
||||
{ date: '2024-06-16', desktop: 371, mobile: 310 },
|
||||
{ date: '2024-06-17', desktop: 475, mobile: 520 },
|
||||
{ date: '2024-06-18', desktop: 107, mobile: 170 },
|
||||
{ date: '2024-06-19', desktop: 341, mobile: 290 },
|
||||
{ date: '2024-06-20', desktop: 408, mobile: 450 },
|
||||
{ date: '2024-06-21', desktop: 169, mobile: 210 },
|
||||
{ date: '2024-06-22', desktop: 317, mobile: 270 },
|
||||
{ date: '2024-06-23', desktop: 480, mobile: 530 },
|
||||
{ date: '2024-06-24', desktop: 132, mobile: 180 },
|
||||
{ date: '2024-06-25', desktop: 141, mobile: 190 },
|
||||
{ date: '2024-06-26', desktop: 434, mobile: 380 },
|
||||
{ date: '2024-06-27', desktop: 448, mobile: 490 },
|
||||
{ date: '2024-06-28', desktop: 149, mobile: 200 },
|
||||
{ date: '2024-06-29', desktop: 103, mobile: 160 },
|
||||
{ date: '2024-06-30', desktop: 446, mobile: 400 },
|
||||
];
|
||||
|
||||
const chartConfig = {
|
||||
views: {
|
||||
label: 'Page Views',
|
||||
},
|
||||
desktop: {
|
||||
label: 'Desktop',
|
||||
color: 'var(--chart-1)',
|
||||
},
|
||||
mobile: {
|
||||
label: 'Mobile',
|
||||
color: 'var(--chart-2)',
|
||||
},
|
||||
} satisfies ChartConfig;
|
||||
|
||||
const total = useMemo(
|
||||
() => ({
|
||||
desktop: chartData.reduce((acc, curr) => acc + curr.desktop, 0),
|
||||
mobile: chartData.reduce((acc, curr) => acc + curr.mobile, 0),
|
||||
}),
|
||||
[],
|
||||
);
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader className="flex flex-col items-stretch space-y-0 border-b p-0 sm:flex-row">
|
||||
<div className="flex flex-1 flex-col justify-center gap-1 px-6 py-5 sm:py-6">
|
||||
<CardTitle>Page Views</CardTitle>
|
||||
|
||||
<CardDescription>
|
||||
Showing total visitors for the last 3 months
|
||||
</CardDescription>
|
||||
</div>
|
||||
|
||||
<div className="flex">
|
||||
{['desktop', 'mobile'].map((key) => {
|
||||
const chart = key as keyof typeof chartConfig;
|
||||
return (
|
||||
<button
|
||||
key={chart}
|
||||
data-active={activeChart === chart}
|
||||
className="data-[active=true]:bg-muted/50 relative z-30 flex flex-1 flex-col justify-center gap-1 border-t px-6 py-4 text-left even:border-l sm:border-t-0 sm:border-l sm:px-8 sm:py-6"
|
||||
onClick={() => setActiveChart(chart)}
|
||||
>
|
||||
<span className="text-muted-foreground text-xs">
|
||||
{chartConfig[chart].label}
|
||||
</span>
|
||||
<span className="text-lg leading-none font-bold sm:text-3xl">
|
||||
{total[key as keyof typeof total].toLocaleString()}
|
||||
</span>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</CardHeader>
|
||||
|
||||
<CardContent className="px-2 sm:p-6">
|
||||
<ChartContainer
|
||||
config={chartConfig}
|
||||
className="aspect-auto h-64 w-full"
|
||||
>
|
||||
<BarChart accessibilityLayer data={chartData}>
|
||||
<CartesianGrid vertical={false} />
|
||||
<XAxis
|
||||
dataKey="date"
|
||||
tickLine={false}
|
||||
axisLine={false}
|
||||
tickMargin={8}
|
||||
minTickGap={32}
|
||||
tickFormatter={(value) => {
|
||||
const date = new Date(value);
|
||||
return date.toLocaleDateString('en-US', {
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
});
|
||||
}}
|
||||
/>
|
||||
<ChartTooltip
|
||||
content={
|
||||
<ChartTooltipContent
|
||||
className="w-[150px]"
|
||||
nameKey="views"
|
||||
labelFormatter={(value) => {
|
||||
return new Date(value).toLocaleDateString('en-US', {
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
year: 'numeric',
|
||||
});
|
||||
}}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
<Bar dataKey={activeChart} fill={`var(--color-${activeChart})`} />
|
||||
</BarChart>
|
||||
</ChartContainer>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import dynamic from 'next/dynamic';
|
||||
|
||||
import { LoadingOverlay } from '@kit/ui/loading-overlay';
|
||||
|
||||
export const DashboardDemo = dynamic(() => import('./dashboard-demo-charts'), {
|
||||
export const Dashboard = dynamic(() => import('./team-account-statistics'), {
|
||||
ssr: false,
|
||||
loading: () => (
|
||||
<LoadingOverlay
|
||||
@@ -0,0 +1,163 @@
|
||||
import React, { use } from 'react';
|
||||
|
||||
import { redirect } from 'next/navigation';
|
||||
|
||||
import { formatCurrency } from '@/packages/shared/src/utils';
|
||||
import { PiggyBankIcon, Settings } from 'lucide-react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { Card, CardTitle } from '@kit/ui/card';
|
||||
import { Button } from '@kit/ui/shadcn/button';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
|
||||
import pathsConfig from '~/config/paths.config';
|
||||
import { createPath } from '~/config/team-account-navigation.config';
|
||||
|
||||
interface TeamAccountBenefitStatisticsProps {
|
||||
accountSlug: string;
|
||||
}
|
||||
|
||||
const StatisticsCard = ({ children }: { children: React.ReactNode }) => {
|
||||
return <Card className="p-4">{children}</Card>;
|
||||
};
|
||||
|
||||
const StatisticsCardTitle = ({ children }: { children: React.ReactNode }) => {
|
||||
return <CardTitle className="text-sm font-medium">{children}</CardTitle>;
|
||||
};
|
||||
|
||||
const StatisticsDescription = ({ children }: { children: React.ReactNode }) => {
|
||||
return <p className="text-success text-xs">{children}</p>;
|
||||
};
|
||||
|
||||
const StatisticsValue = ({ children }: { children: React.ReactNode }) => {
|
||||
return <h4 className="">{children}</h4>;
|
||||
};
|
||||
|
||||
const TeamAccountBenefitStatistics = ({
|
||||
accountSlug,
|
||||
}: TeamAccountBenefitStatisticsProps) => {
|
||||
const {
|
||||
i18n: { language },
|
||||
} = useTranslation();
|
||||
|
||||
return (
|
||||
<div className="flex h-full w-full flex-col gap-2 sm:flex-row">
|
||||
<Card className="relative flex flex-row">
|
||||
<div className="p-6">
|
||||
<Button
|
||||
onClick={() =>
|
||||
redirect(createPath(pathsConfig.app.accountBilling, accountSlug))
|
||||
}
|
||||
variant="outline"
|
||||
className="absolute top-1 right-1 p-3"
|
||||
>
|
||||
<Settings />
|
||||
</Button>
|
||||
<div className="flex h-16 w-16 items-center justify-center rounded-full bg-orange-100">
|
||||
<PiggyBankIcon className="h-[32px] w-[32px] stroke-orange-400 stroke-2" />
|
||||
</div>
|
||||
<p className="mt-4 text-sm font-medium">
|
||||
<Trans i18nKey="teams:benefitStatistics.budget.title" />
|
||||
</p>
|
||||
<h3 className="text-2xl">
|
||||
<Trans
|
||||
i18nKey="teams:benefitStatistics.budget.balance"
|
||||
values={{
|
||||
balance: formatCurrency({
|
||||
value: 11800,
|
||||
locale: language,
|
||||
currencyCode: 'EUR',
|
||||
}),
|
||||
}}
|
||||
/>
|
||||
</h3>
|
||||
<StatisticsDescription>
|
||||
<Trans
|
||||
i18nKey="teams:benefitStatistics.budget.volume"
|
||||
values={{
|
||||
volume: formatCurrency({
|
||||
value: 15000,
|
||||
locale: language,
|
||||
currencyCode: 'EUR',
|
||||
}),
|
||||
}}
|
||||
/>
|
||||
</StatisticsDescription>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<div className="grid flex-2 grid-cols-2 gap-2 sm:grid-cols-3 sm:grid-rows-2">
|
||||
<StatisticsCard>
|
||||
<StatisticsCardTitle>
|
||||
<Trans i18nKey="teams:benefitStatistics.data.analysis" />
|
||||
</StatisticsCardTitle>
|
||||
<StatisticsValue>18 %</StatisticsValue>
|
||||
<StatisticsDescription>
|
||||
<Trans
|
||||
i18nKey="teams:benefitStatistics.data.reservations"
|
||||
values={{ value: 36 }}
|
||||
/>
|
||||
</StatisticsDescription>
|
||||
</StatisticsCard>
|
||||
<StatisticsCard>
|
||||
<StatisticsCardTitle>
|
||||
<Trans i18nKey="teams:benefitStatistics.data.doctorsAndSpecialists" />
|
||||
</StatisticsCardTitle>
|
||||
<StatisticsValue>22 %</StatisticsValue>
|
||||
<StatisticsDescription>
|
||||
<Trans
|
||||
i18nKey="teams:benefitStatistics.data.reservations"
|
||||
values={{ value: 44 }}
|
||||
/>
|
||||
</StatisticsDescription>
|
||||
</StatisticsCard>
|
||||
<StatisticsCard>
|
||||
<StatisticsCardTitle>
|
||||
<Trans i18nKey="teams:benefitStatistics.data.researches" />
|
||||
</StatisticsCardTitle>
|
||||
<StatisticsValue>20 %</StatisticsValue>
|
||||
<StatisticsDescription>
|
||||
<Trans
|
||||
i18nKey="teams:benefitStatistics.data.reservations"
|
||||
values={{ value: 40 }}
|
||||
/>
|
||||
</StatisticsDescription>
|
||||
</StatisticsCard>
|
||||
<StatisticsCard>
|
||||
<StatisticsCardTitle>E-konsultatsioon</StatisticsCardTitle>
|
||||
<StatisticsValue>17 %</StatisticsValue>
|
||||
<StatisticsDescription>
|
||||
<Trans
|
||||
i18nKey="teams:benefitStatistics.data.reservations"
|
||||
values={{ value: 34 }}
|
||||
/>
|
||||
</StatisticsDescription>
|
||||
</StatisticsCard>
|
||||
<Card className="col-span-2 p-4">
|
||||
<StatisticsCardTitle>
|
||||
<Trans i18nKey="teams:benefitStatistics.data.healthResearchPlans" />
|
||||
</StatisticsCardTitle>
|
||||
<div className="grid grid-cols-2 gap-2">
|
||||
<div className="border-r">
|
||||
<StatisticsValue>23 %</StatisticsValue>
|
||||
<StatisticsDescription>
|
||||
<Trans
|
||||
i18nKey="teams:benefitStatistics.data.serviceUsage"
|
||||
values={{ value: 46 }}
|
||||
/>
|
||||
</StatisticsDescription>
|
||||
</div>
|
||||
<div className="ml-4">
|
||||
<StatisticsValue>1800 €</StatisticsValue>
|
||||
<StatisticsDescription>
|
||||
<Trans i18nKey="teams:benefitStatistics.data.serviceSum" />
|
||||
</StatisticsDescription>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default TeamAccountBenefitStatistics;
|
||||
@@ -0,0 +1,43 @@
|
||||
import React from 'react';
|
||||
|
||||
import { Card } from '@kit/ui/card';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
import { cn } from '@kit/ui/utils';
|
||||
|
||||
import {
|
||||
NormStatus,
|
||||
getAccountHealthDetailsFields,
|
||||
} from '../_lib/server/load-team-account-health-details';
|
||||
import { TeamAccountStatisticsProps } from './team-account-statistics';
|
||||
|
||||
const TeamAccountHealthDetails = ({
|
||||
memberParams,
|
||||
}: {
|
||||
memberParams: TeamAccountStatisticsProps['memberParams'];
|
||||
}) => {
|
||||
const accountHealthDetailsFields =
|
||||
getAccountHealthDetailsFields(memberParams);
|
||||
return (
|
||||
<div className="grid flex-1 grid-cols-2 gap-4 md:grid-cols-3">
|
||||
{accountHealthDetailsFields.map(({ title, Icon, value, normStatus }) => (
|
||||
<Card className="relative p-4" key={title}>
|
||||
<div
|
||||
className={cn('absolute top-2 right-2 rounded-2xl p-2', {
|
||||
'bg-success': normStatus === NormStatus.NORMAL,
|
||||
'bg-warning': normStatus === NormStatus.WARNING,
|
||||
'bg-destructive': normStatus === NormStatus.CRITICAL,
|
||||
})}
|
||||
>
|
||||
<Icon color="white" className="stroke-2" />
|
||||
</div>
|
||||
<h5 className="mt-8 leading-none">
|
||||
<Trans i18nKey={title} />
|
||||
</h5>
|
||||
<span className="text-muted-foreground text-xs">{value}</span>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default TeamAccountHealthDetails;
|
||||
@@ -2,12 +2,13 @@ import { PageHeader } from '@kit/ui/page';
|
||||
|
||||
export function TeamAccountLayoutPageHeader(
|
||||
props: React.PropsWithChildren<{
|
||||
title: string | React.ReactNode;
|
||||
description: string | React.ReactNode;
|
||||
account: string;
|
||||
title?: string | React.ReactNode;
|
||||
description?: string | React.ReactNode;
|
||||
}>,
|
||||
) {
|
||||
return (
|
||||
<PageHeader description={props.description}>{props.children}</PageHeader>
|
||||
<PageHeader description={props.description} title={props.title}>
|
||||
{props.children}
|
||||
</PageHeader>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -52,15 +52,15 @@ function SidebarContainer(props: {
|
||||
|
||||
return (
|
||||
<Sidebar collapsible={collapsible}>
|
||||
<SidebarHeader className={'h-16 justify-center'}>
|
||||
<div className={'flex items-center justify-between gap-x-3'}>
|
||||
<SidebarHeader className="h-16 justify-center">
|
||||
<div className="flex items-center justify-between gap-x-3">
|
||||
<TeamAccountAccountsSelector
|
||||
userId={userId}
|
||||
selectedAccount={account}
|
||||
accounts={accounts}
|
||||
/>
|
||||
|
||||
<div className={'group-data-[minimized=true]:hidden'}>
|
||||
<div className="group-data-[minimized=true]:hidden">
|
||||
<TeamAccountNotifications
|
||||
userId={userId}
|
||||
accountId={props.accountId}
|
||||
|
||||
101
app/home/[account]/_components/team-account-statistics.tsx
Normal file
101
app/home/[account]/_components/team-account-statistics.tsx
Normal file
@@ -0,0 +1,101 @@
|
||||
'use client';
|
||||
|
||||
import { redirect } from 'next/navigation';
|
||||
|
||||
import { Database } from '@/packages/supabase/src/database.types';
|
||||
import { ChevronRight, Euro, User } from 'lucide-react';
|
||||
|
||||
import { Card } from '@kit/ui/card';
|
||||
import { Trans } from '@kit/ui/makerkit/trans';
|
||||
|
||||
import pathsConfig from '~/config/paths.config';
|
||||
import { createPath } from '~/config/team-account-navigation.config';
|
||||
|
||||
import TeamAccountBenefitStatistics from './team-account-benefit-statistics';
|
||||
import TeamAccountHealthDetails from './team-account-health-details';
|
||||
|
||||
export interface TeamAccountStatisticsProps {
|
||||
teamAccount: Database['medreport']['Tables']['accounts']['Row'];
|
||||
memberParams: Pick<
|
||||
Database['medreport']['Tables']['account_params']['Row'],
|
||||
'weight' | 'height'
|
||||
>[];
|
||||
}
|
||||
|
||||
export default function TeamAccountStatistics({
|
||||
teamAccount,
|
||||
memberParams,
|
||||
}: TeamAccountStatisticsProps) {
|
||||
return (
|
||||
<div
|
||||
className={
|
||||
'animate-in fade-in flex flex-col space-y-4 pb-36 duration-500'
|
||||
}
|
||||
>
|
||||
<TeamAccountBenefitStatistics accountSlug={teamAccount.slug || ''} />
|
||||
|
||||
<h5 className="mt-4 mb-2">
|
||||
<Trans i18nKey="teams:home.healthDetails" />
|
||||
</h5>
|
||||
<div className="flex flex-col gap-2 sm:flex-row">
|
||||
<TeamAccountHealthDetails memberParams={memberParams} />
|
||||
|
||||
<div className="flex flex-col gap-2">
|
||||
<Card
|
||||
variant="gradient-success"
|
||||
className="border-success/50 hover:bg-success/20 relative flex h-full cursor-pointer flex-col justify-center px-6 py-4 transition-colors"
|
||||
onClick={() =>
|
||||
redirect(
|
||||
createPath(
|
||||
pathsConfig.app.accountMembers,
|
||||
teamAccount.slug || '',
|
||||
),
|
||||
)
|
||||
}
|
||||
>
|
||||
<div className="flex flex-col">
|
||||
<div className="border-input absolute top-2 right-2 rounded-md border bg-white p-3">
|
||||
<ChevronRight className="stroke-2" />
|
||||
</div>
|
||||
<div className="bg-primary/10 w-fit rounded-2xl p-2">
|
||||
<User color="green" className="stroke-2" />
|
||||
</div>
|
||||
<span className="mt-4 mb-2 text-lg font-semibold">
|
||||
<Trans i18nKey="teams:home.membersSettingsButtonTitle" />
|
||||
</span>
|
||||
<p className="text-muted-foreground text-sm">
|
||||
<Trans i18nKey="teams:home.membersSettingsButtonDescription" />
|
||||
</p>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
variant="gradient-warning"
|
||||
className="border-warning/40 hover:bg-warning/20 relative flex h-full cursor-pointer flex-col justify-center px-6 py-4 transition-colors"
|
||||
onClick={() =>
|
||||
redirect(
|
||||
createPath(
|
||||
pathsConfig.app.accountBilling,
|
||||
teamAccount.slug || '',
|
||||
),
|
||||
)
|
||||
}
|
||||
>
|
||||
<div className="border-input absolute top-2 right-2 rounded-md border bg-white p-3">
|
||||
<ChevronRight className="stroke-2" />
|
||||
</div>
|
||||
<div className="bg-warning/10 w-fit rounded-2xl p-2">
|
||||
<Euro color="orange" className="stroke-2" />
|
||||
</div>
|
||||
<span className="mt-4 mb-2 text-lg font-semibold">
|
||||
<Trans i18nKey="teams:home.membersBillingButtonTitle" />
|
||||
</span>
|
||||
<p className="text-muted-foreground text-sm">
|
||||
<Trans i18nKey="teams:home.membersBillingButtonDescription" />
|
||||
</p>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
import React from 'react';
|
||||
|
||||
import { Clock, TrendingUp, User } from 'lucide-react';
|
||||
|
||||
import { TeamAccountStatisticsProps } from '../../_components/team-account-statistics';
|
||||
|
||||
interface AccountHealthDetailsField {
|
||||
title: string;
|
||||
value: string | number;
|
||||
Icon: React.ComponentType<{
|
||||
size?: number;
|
||||
color?: string;
|
||||
className?: string;
|
||||
}>;
|
||||
normStatus: NormStatus;
|
||||
}
|
||||
|
||||
export enum NormStatus {
|
||||
CRITICAL = 'CRITICAL',
|
||||
WARNING = 'WARNING',
|
||||
NORMAL = 'NORMAL',
|
||||
}
|
||||
|
||||
export const getAccountHealthDetailsFields = (
|
||||
memberParams: TeamAccountStatisticsProps['memberParams'],
|
||||
): AccountHealthDetailsField[] => {
|
||||
const averageBMI = (
|
||||
memberParams.reduce((sum, { height, weight }) => {
|
||||
const hMeters = height! / 100;
|
||||
const bmi = weight! / (hMeters * hMeters);
|
||||
return sum + bmi;
|
||||
}, 0) / memberParams.length
|
||||
).toFixed(0);
|
||||
|
||||
return [
|
||||
{
|
||||
title: 'teams:healthDetails.women',
|
||||
value: `50% (${memberParams.length})`,
|
||||
Icon: User,
|
||||
normStatus: NormStatus.NORMAL,
|
||||
},
|
||||
{
|
||||
title: 'teams:healthDetails.men',
|
||||
value: `50% (${memberParams.length})`,
|
||||
Icon: User,
|
||||
normStatus: NormStatus.NORMAL,
|
||||
},
|
||||
{
|
||||
title: 'teams:healthDetails.avgAge',
|
||||
value: '56',
|
||||
Icon: Clock,
|
||||
normStatus: NormStatus.NORMAL,
|
||||
},
|
||||
{
|
||||
title: 'teams:healthDetails.bmi',
|
||||
value: averageBMI,
|
||||
Icon: TrendingUp,
|
||||
normStatus: NormStatus.WARNING,
|
||||
},
|
||||
{
|
||||
title: 'teams:healthDetails.cholesterol',
|
||||
value: '6.1',
|
||||
Icon: TrendingUp,
|
||||
normStatus: NormStatus.WARNING,
|
||||
},
|
||||
{
|
||||
title: 'teams:healthDetails.vitaminD',
|
||||
value: '76',
|
||||
Icon: TrendingUp,
|
||||
normStatus: NormStatus.NORMAL,
|
||||
},
|
||||
{
|
||||
title: 'teams:healthDetails.smokers',
|
||||
value: '22%',
|
||||
Icon: TrendingUp,
|
||||
normStatus: NormStatus.CRITICAL,
|
||||
},
|
||||
];
|
||||
};
|
||||
@@ -29,14 +29,14 @@ async function TeamAccountBillingPage({ params }: TeamAccountBillingPageProps) {
|
||||
|
||||
const account = await api.getTeamAccount(accountSlug);
|
||||
const companyParams = await api.getTeamAccountParams(account.id);
|
||||
const accounts = await api.getMembers(accountSlug);
|
||||
const { members } = await api.getMembers(accountSlug);
|
||||
|
||||
return (
|
||||
<PageBody>
|
||||
<HealthBenefitForm
|
||||
account={account}
|
||||
companyParams={companyParams}
|
||||
employeeCount={accounts.length}
|
||||
employeeCount={members.length}
|
||||
/>
|
||||
</PageBody>
|
||||
);
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
'use server';
|
||||
|
||||
import { use } from 'react';
|
||||
|
||||
import { CompanyGuard } from '@/packages/features/team-accounts/src/components';
|
||||
import { createTeamAccountsApi } from '@/packages/features/team-accounts/src/server/api';
|
||||
import { getSupabaseServerClient } from '@/packages/supabase/src/clients/server-client';
|
||||
|
||||
import { AppBreadcrumbs } from '@kit/ui/app-breadcrumbs';
|
||||
import { PageBody } from '@kit/ui/page';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
|
||||
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||
|
||||
import { DashboardDemo } from './_components/dashboard-demo';
|
||||
import { Dashboard } from './_components/dashboard';
|
||||
import { TeamAccountLayoutPageHeader } from './_components/team-account-layout-page-header';
|
||||
|
||||
interface TeamAccountHomePageProps {
|
||||
@@ -27,17 +30,24 @@ export const generateMetadata = async () => {
|
||||
|
||||
function TeamAccountHomePage({ params }: TeamAccountHomePageProps) {
|
||||
const account = use(params).account;
|
||||
console.log('TeamAccountHomePage account', account);
|
||||
const client = getSupabaseServerClient();
|
||||
const api = createTeamAccountsApi(client);
|
||||
const teamAccount = use(api.getTeamAccount(account));
|
||||
const { memberParams } = use(api.getMembers(account));
|
||||
|
||||
return (
|
||||
<>
|
||||
<TeamAccountLayoutPageHeader
|
||||
account={account}
|
||||
title={<Trans i18nKey={'common:routes.dashboard'} />}
|
||||
description={<AppBreadcrumbs />}
|
||||
title={
|
||||
<Trans
|
||||
i18nKey={'teams:home.headerTitle'}
|
||||
values={{ companyName: account }}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
|
||||
<PageBody>
|
||||
<DashboardDemo />
|
||||
<Dashboard teamAccount={teamAccount} memberParams={memberParams} />
|
||||
</PageBody>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -53,6 +53,6 @@ export function getTeamAccountSidebarConfig(account: string) {
|
||||
});
|
||||
}
|
||||
|
||||
function createPath(path: string, account: string) {
|
||||
export function createPath(path: string, account: string) {
|
||||
return path.replace('[account]', account);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { getSupabaseServerClient } from "@kit/supabase/server-client";
|
||||
import { getSupabaseServerAdminClient } from "@kit/supabase/server-admin-client";
|
||||
import type { Tables } from "@/packages/supabase/src/database.types";
|
||||
import type { Tables } from '@/packages/supabase/src/database.types';
|
||||
|
||||
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
|
||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||
|
||||
type Account = Tables<{ schema: 'medreport' }, 'accounts'>;
|
||||
type Membership = Tables<{ schema: 'medreport' }, 'accounts_memberships'>;
|
||||
|
||||
export type AccountWithMemberships = Account & { memberships: Membership[] }
|
||||
export type AccountWithMemberships = Account & { memberships: Membership[] };
|
||||
|
||||
export async function getAccount(id: string): Promise<AccountWithMemberships> {
|
||||
const { data } = await getSupabaseServerClient()
|
||||
@@ -28,6 +29,7 @@ export async function getAccountAdmin({
|
||||
.schema('medreport')
|
||||
.from('accounts')
|
||||
.select('*, memberships: accounts_memberships (*)')
|
||||
.eq('is_personal_account', true);
|
||||
|
||||
if (primaryOwnerUserId) {
|
||||
query.eq('primary_owner_user_id', primaryOwnerUserId);
|
||||
|
||||
@@ -164,7 +164,7 @@ async function TeamAccountPage(props: {
|
||||
account: Account & { memberships: Membership[] };
|
||||
}) {
|
||||
const api = createTeamAccountsApi(getSupabaseServerClient());
|
||||
const members = await api.getMembers(props.account.slug ?? '');
|
||||
const { members } = await api.getMembers(props.account.slug ?? '');
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -308,7 +308,32 @@ export class TeamAccountsApi {
|
||||
throw members.error;
|
||||
}
|
||||
|
||||
return members.data;
|
||||
const memberIds = members.data?.map((member) => member.id) ?? [];
|
||||
const memberParams = await this.client
|
||||
.schema('medreport')
|
||||
.from('account_params')
|
||||
.select('weight, height')
|
||||
.in('account_id', memberIds);
|
||||
|
||||
if (memberParams.error) {
|
||||
throw memberParams.error;
|
||||
}
|
||||
|
||||
return { members: members.data, memberParams: memberParams.data };
|
||||
}
|
||||
|
||||
async getMemberParams(ids: string[]) {
|
||||
const memberParams = await this.client
|
||||
.schema('medreport')
|
||||
.from('account_params')
|
||||
.select('weight, height')
|
||||
.in('account_id', ids);
|
||||
|
||||
if (memberParams.error) {
|
||||
throw memberParams.error;
|
||||
}
|
||||
|
||||
return memberParams.data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1640,9 +1640,7 @@ export type Database = {
|
||||
Returns: Json
|
||||
}
|
||||
create_team_account: {
|
||||
Args:
|
||||
| { account_name: string }
|
||||
| { account_name: string; new_personal_code: string }
|
||||
Args: { account_name: string; new_personal_code: string }
|
||||
Returns: {
|
||||
application_role: Database["medreport"]["Enums"]["application_role"]
|
||||
city: string | null
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import * as React from 'react';
|
||||
|
||||
import { VariantProps, cva } from 'class-variance-authority';
|
||||
|
||||
import { cn } from '.';
|
||||
|
||||
const cardVariants = cva('text-card-foreground rounded-xl border', {
|
||||
|
||||
@@ -126,4 +126,4 @@
|
||||
"updateRoleSuccess": "Role updated",
|
||||
"updateRoleError": "Something went wrong, please try again",
|
||||
"updateRoleLoading": "Updating role..."
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"home": {
|
||||
"pageTitle": "Home"
|
||||
"pageTitle": "Dashboard"
|
||||
},
|
||||
"settings": {
|
||||
"pageTitle": "Settings",
|
||||
|
||||
@@ -77,7 +77,7 @@
|
||||
"account": "Account",
|
||||
"members": "Members",
|
||||
"billing": "Billing",
|
||||
"dashboard": "Dashboard",
|
||||
"dashboard": "Ülevaade",
|
||||
"settings": "Settings",
|
||||
"profile": "Profile",
|
||||
"application": "Application"
|
||||
@@ -129,4 +129,4 @@
|
||||
"expiredAt": "Kehtiv kuni {{expiredAt}}"
|
||||
},
|
||||
"doctor": "Arst"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
{
|
||||
"home": {
|
||||
"pageTitle": "Home"
|
||||
"pageTitle": "Ülevaade",
|
||||
"headerTitle": "{{companyName}} tervise ülevaade",
|
||||
"healthDetails": "Ettevõtte terviseandmed",
|
||||
"membersSettingsButtonTitle": "Halda töötajaid",
|
||||
"membersSettingsButtonDescription": "Lisa, muuda või eemalda töötajaid.",
|
||||
"membersBillingButtonTitle": "Halda eelarvet",
|
||||
"membersBillingButtonDescription": "Vali kuidas soovid eelarvet töötajate vahel jagada."
|
||||
},
|
||||
"settings": {
|
||||
"pageTitle": "Settings",
|
||||
@@ -18,6 +24,31 @@
|
||||
"billing": {
|
||||
"pageTitle": "Billing"
|
||||
},
|
||||
"benefitStatistics": {
|
||||
"budget": {
|
||||
"title": "Ettevõtte Tervisekassa seis",
|
||||
"balance": "Eelarve jääk {{balance}}",
|
||||
"volume": "Eelarve maht {{volume}}"
|
||||
},
|
||||
"data": {
|
||||
"reservations": "{{value}} broneeringut",
|
||||
"analysis": "Analüüsid",
|
||||
"doctorsAndSpecialists": "Eriarstid ja spetsialistid",
|
||||
"researches": "Uuringud",
|
||||
"healthResearchPlans": "Terviseuuringute paketid",
|
||||
"serviceUsage": "{{value}} teenuse kasutust",
|
||||
"serviceSum": "Teenuste summa"
|
||||
}
|
||||
},
|
||||
"healthDetails": {
|
||||
"women": "Naised",
|
||||
"men": "Mehed",
|
||||
"avgAge": "Keskmine vanus",
|
||||
"bmi": "KMI",
|
||||
"cholesterol": "Üldkolesterool",
|
||||
"vitaminD": "Vitamiin D",
|
||||
"smokers": "Suitsetajad"
|
||||
},
|
||||
"yourTeams": "Your Companies ({{teamsCount}})",
|
||||
"createTeam": "Create a Company",
|
||||
"creatingTeam": "Creating Company...",
|
||||
|
||||
2
supabase/migrations/20250818111200_team_account.sql
Normal file
2
supabase/migrations/20250818111200_team_account.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
CREATE TRIGGER log_account_change AFTER DELETE OR UPDATE ON medreport.accounts_memberships FOR EACH ROW EXECUTE FUNCTION audit.log_audit_changes();
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
DROP FUNCTION IF EXISTS medreport.team_account_workspace(text);
|
||||
|
||||
CREATE FUNCTION medreport.team_account_workspace(account_slug text)
|
||||
RETURNS TABLE(
|
||||
id uuid,
|
||||
name character varying,
|
||||
picture_url character varying,
|
||||
slug text,
|
||||
role character varying,
|
||||
role_hierarchy_level integer,
|
||||
primary_owner_user_id uuid,
|
||||
subscription_status medreport.subscription_status,
|
||||
permissions medreport.app_permissions[],
|
||||
account_role varchar,
|
||||
application_role medreport.application_role
|
||||
)
|
||||
LANGUAGE plpgsql
|
||||
SET search_path TO ''
|
||||
AS $function$begin
|
||||
return QUERY
|
||||
select
|
||||
accounts.id,
|
||||
accounts.name,
|
||||
accounts.picture_url,
|
||||
accounts.slug,
|
||||
roles.name,
|
||||
roles.hierarchy_level,
|
||||
accounts.primary_owner_user_id,
|
||||
subscriptions.status,
|
||||
array_agg(role_permissions.permission),
|
||||
accounts_memberships.account_role,
|
||||
accounts.application_role
|
||||
from
|
||||
medreport.accounts
|
||||
join medreport.accounts_memberships on accounts.id = accounts_memberships.account_id
|
||||
left join medreport.subscriptions on accounts.id = subscriptions.account_id
|
||||
join medreport.roles on accounts_memberships.account_role = roles.name
|
||||
left join medreport.role_permissions on accounts_memberships.account_role = role_permissions.role
|
||||
where
|
||||
accounts.slug = account_slug
|
||||
and medreport.accounts_memberships.user_id = (select auth.uid())
|
||||
group by
|
||||
accounts.id,
|
||||
accounts_memberships.account_role,
|
||||
subscriptions.status,
|
||||
roles.hierarchy_level,
|
||||
roles.name;
|
||||
end;$function$;
|
||||
|
||||
GRANT EXECUTE ON FUNCTION medreport.team_account_workspace(text) TO authenticated, service_role;
|
||||
Reference in New Issue
Block a user