diff --git a/src/app/portfolio/[slug]/(portfolio)/your-projects/live/DealStageChart.tsx b/src/app/portfolio/[slug]/(portfolio)/your-projects/live/DealStageChart.tsx index 1a388d7..dc999eb 100644 --- a/src/app/portfolio/[slug]/(portfolio)/your-projects/live/DealStageChart.tsx +++ b/src/app/portfolio/[slug]/(portfolio)/your-projects/live/DealStageChart.tsx @@ -8,44 +8,54 @@ const STAGE_ORDER = [ "Booking team to contact tenant", "Survey in progress", "Not viable", + "Needs Heating Upgrade installed", "Needs support", "Coordination + design", "Ready to be installed", ]; +const stage = (label: string) => STAGE_ORDER.find((s) => s === label)!; + const STAGE_LABELS: Record = { - "1617223910": STAGE_ORDER[0], - "3583836399": STAGE_ORDER[0], - "3589581001": STAGE_ORDER[1], - "3569878239": STAGE_ORDER[1], - "1617223911": STAGE_ORDER[1], - "1984184569": STAGE_ORDER[1], - "3569572028": STAGE_ORDER[1], - "3570936026": STAGE_ORDER[1], - "2663668937": STAGE_ORDER[1], - "1984401629": STAGE_ORDER[1], - "1617223912": STAGE_ORDER[2], - "1617223913": STAGE_ORDER[2], - "2558220518": STAGE_ORDER[1], - "3474594026": STAGE_ORDER[1], - "3206388924": STAGE_ORDER[2], - "1617223915": STAGE_ORDER[2], - "1617223917": STAGE_ORDER[2], - "1887735998": STAGE_ORDER[3], - "3061261536": STAGE_ORDER[4], - "2571417798": STAGE_ORDER[2], - "1617223914": STAGE_ORDER[5], - "1887736000": STAGE_ORDER[2], - "1617223916": STAGE_ORDER[2], - "2628341989": STAGE_ORDER[2], - "3441170637": STAGE_ORDER[2], - "2628233422": STAGE_ORDER[5], - "1887735999": STAGE_ORDER[4], - "2702650617": STAGE_ORDER[5], - "2473886962": STAGE_ORDER[5], - "3016601828": STAGE_ORDER[4], - "1668803774": STAGE_ORDER[6], - "3440363736": STAGE_ORDER[6], + "1617223910": stage("Initial planning"), + "3583836399": stage("Initial planning"), + + "3589581001": stage("Booking team to contact tenant"), + "3569878239": stage("Booking team to contact tenant"), + "1617223911": stage("Booking team to contact tenant"), + "1984184569": stage("Booking team to contact tenant"), + "3569572028": stage("Booking team to contact tenant"), + "3570936026": stage("Booking team to contact tenant"), + "2663668937": stage("Booking team to contact tenant"), + "1984401629": stage("Booking team to contact tenant"), + "2558220518": stage("Booking team to contact tenant"), + "3474594026": stage("Booking team to contact tenant"), + + "1617223912": stage("Survey in progress"), + "1617223913": stage("Survey in progress"), + "3206388924": stage("Survey in progress"), + "1617223915": stage("Survey in progress"), + "1617223917": stage("Survey in progress"), + "2571417798": stage("Survey in progress"), + "1887736000": stage("Survey in progress"), + "1617223916": stage("Survey in progress"), + "2628341989": stage("Survey in progress"), + "3441170637": stage("Survey in progress"), + + "1887735998": stage("Not viable"), + + "3061261536": stage("Needs Heating Upgrade installed"), + "1887735999": stage("Needs Heating Upgrade installed"), + "3016601828": stage("Needs Heating Upgrade installed"), + + "1617223914": stage("Needs support"), + "2628233422": stage("Needs support"), + "2702650617": stage("Needs support"), + "2473886962": stage("Needs support"), + + "1668803774": stage("Coordination + design"), + "3440363736": stage("Coordination + design"), + "2769407183": stage("Needs Heating Upgrade installed"), }; interface DealStageChartProps { @@ -56,18 +66,22 @@ interface DealStageChartProps { export function DealStageChart({ deals, onOpenTable }: DealStageChartProps) { const data = useMemo(() => { const counts: Record = {}; + + // Count deals by stage deals.forEach((d) => { const stageId = d.dealstage || "unknown"; const stageName = STAGE_LABELS[stageId] || "Unknown Stage"; counts[stageName] = (counts[stageName] || 0) + 1; }); - const unsorted = Object.entries(counts).map(([name, value]) => ({ + // Ensure every stage in STAGE_ORDER has a default of 0 + const complete = STAGE_ORDER.map((name) => ({ name, - value, + value: counts[name] || 0, })); - return unsorted.sort((a, b) => { + // Sort according to STAGE_ORDER (just in case) + return complete.sort((a, b) => { const aIndex = STAGE_ORDER.indexOf(a.name); const bIndex = STAGE_ORDER.indexOf(b.name); return ( @@ -77,6 +91,9 @@ export function DealStageChart({ deals, onOpenTable }: DealStageChartProps) { }); }, [deals]); + // ✅ Calculate total deals + const total = useMemo(() => deals.length, [deals]); + const handleBarClick = (value: { name: string; value: number }) => { const filtered = deals.filter((d) => { const stageId = d.dealstage || "unknown"; @@ -95,6 +112,11 @@ export function DealStageChart({ deals, onOpenTable }: DealStageChartProps) {

Click a bar to view related properties

+ + {/* ✅ Total count */} +

+ Total: {total.toLocaleString()} properties +