2023-03-15 20:06:21 +00:00
|
|
|
// recharts
|
|
|
|
import {
|
|
|
|
CartesianGrid,
|
|
|
|
Line,
|
|
|
|
LineChart,
|
|
|
|
ResponsiveContainer,
|
|
|
|
Tooltip,
|
|
|
|
XAxis,
|
|
|
|
YAxis,
|
|
|
|
} from "recharts";
|
|
|
|
// ui
|
|
|
|
import { CustomMenu } from "components/ui";
|
|
|
|
// constants
|
|
|
|
import { MONTHS } from "constants/project";
|
|
|
|
|
|
|
|
type Props = {
|
2023-03-24 05:36:52 +00:00
|
|
|
issues:
|
|
|
|
| {
|
|
|
|
week_in_month: number;
|
|
|
|
completed_count: number;
|
|
|
|
}[]
|
|
|
|
| undefined;
|
|
|
|
month: number;
|
|
|
|
setMonth: React.Dispatch<React.SetStateAction<number>>;
|
2023-03-15 20:06:21 +00:00
|
|
|
};
|
|
|
|
|
2023-03-24 05:36:52 +00:00
|
|
|
export const CompletedIssuesGraph: React.FC<Props> = ({ month, issues, setMonth }) => {
|
|
|
|
const weeks = month === 2 ? 4 : 5;
|
2023-03-15 20:06:21 +00:00
|
|
|
|
|
|
|
const data: any[] = [];
|
|
|
|
|
2023-03-24 05:36:52 +00:00
|
|
|
for (let i = 1; i <= weeks; i++) {
|
|
|
|
data.push({
|
|
|
|
week_in_month: i,
|
|
|
|
completed_count: issues?.find((item) => item.week_in_month === i)?.completed_count ?? 0,
|
|
|
|
});
|
2023-03-15 20:06:21 +00:00
|
|
|
}
|
|
|
|
|
2023-03-24 05:36:52 +00:00
|
|
|
const CustomTooltip = ({ payload, label }: any) => (
|
|
|
|
<div className="space-y-1 rounded bg-white p-3 text-sm shadow-md">
|
|
|
|
<h4 className="text-gray-500">{label}</h4>
|
|
|
|
<h5>Completed issues: {payload[0]?.value}</h5>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
2023-03-15 20:06:21 +00:00
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<div className="mb-0.5 flex justify-between">
|
|
|
|
<h3 className="font-semibold">Issues closed by you</h3>
|
2023-03-24 05:36:52 +00:00
|
|
|
<CustomMenu label={<span className="text-sm">{MONTHS[month - 1]}</span>} noBorder>
|
2023-03-15 20:06:21 +00:00
|
|
|
{MONTHS.map((month, index) => (
|
2023-03-24 05:36:52 +00:00
|
|
|
<CustomMenu.MenuItem key={month} onClick={() => setMonth(index + 1)}>
|
2023-03-15 20:06:21 +00:00
|
|
|
{month}
|
|
|
|
</CustomMenu.MenuItem>
|
|
|
|
))}
|
|
|
|
</CustomMenu>
|
|
|
|
</div>
|
|
|
|
<div className="rounded-[10px] border bg-white p-8 pl-4">
|
|
|
|
<ResponsiveContainer width="100%" height={250}>
|
|
|
|
<LineChart data={data}>
|
|
|
|
<CartesianGrid stroke="#e2e2e2" />
|
2023-03-24 05:36:52 +00:00
|
|
|
<XAxis dataKey="week_in_month" />
|
2023-03-28 18:38:34 +00:00
|
|
|
<YAxis dataKey="completed_count" allowDecimals={false} />
|
2023-03-24 05:36:52 +00:00
|
|
|
<Tooltip content={<CustomTooltip />} />
|
2023-03-15 20:06:21 +00:00
|
|
|
<Line
|
|
|
|
type="monotone"
|
2023-03-24 05:36:52 +00:00
|
|
|
dataKey="completed_count"
|
2023-03-15 20:06:21 +00:00
|
|
|
stroke="#d687ff"
|
|
|
|
strokeWidth={3}
|
|
|
|
fill="#8e2de2"
|
|
|
|
/>
|
|
|
|
</LineChart>
|
|
|
|
</ResponsiveContainer>
|
2023-03-24 05:36:52 +00:00
|
|
|
<h4 className="mt-4 flex items-center justify-center gap-2 text-[#d687ff]">
|
|
|
|
<span className="h-2 w-2 bg-[#d687ff]" />
|
|
|
|
Completed Issues
|
|
|
|
</h4>
|
2023-03-15 20:06:21 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|