|
1 | | -import React from "react"; |
| 1 | +import React, { useState, useEffect } from "react"; |
2 | 2 | import ActivityCalendar from "react-activity-calendar"; |
3 | 3 | import { Tooltip } from "@mui/material"; |
4 | 4 | import { useTranslation } from "react-i18next"; |
5 | 5 |
|
6 | | -const ActivityStatisticComponent = ({ activityData }) => { |
| 6 | +const ActivityStatisticComponent = (props) => { |
| 7 | + const { activityData, selectedYear } = props; |
7 | 8 | const { t } = useTranslation(); |
8 | 9 |
|
9 | | - const formattedData = activityData.map((item) => ({ |
10 | | - date: new Date(item.date).toISOString().split("T")[0], // YYYY-MM-DD formatı |
11 | | - count: parseInt(item.count, 10), |
12 | | - level: item.level, |
13 | | - })); |
| 10 | + const getLocalizedLabels = () => { |
| 11 | + const weekdays = t("admin_activity_calendar_weekdays", { |
| 12 | + returnObjects: true, |
| 13 | + defaultValue: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"], |
| 14 | + }); |
| 15 | + |
| 16 | + const months = t("admin_activity_calendar_months", { |
| 17 | + returnObjects: true, |
| 18 | + defaultValue: [ |
| 19 | + "Jan", |
| 20 | + "Feb", |
| 21 | + "Mar", |
| 22 | + "Apr", |
| 23 | + "May", |
| 24 | + "Jun", |
| 25 | + "Jul", |
| 26 | + "Aug", |
| 27 | + "Sep", |
| 28 | + "Oct", |
| 29 | + "Nov", |
| 30 | + "Dec", |
| 31 | + ], |
| 32 | + }); |
| 33 | + |
| 34 | + return { weekdays, months }; |
| 35 | + }; |
| 36 | + |
| 37 | + const { weekdays, months } = getLocalizedLabels(); |
| 38 | + |
| 39 | + const generateYearData = (year, data) => { |
| 40 | + const dates = new Map( |
| 41 | + data.map((item) => [item.date, { count: item.count, level: item.level }]) |
| 42 | + ); |
| 43 | + |
| 44 | + const yearData = []; |
| 45 | + const startDate = new Date(`${year}-01-01`); |
| 46 | + const endDate = new Date(`${year}-12-31`); |
| 47 | + |
| 48 | + let currentDate = new Date(startDate); |
| 49 | + |
| 50 | + while (currentDate <= endDate) { |
| 51 | + const formattedDate = currentDate.toISOString().split("T")[0]; |
| 52 | + yearData.push({ |
| 53 | + date: formattedDate, |
| 54 | + count: dates.get(formattedDate)?.count || 0, |
| 55 | + level: dates.get(formattedDate)?.level || 0, |
| 56 | + }); |
| 57 | + currentDate.setDate(currentDate.getDate() + 1); |
| 58 | + } |
| 59 | + |
| 60 | + return yearData; |
| 61 | + }; |
| 62 | + |
| 63 | + const formattedData = generateYearData( |
| 64 | + selectedYear, |
| 65 | + activityData.map((item) => ({ |
| 66 | + date: new Date(item.date).toISOString().split("T")[0], |
| 67 | + count: parseInt(item.count, 10), |
| 68 | + level: item.level, |
| 69 | + })) |
| 70 | + ); |
14 | 71 |
|
15 | 72 | return ( |
16 | 73 | <ActivityCalendar |
17 | 74 | data={formattedData} |
18 | 75 | blockRadius={4} |
19 | 76 | blockSize={16} |
| 77 | + showWeekdayLabels={true} |
20 | 78 | theme={{ |
21 | 79 | dark: ["#DAF0FE", "#99D1F2", "#53B2F0", "#1E86E5", "#0A3B7A"], |
22 | 80 | light: ["#0A3B7A", "#1561A5", "#1E86E5", "#53B2F0", "#99D1F2"], |
23 | 81 | }} |
24 | 82 | labels={{ |
25 | 83 | legend: { |
26 | 84 | less: t("admin_activity_calendar_legend_less", { |
27 | | - defaultValue: "Az", |
| 85 | + defaultValue: "Less", |
28 | 86 | }), |
29 | 87 | more: t("admin_activity_calendar_legend_more", { |
30 | | - defaultValue: "Çok", |
| 88 | + defaultValue: "High", |
31 | 89 | }), |
32 | 90 | }, |
33 | | - months: t("admin_activity_calendar_months", { |
34 | | - defaultValue: [ |
35 | | - "Oca", |
36 | | - "Şub", |
37 | | - "Mar", |
38 | | - "Nis", |
39 | | - "May", |
40 | | - "Haz", |
41 | | - "Tem", |
42 | | - "Ağu", |
43 | | - "Eyl", |
44 | | - "Eki", |
45 | | - "Kas", |
46 | | - "Ara", |
47 | | - ], |
48 | | - }), |
| 91 | + months, |
| 92 | + weekdays, |
49 | 93 | totalCount: t("admin_activity_calendar_total_count", { |
50 | 94 | defaultValue: "{{count}} katkı {{year}} yılında", |
51 | 95 | }), |
52 | | - showWeekdayLabels: false, |
53 | 96 | }} |
54 | 97 | renderBlock={(block, activity) => ( |
55 | 98 | <Tooltip |
56 | 99 | title={ |
57 | | - activity |
| 100 | + activity && activity.count > 0 |
58 | 101 | ? t("admin_activity_calendar_logs_tooltip", { |
59 | 102 | count: activity.count, |
60 | 103 | date: activity.date, |
61 | 104 | }) |
62 | 105 | : t("admin_activity_calendar_no_activity", { |
63 | | - defaultValue: "Etkinlik Yok", |
| 106 | + defaultValue: "No Activity", |
64 | 107 | }) |
65 | 108 | } |
66 | 109 | > |
|
0 commit comments