Skip to content

Commit f7b5313

Browse files
Merge pull request #4267 from OneCommunityGlobal/Meron-Fix-Accessing-Skills-Page-for-different-user-Ids
Meron - Fix Accessing Skills Page for different user Ids
2 parents f3d9607 + 1a95866 commit f7b5313

3 files changed

Lines changed: 54 additions & 24 deletions

File tree

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,17 @@
1010

1111
# misc
1212
.DS_Store
13+
14+
# Environment files
1315
.env
1416
.env.local
17+
.env.development
1518
.env.development.local
1619
.env.test.local
1720
.env.production.local
1821

22+
23+
1924
npm-debug.log*
2025
yarn-debug.log*
2126
yarn-error.log*

src/components/ExperienceDonutChart/ExperienceDonutChart.jsx

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -62,24 +62,54 @@ export default function ExperienceDonutChart() {
6262
setActiveIndex(null);
6363

6464
try {
65-
const randomMultiplier =
66-
(appliedFilters.roles?.length || 1) +
67-
(appliedFilters.startDate ? 1 : 0) +
68-
(appliedFilters.endDate ? 1 : 0);
69-
70-
const dummy = EXPERIENCE_LABELS.map((label, idx) => ({
71-
name: label,
72-
value: secureRandomInt(5, 5 + 50 * randomMultiplier), // ✅ secure random
73-
color: SEGMENT_COLORS[idx % SEGMENT_COLORS.length],
74-
}));
75-
76-
const filtered = dummy.filter(d => d.value > 0);
77-
const totalCount = filtered.reduce((sum, d) => sum + d.value, 0);
78-
79-
setChartData(filtered);
80-
setTotal(totalCount);
81-
} catch {
82-
setError('Failed to load dummy data');
65+
const token = localStorage.getItem('token');
66+
if (!token) throw new Error('No token found. Please log in.');
67+
68+
const url = `${process.env.REACT_APP_APIENDPOINT}/experience-breakdown`;
69+
const params = {};
70+
71+
if (filterStartDate && filterEndDate) {
72+
params.startDate = filterStartDate;
73+
params.endDate = filterEndDate;
74+
} else if (filterRoles && filterRoles.length > 0) {
75+
params.roles = filterRoles.join(',');
76+
}
77+
78+
// const response = await axios.get(url, { params });
79+
const response = await axios.get(url, {
80+
headers: { Authorization: token },
81+
params,
82+
});
83+
84+
const { data } = response;
85+
86+
if (!data || data.length === 0) {
87+
setChartData(null);
88+
setLoading(false);
89+
return;
90+
}
91+
92+
const counts = experienceLabels.map(label => {
93+
const found = data.find(d => d.experience === label);
94+
return found ? found.count : 0;
95+
});
96+
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+
};
109+
110+
setChartData({ chart, totalCount });
111+
} catch (err) {
112+
setError(err.response?.data?.message || err.message || 'Error fetching data.');
83113
setChartData(null);
84114
setTotal(0);
85115
} finally {

src/components/HGNSkillsDashboard/SkillsProfilePage/components/UserSkillsProfile.jsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,7 @@ function UserSkillsProfile() {
3535
}
3636

3737
const response = await axios.get(
38-
`http://localhost:4500/api/skills/profile/${effectiveUserId}`,
39-
{
40-
headers: {
41-
Authorization: `${token}`,
42-
},
43-
},
38+
`${process.env.REACT_APP_APIENDPOINT}/skills/profile/${effectiveUserId}`,
4439
);
4540
// console.log('Profile Data:', response.data);
4641

0 commit comments

Comments
 (0)