Skip to content

Commit 2a0ec0f

Browse files
Merge pull request #4961 from OneCommunityGlobal/Sohail-donut-chart-fix
Sohail: Comment start Job Posting Page Analytics: Create a donut chart showing applicants by experience
2 parents c9bfc1d + e2c0020 commit 2a0ec0f

3 files changed

Lines changed: 135 additions & 86 deletions

File tree

.husky/pre-commit

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ if [ -f .nvmrc ]; then
77
nvm use 20 2>/dev/null || nvm install 20 && nvm use 20
88
fi
99

10-
. "$(dirname "$0")/_/husky.sh"
11-
1210
echo ""
1311
echo "🛡️ Husky pre-commit hook triggered"
1412

src/components/ExperienceDonutChart/ExperienceDonutChart.jsx

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useEffect, useMemo, useRef, useState } from 'react';
22
import { useSelector } from 'react-redux';
3+
import axios from 'axios'; // Added axios import to fix network request errors
34
import { PieChart, Pie, Cell, ResponsiveContainer, Tooltip } from 'recharts';
45
import styles from './ExperienceDonutChart.module.css';
56

@@ -65,17 +66,19 @@ export default function ExperienceDonutChart() {
6566
const token = localStorage.getItem('token');
6667
if (!token) throw new Error('No token found. Please log in.');
6768

68-
const url = `${process.env.REACT_APP_APIENDPOINT}/experience-breakdown`;
69+
// Fixed API endpoint path to include /applicant-analytics
70+
const url = `${process.env.REACT_APP_APIENDPOINT}/applicant-analytics/experience-breakdown`;
6971
const params = {};
7072

71-
if (filterStartDate && filterEndDate) {
72-
params.startDate = filterStartDate;
73-
params.endDate = filterEndDate;
74-
} else if (filterRoles && filterRoles.length > 0) {
75-
params.roles = filterRoles.join(',');
73+
// Replaced undefined filter variables with correctly scoped appliedFilters
74+
if (appliedFilters.startDate && appliedFilters.endDate) {
75+
params.startDate = appliedFilters.startDate;
76+
params.endDate = appliedFilters.endDate;
77+
}
78+
if (appliedFilters.roles && appliedFilters.roles.length > 0) {
79+
params.roles = appliedFilters.roles.join(',');
7680
}
7781

78-
// const response = await axios.get(url, { params });
7982
const response = await axios.get(url, {
8083
headers: { Authorization: token },
8184
params,
@@ -89,25 +92,20 @@ export default function ExperienceDonutChart() {
8992
return;
9093
}
9194

92-
const counts = experienceLabels.map(label => {
95+
// Re-formatted chart data as an array of objects for Recharts compatibility
96+
const formattedData = EXPERIENCE_LABELS.map((label, index) => {
9397
const found = data.find(d => d.experience === label);
94-
return found ? found.count : 0;
98+
return {
99+
name: label,
100+
value: found ? found.count : 0,
101+
color: SEGMENT_COLORS[index % SEGMENT_COLORS.length], // Fixed case sensitivity for constants
102+
};
95103
});
96104

97-
const totalCount = counts.reduce((a, b) => a + b, 0);
98-
99-
const chart = {
100-
labels: experienceLabels,
101-
datasets: [
102-
{
103-
data: counts,
104-
backgroundColor: segmentColors,
105-
hoverOffset: 20,
106-
},
107-
],
108-
};
105+
const totalCount = formattedData.reduce((a, b) => a + b.value, 0);
109106

110-
setChartData({ chart, totalCount });
107+
setChartData(formattedData);
108+
setTotal(totalCount); // Added state update for chart center total
111109
} catch (err) {
112110
setError(err.response?.data?.message || err.message || 'Error fetching data.');
113111
setChartData(null);
@@ -150,7 +148,7 @@ export default function ExperienceDonutChart() {
150148
return (
151149
<div className={styles['chart-details']}>
152150
{chartData.map((d, idx) => {
153-
const pct = ((d.value / total) * 100).toFixed(1);
151+
const pct = total > 0 ? ((d.value / total) * 100).toFixed(1) : 0;
154152
return (
155153
<div
156154
key={d.name}
@@ -172,10 +170,11 @@ export default function ExperienceDonutChart() {
172170
const CustomTooltip = ({ active, payload }) => {
173171
if (!active || !payload?.length) return null;
174172
const d = payload[0]?.payload;
175-
const pct = ((d.value / total) * 100).toFixed(1);
173+
const pct = total > 0 ? ((d.value / total) * 100).toFixed(1) : 0;
176174

177175
return (
178176
<div className={styles['custom-tooltip']}>
177+
{/* Corrected tooltip to use name and value from payload for visibility */}
179178
<strong>{d.name}</strong>
180179
<br />
181180
Count: {d.value}

0 commit comments

Comments
 (0)