mirror of
https://github.com/kjanat/livedash-node.git
synced 2026-02-13 21:15:45 +01:00
- Update tsconfig to ES2024 target and bundler moduleResolution - Add dynamic imports for chart.js and recharts (bundle optimization) - Consolidate 17 useState into useReducer in sessions page - Fix 18 .js extension imports across lib files - Add type declarations for @rapideditor/country-coder - Fix platform user types (PlatformUserRole enum) - Fix Calendar component prop types - Centralize next-auth type augmentation - Add force-dynamic to all API routes (prevent build-time prerender) - Fix Prisma JSON null handling with Prisma.DbNull - Fix various type mismatches (SessionMessage, ImportRecord, etc.) - Export ButtonProps from button component - Update next-themes import path - Replace JSX.Element with React.ReactElement - Remove obsolete debug scripts and pnpm lockfile - Downgrade eslint to v8 for next compatibility
121 lines
2.8 KiB
TypeScript
121 lines
2.8 KiB
TypeScript
"use client";
|
|
|
|
import { useId } from "react";
|
|
import {
|
|
Area,
|
|
AreaChart,
|
|
CartesianGrid,
|
|
Line,
|
|
LineChart,
|
|
ResponsiveContainer,
|
|
Tooltip,
|
|
XAxis,
|
|
YAxis,
|
|
} from "recharts";
|
|
|
|
interface LineChartData {
|
|
date: string;
|
|
value: number;
|
|
[key: string]: string | number;
|
|
}
|
|
|
|
interface LineChartInnerProps {
|
|
data: LineChartData[];
|
|
dataKey: string;
|
|
color: string;
|
|
gradient: boolean;
|
|
height: number;
|
|
}
|
|
|
|
interface TooltipProps {
|
|
active?: boolean;
|
|
payload?: Array<{ value: number; name?: string }>;
|
|
label?: string;
|
|
}
|
|
|
|
const CustomTooltip = ({ active, payload, label }: TooltipProps) => {
|
|
if (active && payload && payload.length) {
|
|
return (
|
|
<div className="rounded-lg border bg-background p-3 shadow-md">
|
|
<p className="text-sm font-medium">{label}</p>
|
|
<p className="text-sm text-muted-foreground">
|
|
<span className="font-medium text-foreground">
|
|
{payload[0].value}
|
|
</span>{" "}
|
|
sessions
|
|
</p>
|
|
</div>
|
|
);
|
|
}
|
|
return null;
|
|
};
|
|
|
|
export default function LineChartInner({
|
|
data,
|
|
dataKey,
|
|
color,
|
|
gradient,
|
|
height,
|
|
}: LineChartInnerProps) {
|
|
const gradientId = useId();
|
|
const ChartComponent = gradient ? AreaChart : LineChart;
|
|
|
|
return (
|
|
<ResponsiveContainer width="100%" height={height}>
|
|
<ChartComponent
|
|
data={data}
|
|
margin={{ top: 5, right: 30, left: 20, bottom: 5 }}
|
|
>
|
|
<defs>
|
|
{gradient && (
|
|
<linearGradient id={gradientId} x1="0" y1="0" x2="0" y2="1">
|
|
<stop offset="5%" stopColor={color} stopOpacity={0.3} />
|
|
<stop offset="95%" stopColor={color} stopOpacity={0.05} />
|
|
</linearGradient>
|
|
)}
|
|
</defs>
|
|
<CartesianGrid
|
|
strokeDasharray="3 3"
|
|
stroke="hsl(var(--border))"
|
|
strokeOpacity={0.3}
|
|
/>
|
|
<XAxis
|
|
dataKey="date"
|
|
stroke="hsl(var(--muted-foreground))"
|
|
fontSize={12}
|
|
tickLine={false}
|
|
axisLine={false}
|
|
/>
|
|
<YAxis
|
|
stroke="hsl(var(--muted-foreground))"
|
|
fontSize={12}
|
|
tickLine={false}
|
|
axisLine={false}
|
|
/>
|
|
<Tooltip content={<CustomTooltip />} />
|
|
|
|
{gradient ? (
|
|
<Area
|
|
type="monotone"
|
|
dataKey={dataKey}
|
|
stroke={color}
|
|
strokeWidth={2}
|
|
fill={`url(#${gradientId})`}
|
|
dot={{ fill: color, strokeWidth: 2, r: 4 }}
|
|
activeDot={{ r: 6, stroke: color, strokeWidth: 2 }}
|
|
/>
|
|
) : (
|
|
<Line
|
|
type="monotone"
|
|
dataKey={dataKey}
|
|
stroke={color}
|
|
strokeWidth={2}
|
|
dot={{ fill: color, strokeWidth: 2, r: 4 }}
|
|
activeDot={{ r: 6, stroke: color, strokeWidth: 2 }}
|
|
/>
|
|
)}
|
|
</ChartComponent>
|
|
</ResponsiveContainer>
|
|
);
|
|
}
|