-
Monthly KPI
-
-
-
- KPI |
- Value |
-
-
-
- {data.map((row) => (
-
- {row.kpi} |
- {row.value} |
-
- ))}
-
-
+
);
+ }
+
+ if (loading) {
+ return (
+
+ );
+ }
+
+ // Use optional chaining and nullish coalescing to safely default values to 0
+ const yield_kwh = kpiData?.yield_kwh ?? 0;
+ const consumption_kwh = kpiData?.consumption_kwh ?? 0;
+ const grid_draw_kwh = kpiData?.grid_draw_kwh ?? 0;
+ const efficiency = kpiData?.efficiency ?? 0;
+
+ const data = [
+ { kpi: 'Monthly Yield', value: `${yield_kwh.toFixed(0)} kWh` },
+ { kpi: 'Monthly Consumption', value: `${consumption_kwh.toFixed(0)} kWh` },
+ { kpi: 'Monthly Grid Draw', value: `${grid_draw_kwh.toFixed(0)} kWh` },
+ { kpi: 'Efficiency', value: `${efficiency.toFixed(1)}%` },
+ ];
+
+ return (
+
+
Monthly KPI
+
+
+
+ KPI |
+ Value |
+
+
+
+ {data.map((row) => (
+
+ {row.kpi} |
+ {row.value} |
+
+ ))}
+
+
+
+ );
};
export default KPI_Table;
+
+