import React, { useState, useEffect } from 'react';
import axios from 'axios';
const Scorecard = () => {
const [data, setData] = useState(null);
const [loading, setLoading] = useState(true);
useEffect(() => {
fetchScorecard();
}, []);
const fetchScorecard = async () => {
try {
const res = await axios.get('/scorecard/weekly-summary');
setData(res.data);
} catch (err) {
console.error("Failed to load BSC");
} finally {
setLoading(false);
}
};
if (loading) return
Calculating HR Metrics...
;
const perspectives = [
{ id: 'financial', label: 'Financial (ROI & Costs)', color: 'bg-emerald-600' },
{ id: 'customer', label: 'Employee Experience (EX)', color: 'bg-blue-600' },
{ id: 'internal_process', label: 'Process Excellence', color: 'bg-purple-600' },
{ id: 'learning_growth', label: 'Talent & Culture', color: 'bg-orange-600' }
];
return (
Balanced Scorecard - HR Health
Week Starting: {data.week}
{perspectives.map((p) => (
{p.label}
Health: {data.health[p.id].healthScore}%
{data.metrics.filter(m => m.perspective === p.id).map(metric => (
{metric.name}
Target: {metric.target_value}{metric.unit}
= metric.target_value ? 'text-green-600' : 'text-red-500'}`}>
{metric.current_value || 0}{metric.unit}
))}
))}
);
};
export default Scorecard;