feat: synchronize dashboard origins with management page and add integration endpoints
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m53s
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m53s
- Updated Dashboard origin chart to strictly reflect only configured origins, grouping unmapped data into an 'Outros' category. - Added GET /api/integration/funnels and GET /api/integration/origins endpoints to allow external AIs to dynamically map stages and lead sources.
This commit is contained in:
@@ -192,25 +192,45 @@ export const Dashboard: React.FC = () => {
|
||||
|
||||
// --- Chart Data: Origin ---
|
||||
const originData = useMemo(() => {
|
||||
const origins = data.reduce((acc, curr) => {
|
||||
const counts = data.reduce((acc, curr) => {
|
||||
acc[curr.origin] = (acc[curr.origin] || 0) + 1;
|
||||
return acc;
|
||||
}, {} as Record<string, number>);
|
||||
|
||||
return (Object.entries(origins) as [string, number][])
|
||||
.map(([name, value]) => {
|
||||
const def = originDefs.find(o => o.name === name);
|
||||
// Extract base color (e.g. "red" from "bg-red-100 text-red-700...")
|
||||
let hexColor = '';
|
||||
if (def && def.color_class) {
|
||||
if (originDefs.length > 0) {
|
||||
const activeOrigins = originDefs.map(def => {
|
||||
let hexColor = '#71717a'; // Default zinc
|
||||
if (def.color_class) {
|
||||
const match = def.color_class.match(/bg-([a-z]+)-\d+/);
|
||||
if (match && tailwindToHex[match[1]]) {
|
||||
hexColor = tailwindToHex[match[1]];
|
||||
}
|
||||
}
|
||||
return { name, value, hexColor };
|
||||
})
|
||||
.sort((a, b) => b.value - a.value);
|
||||
return {
|
||||
name: def.name,
|
||||
value: counts[def.name] || 0,
|
||||
hexColor
|
||||
};
|
||||
});
|
||||
|
||||
// Calculate "Outros" for data that doesn't match current active origins
|
||||
const activeNames = new Set(originDefs.map(d => d.name));
|
||||
const othersValue = (Object.entries(counts) as [string, number][])
|
||||
.filter(([name]) => !activeNames.has(name))
|
||||
.reduce((sum, [_, val]) => sum + val, 0);
|
||||
|
||||
if (othersValue > 0) {
|
||||
activeOrigins.push({
|
||||
name: 'Outros',
|
||||
value: othersValue,
|
||||
hexColor: '#94a3b8' // Gray-400
|
||||
});
|
||||
}
|
||||
|
||||
return activeOrigins.sort((a, b) => b.value - a.value);
|
||||
}
|
||||
|
||||
return []; // No definitions = No chart (matches funnel behavior)
|
||||
}, [data, originDefs]);
|
||||
|
||||
// --- Table Data: Sellers Ranking ---
|
||||
|
||||
Reference in New Issue
Block a user