mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 00:03:33 +10:00
fix: ssr hydration error in piechart
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { HTMLAttributes } from 'react';
|
import { HTMLAttributes, useEffect, useState } from 'react';
|
||||||
|
|
||||||
import { Cell, Pie, PieChart, Tooltip } from 'recharts';
|
import { Cell, Pie, PieChart, Tooltip } from 'recharts';
|
||||||
|
|
||||||
@ -41,33 +41,40 @@ const renderCustomizedLabel = ({
|
|||||||
export type CapTableProps = HTMLAttributes<HTMLDivElement>;
|
export type CapTableProps = HTMLAttributes<HTMLDivElement>;
|
||||||
|
|
||||||
export const CapTable = ({ className, ...props }: CapTableProps) => {
|
export const CapTable = ({ className, ...props }: CapTableProps) => {
|
||||||
|
const [isSSR, setIsSSR] = useState(true);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setIsSSR(false);
|
||||||
|
}, []);
|
||||||
return (
|
return (
|
||||||
<div className={cn('flex flex-col', className)} {...props}>
|
<div className={cn('flex flex-col', className)} {...props}>
|
||||||
<h3 className="px-4 text-lg font-semibold">Cap Table</h3>
|
<h3 className="px-4 text-lg font-semibold">Cap Table</h3>
|
||||||
|
|
||||||
<div className="border-border mt-2.5 flex flex-1 items-center justify-center rounded-2xl border shadow-sm hover:shadow">
|
<div className="border-border mt-2.5 flex flex-1 items-center justify-center rounded-2xl border shadow-sm hover:shadow">
|
||||||
<PieChart width={400} height={400}>
|
{!isSSR && (
|
||||||
<Pie
|
<PieChart width={400} height={400}>
|
||||||
data={CAP_TABLE}
|
<Pie
|
||||||
cx="50%"
|
data={CAP_TABLE}
|
||||||
cy="50%"
|
cx="50%"
|
||||||
labelLine={false}
|
cy="50%"
|
||||||
label={renderCustomizedLabel}
|
labelLine={false}
|
||||||
outerRadius={180}
|
label={renderCustomizedLabel}
|
||||||
innerRadius={100}
|
outerRadius={180}
|
||||||
fill="#8884d8"
|
innerRadius={100}
|
||||||
dataKey="percentage"
|
fill="#8884d8"
|
||||||
>
|
dataKey="percentage"
|
||||||
{CAP_TABLE.map((entry, index) => (
|
>
|
||||||
<Cell key={`cell-${index}`} fill={COLORS[index % COLORS.length]} />
|
{CAP_TABLE.map((entry, index) => (
|
||||||
))}
|
<Cell key={`cell-${index}`} fill={COLORS[index % COLORS.length]} />
|
||||||
</Pie>
|
))}
|
||||||
<Tooltip
|
</Pie>
|
||||||
formatter={(percent: number, name, props) => {
|
<Tooltip
|
||||||
return [`${percent}%`, name || props['name'] || props['payload']['name']];
|
formatter={(percent: number, name, props) => {
|
||||||
}}
|
return [`${percent}%`, name || props['name'] || props['payload']['name']];
|
||||||
/>
|
}}
|
||||||
</PieChart>
|
/>
|
||||||
|
</PieChart>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import { cn } from '@documenso/ui/lib/utils';
|
|||||||
|
|
||||||
import { StargazersType } from './page';
|
import { StargazersType } from './page';
|
||||||
|
|
||||||
|
export type MetricsDataKey = 'stars' | 'forks' | 'mergedPRs' | 'openIssues';
|
||||||
export type GithubMetricProps = HTMLAttributes<HTMLDivElement> & {
|
export type GithubMetricProps = HTMLAttributes<HTMLDivElement> & {
|
||||||
data: StargazersType;
|
data: StargazersType;
|
||||||
metricKey: MetricsDataKey;
|
metricKey: MetricsDataKey;
|
||||||
@ -17,8 +18,6 @@ export type GithubMetricProps = HTMLAttributes<HTMLDivElement> & {
|
|||||||
chartHeight?: number;
|
chartHeight?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type MetricsDataKey = 'stars' | 'forks' | 'mergedPRs' | 'openIssues';
|
|
||||||
|
|
||||||
export const GithubMetric = ({
|
export const GithubMetric = ({
|
||||||
className,
|
className,
|
||||||
data,
|
data,
|
||||||
@ -39,9 +38,9 @@ export const GithubMetric = ({
|
|||||||
<div className={cn('flex flex-col', className)} {...props}>
|
<div className={cn('flex flex-col', className)} {...props}>
|
||||||
<h3 className="px-4 text-lg font-semibold">{title}</h3>
|
<h3 className="px-4 text-lg font-semibold">{title}</h3>
|
||||||
|
|
||||||
<div className="border-border mt-2.5 flex flex-1 items-center justify-center rounded-2xl border shadow-sm hover:shadow">
|
<div className="border-border mt-2.5 flex flex-1 items-center justify-center rounded-2xl border pr-2 shadow-sm hover:shadow">
|
||||||
<ResponsiveContainer width="100%" height={chartHeight}>
|
<ResponsiveContainer width="100%" height={chartHeight}>
|
||||||
<BarChart data={formattedData} margin={{ top: 40, right: 20 }}>
|
<BarChart data={formattedData} margin={{ top: 30, right: 20 }}>
|
||||||
<XAxis dataKey="month" />
|
<XAxis dataKey="month" />
|
||||||
<YAxis />
|
<YAxis />
|
||||||
<Tooltip
|
<Tooltip
|
||||||
|
|||||||
Reference in New Issue
Block a user