Gate the ROI calculator behind a registration form, add strategy deck
CI / build (push) Canceled after 0s

Replaces the open calculator with the intended flow: visitors register
(name, company, title, business email, region, device count) to unlock
a 15-slide Strategy Deck viewer and the ROI Calculator. Both the deck
and a personalised ROI report now download as real PowerPoint files,
built client-side with JSZip by patching the deck template's XML.
Registration and report downloads are captured as enquiries via the
existing /api/leads endpoint. Drops the old PNG results-slide export
(html2canvas) in favour of the PPTX report.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-10-26 14:34:13 +05:00
co-authored by Claude Sonnet 5
parent 5232e6bd64
commit ca838ba287
30 changed files with 1905 additions and 1103 deletions
+109
View File
@@ -0,0 +1,109 @@
import { useEffect, useRef, useState } from 'react'
import { calculate, formatForDeck, loadInputs } from './calc.js'
import { buildPersonalisedDeck, getExampleDeck, prefetchTemplate, triggerDownload } from './pptxReport.js'
import type { Registrant } from './RoiLanding'
const SLIDE_COUNT = 15
const slides = Array.from({ length: SLIDE_COUNT }, (_, i) => `/roi/slides/slide-${String(i + 1).padStart(2, '0')}.jpg`)
export default function RoiDeckViewer({ active, registrant }: { active: boolean; registrant: Registrant }) {
const [cur, setCur] = useState(0)
const [busy, setBusy] = useState(false)
const thumbsRef = useRef<HTMLDivElement>(null)
const go = (n: number) => setCur(Math.max(0, Math.min(SLIDE_COUNT - 1, n)))
async function downloadDeck() {
if (busy) return
setBusy(true)
try {
const i: any = loadInputs(registrant)
const r = calculate(i)
const values = formatForDeck(i, r, registrant)
const meta = { company: registrant?.company || 'Your Company' }
// Slide 3 shows their device count (from the form) straight away. Slide 12 keeps the
// example figures until they've entered their own numbers in the calculator.
const blob = i.touched && r.complete ? await buildPersonalisedDeck(values, meta) : values.subs ? await buildPersonalisedDeck(values, meta, { roi: false }) : await getExampleDeck()
triggerDownload(blob, 'BlackDice_Turn_Network_Protection_Strategy_Deck.pptx')
} catch (err) {
console.error(err)
} finally {
setBusy(false)
}
}
// Warm the template cache while the deck is being viewed
useEffect(() => {
if (active) prefetchTemplate().catch(() => {})
}, [active])
useEffect(() => {
if (!active) return
const onKey = (e: KeyboardEvent) => {
const tag = (e.target as HTMLElement)?.tagName
if (['INPUT', 'SELECT', 'TEXTAREA'].includes(tag)) return
if (e.key === 'ArrowRight' || e.key === 'ArrowDown') {
e.preventDefault()
setCur((c) => Math.min(SLIDE_COUNT - 1, c + 1))
}
if (e.key === 'ArrowLeft' || e.key === 'ArrowUp') {
e.preventDefault()
setCur((c) => Math.max(0, c - 1))
}
}
document.addEventListener('keydown', onKey)
return () => document.removeEventListener('keydown', onKey)
}, [active])
useEffect(() => {
const thumb = thumbsRef.current?.children[cur] as HTMLElement | undefined
thumb?.scrollIntoView({ block: 'nearest', inline: 'center', behavior: 'smooth' })
}, [cur])
// Preload the next slide for snappy navigation
useEffect(() => {
if (cur + 1 < SLIDE_COUNT) new Image().src = slides[cur + 1]
}, [cur])
return (
<div className="deck-viewer-wrap">
<div className="deck-viewer-top">
<div>
<div className="deck-viewer-title">Turn Network Protection into Competitive Advantage</div>
<div className="deck-viewer-sub">15 slides · Use arrow keys or click to navigate · Click thumbnails to jump to any slide</div>
</div>
<button type="button" className="deck-dl-btn" onClick={downloadDeck} disabled={busy}>
<svg viewBox="0 0 24 24">
<path d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4" />
<polyline points="7 10 12 15 17 10" />
<line x1="12" y1="15" x2="12" y2="3" />
</svg>
{busy ? 'Preparing…' : 'Download Deck (PPTX)'}
</button>
</div>
<div className="slide-viewer">
<div className="slide-display">
<button className="slide-nav-btn prev" onClick={() => go(cur - 1)} disabled={cur === 0} aria-label="Previous slide">
&#8249;
</button>
<img src={slides[cur]} alt={`Slide ${cur + 1}`} />
<button className="slide-nav-btn next" onClick={() => go(cur + 1)} disabled={cur === SLIDE_COUNT - 1} aria-label="Next slide">
&#8250;
</button>
</div>
<div className="slide-controls">
<div className="slide-counter">
{cur + 1} / {SLIDE_COUNT}
</div>
<div className="slide-thumbs" ref={thumbsRef}>
{slides.map((src, i) => (
<button key={src} className={`slide-thumb-btn${i === cur ? ' active' : ''}`} onClick={() => go(i)} title={`Slide ${i + 1}`}>
<img src={src} alt={`Slide ${i + 1}`} loading="lazy" />
</button>
))}
</div>
</div>
</div>
</div>
)
}