From 2b32e26e052059d70e66e21e021177f495b5802a Mon Sep 17 00:00:00 2001 From: Mehboob Khan Date: Mon, 19 Oct 2026 16:22:56 +0500 Subject: [PATCH] Capture ROI calculator submissions as enquiries for admin review Visitors can now send their ROI results with name/email/company, which records the full inputs and savings breakdown through the existing leads API so admins can review them in the Enquiries tab. Co-Authored-By: Claude Sonnet 5 --- src/cms/admin/LeadsPanel.tsx | 4 +- src/site/roi/RoiCalculator.tsx | 83 ++++++++++++++++++++++++++++++++++ src/site/roi/roiCalculator.css | 27 +++++++++++ 3 files changed, 113 insertions(+), 1 deletion(-) diff --git a/src/cms/admin/LeadsPanel.tsx b/src/cms/admin/LeadsPanel.tsx index 196a64f..291e024 100644 --- a/src/cms/admin/LeadsPanel.tsx +++ b/src/cms/admin/LeadsPanel.tsx @@ -64,7 +64,9 @@ export default function LeadsPanel() { {lead.phone ? ` · ${lead.phone}` : ''} {lead.message ? ( - + {lead.message} ) : null} diff --git a/src/site/roi/RoiCalculator.tsx b/src/site/roi/RoiCalculator.tsx index 3900028..41e844c 100644 --- a/src/site/roi/RoiCalculator.tsx +++ b/src/site/roi/RoiCalculator.tsx @@ -9,8 +9,10 @@ import { INPUTS_KEY, loadInputs, REGIONS, + regionLabel, } from './calc.js' import RoiSlide from './RoiSlide' +import { submitLead } from '../../cms/api' const Icon = { globe: ( @@ -79,10 +81,35 @@ function CardHeader({ const rangePct = (val: number, min: number, max: number) => `${(((val - min) / (max - min)) * 100).toFixed(1)}%` +/** Plain-text summary of a visitor's inputs and results, stored as the enquiry's message. */ +function buildRoiSummary(i: Record, r: ReturnType) { + return [ + `Active subscribers: ${i.subs ? Number(i.subs).toLocaleString('en-US') : '—'}`, + `Region: ${i.region === 'custom' ? `Custom ($${i.customPrice || 0}/GB)` : regionLabel(i.region)}`, + `Bandwidth scenario: ${i.scenario}`, + `Support calls per 1,000 subs/month: ${i.callsPer1000}`, + `Average cost per call: $${i.callCost}`, + `Security-related calls: ${i.securityPct}%`, + `Monthly ARPU: ${i.arpu ? `$${i.arpu}` : '—'}`, + `Annual churn rate: ${i.churn ? `${i.churn}%` : '—'}`, + `Annual network infrastructure OpEx: ${i.netOpex ? `$${Number(i.netOpex).toLocaleString('en-US')}` : '—'}`, + `DDoS incidents per year: ${i.ddos || 0}`, + '', + `Total estimated annual savings: ${fmtRange(r.total.lo, r.total.hi) || '—'}`, + ` Bandwidth savings: ${fmtRange(r.bw.lo, r.bw.hi) || '—'}`, + ` Support call reduction: ${fmtRange(r.calls.lo, r.calls.hi) || '—'}`, + ` Churn reduction: ${fmtRange(r.churn.lo, r.churn.hi) || '—'}`, + ` Network equipment: ${fmtRange(r.equip.lo, r.equip.hi) || '—'}`, + ` DDoS avoided costs: ${fmtRange(r.ddos.lo, r.ddos.hi) || '—'}`, + ].join('\n') +} + export default function RoiCalculator() { const [i, setI] = useState(loadInputs) const [showAssump, setShowAssump] = useState(false) const [showSlide, setShowSlide] = useState(false) + const [lead, setLead] = useState({ name: '', email: '', company: '' }) + const [leadState, setLeadState] = useState<'idle' | 'sending' | 'sent' | 'error'>('idle') const update = (patch: Record) => { setI((s: typeof i) => ({ ...s, ...patch })) @@ -92,6 +119,25 @@ export default function RoiCalculator() { const r = useMemo(() => calculate(i), [i]) + const submitRoiLead = async (e: React.FormEvent) => { + e.preventDefault() + if (!lead.email.trim() || leadState === 'sending') return + setLeadState('sending') + try { + await submitLead({ + form: 'roi-calculator', + name: lead.name.trim(), + email: lead.email.trim(), + company: lead.company.trim(), + page: '/roi-calculator', + message: buildRoiSummary(i, r), + }) + setLeadState('sent') + } catch { + setLeadState('error') + } + } + // Remember inputs for this visitor (survives refresh) useEffect(() => { try { @@ -417,6 +463,43 @@ export default function RoiCalculator() { depend on network architecture, traffic mix, subscriber behaviour, and existing security controls. + {r.complete && ( +
+
+

Send these results to your team

+ {leadState === 'sent' ? ( +

Thanks — your results have been recorded. We'll follow up shortly.

+ ) : ( +
+ setLead((s) => ({ ...s, name: e.target.value }))} + /> + setLead((s) => ({ ...s, email: e.target.value }))} + /> + setLead((s) => ({ ...s, company: e.target.value }))} + /> + +
+ )} + {leadState === 'error' &&

Something went wrong — please try again.

} +
+
+ )} +

Your personalised ROI slide

diff --git a/src/site/roi/roiCalculator.css b/src/site/roi/roiCalculator.css index 04399e7..68a7b66 100644 --- a/src/site/roi/roiCalculator.css +++ b/src/site/roi/roiCalculator.css @@ -573,6 +573,33 @@ color: #889; margin-top: 8px; } + +/* Lead capture form */ +.roi-calc .roi-lead-form { + display: flex; + gap: 10px; + flex-wrap: wrap; + margin-top: 12px; +} +.roi-calc .roi-lead-form input { + flex: 1 1 160px; + padding: 10px 13px; + border: 1.5px solid #c8dde3; + border-radius: 8px; + font-family: 'Ubuntu', sans-serif; + font-size: 13px; + color: var(--roi-text); + background: var(--roi-white); + outline: none; + transition: border-color 0.2s, box-shadow 0.2s; +} +.roi-calc .roi-lead-form input:focus { + border-color: var(--roi-green); + box-shadow: 0 0 0 3px rgba(53, 184, 136, 0.15); +} +.roi-calc .roi-lead-form .report-dl-btn { + flex: 0 0 auto; +} @media (max-width: 960px) { .roi-calc .main { grid-template-columns: 1fr;