@skyhook-io/radar-app 1.23.0 → 1.23.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/package.json +1 -1
  2. package/src/App.tsx +14 -3
  3. package/src/api/client.ts +29 -3
  4. package/src/api/client.updateResource.secretExpiry.test.tsx +47 -0
  5. package/src/api/poll.ts +78 -0
  6. package/src/api/radarFeatures.ts +3 -0
  7. package/src/components/CloudFunnelButton.tsx +1 -0
  8. package/src/components/helm/HelmDrawerRouting.test.tsx +34 -1
  9. package/src/components/helm/HelmReleaseDrawer.tsx +6 -4
  10. package/src/components/helm/HelmView.tsx +4 -3
  11. package/src/components/helm/ObservedHelmNotice.tsx +39 -17
  12. package/src/components/helm/ObservedHelmRelease.test.tsx +62 -3
  13. package/src/components/helm/ObservedHelmReleaseDrawer.test.tsx +18 -0
  14. package/src/components/helm/ObservedHelmReleaseDrawer.tsx +4 -2
  15. package/src/components/issues/uncheckedSources.test.ts +8 -0
  16. package/src/components/issues/uncheckedSources.ts +3 -0
  17. package/src/components/nudges/activeNudges.test.ts +39 -0
  18. package/src/components/nudges/activeNudges.ts +76 -0
  19. package/src/components/poll/OssPoll.tsx +871 -0
  20. package/src/components/poll/mount.test.ts +12 -0
  21. package/src/components/poll/pollCloud.test.ts +23 -0
  22. package/src/components/poll/pollCloud.ts +6 -0
  23. package/src/components/poll/pollDefinition.ts +93 -0
  24. package/src/components/poll/pollFlow.test.ts +140 -0
  25. package/src/components/poll/pollFlow.ts +137 -0
  26. package/src/components/poll/pollSender.test.ts +137 -0
  27. package/src/components/poll/pollSender.ts +76 -0
  28. package/src/components/poll/pollStorage.test.ts +53 -0
  29. package/src/components/poll/pollStorage.ts +77 -0
  30. package/src/components/poll/round.json +350 -0
  31. package/src/components/product-hunt/ProductHuntNotice.tsx +2 -0
  32. package/src/components/resources/ImageFilesystemModal.test.tsx +21 -1
  33. package/src/components/resources/ImageFilesystemModal.tsx +42 -3
  34. package/src/components/resources/ResourcesView.tsx +22 -5
  35. package/src/components/ui/UpdateNotification.tsx +2 -0
  36. package/src/components/usage-data/UsageDataPrompt.tsx +2 -0
  37. package/src/components/whats-new/WhatsNew.tsx +2 -0
  38. package/src/components/whats-new/releaseNotes.ts +75 -1
@@ -0,0 +1,871 @@
1
+ import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'
2
+ import { createPortal } from 'react-dom'
3
+ import { useSearchParams } from 'react-router-dom'
4
+ import { clsx } from 'clsx'
5
+ import { ArrowLeft, Cloud, MessageSquareHeart, X } from 'lucide-react'
6
+ import { DialogPortal } from '@skyhook-io/k8s-ui/components/ui/DialogPortal'
7
+ import { useCapabilities } from '../../api/client'
8
+ import { getApiBase } from '../../api/config'
9
+ import { PollSubmitError, dismissPoll, recordPollShown, submitPoll, usePollStatus } from '../../api/poll'
10
+ import { useAnimatedUnmount } from '../../hooks/useAnimatedUnmount'
11
+ import { TRANSITION_MENU, overlayExitMs, overlayTransitionStyle } from '../../utils/animation'
12
+ import { openCloudFromPoll } from './pollCloud'
13
+ import { createPollSender } from './pollSender'
14
+ import { otherNudgeSeenThisLoad, useNudgeVisible, useOtherNudgeVisible } from '../nudges/activeNudges'
15
+ import { CURRENT_ROUND, POLL_COPY, type PollAnswers, type PollQuestion } from './pollDefinition'
16
+ import {
17
+ type ClosingLine,
18
+ type PollScreen,
19
+ closingLine,
20
+ looksLikeEmail,
21
+ newSubmissionId,
22
+ orderedOptions,
23
+ pollScreens,
24
+ pruneAnswers,
25
+ toggleChoice,
26
+ } from './pollFlow'
27
+ import { useCloudHintsEnabled } from '../cloudHints/cloudHints'
28
+ import { type BrowserPollState, browserAllows, mergePollState, readPollState, recordActiveDay, writePollState } from './pollStorage'
29
+
30
+ const NUDGE_ID = 'oss-poll'
31
+ // Never the first thing someone sees: the card waits until Radar has been
32
+ // open for a minute and nothing else is asking for attention.
33
+ const CARD_DELAY_MS = 60_000
34
+ // `?poll-preview` opens the card at once, for review. No answers are sent and
35
+ // no showing, dismissal or answer is recorded, so it can be clicked through on
36
+ // any build.
37
+ // `?poll-preview=send-fails` shows what a failed send looks like.
38
+ const PREVIEW_PARAM = 'poll-preview'
39
+ const PREVIEW_SEND_FAILS = 'send-fails'
40
+
41
+ function storage(): Storage | null {
42
+ try {
43
+ return window.localStorage
44
+ } catch {
45
+ return null
46
+ }
47
+ }
48
+
49
+ /**
50
+ * The in-product "help us improve Radar OSS" poll: a corner card that opens a
51
+ * dialog of short question screens. The host must not mount it when Radar is
52
+ * embedded in another app.
53
+ */
54
+ export function OssPoll() {
55
+ const capabilities = useCapabilities()
56
+ const rawMode = capabilities.data ? (capabilities.data.deployment?.mode ?? 'local') : undefined
57
+ const offerable = rawMode === 'local' || rawMode === 'in-cluster'
58
+ const cloudHints = useCloudHintsEnabled()
59
+
60
+ const status = usePollStatus(offerable)
61
+ const [browserState, setBrowserState] = useState<BrowserPollState | null>(null)
62
+ const apiBase = getApiBase()
63
+
64
+ // Today counts as a day of use, once the server says this install may be
65
+ // asked. A tab left open for days counts again each time it comes back into
66
+ // view. Where the poll is off, nothing is recorded.
67
+ const pollOn = !!status.data?.eligible
68
+ useEffect(() => {
69
+ if (!pollOn) return
70
+ const count = () => {
71
+ const store = storage()
72
+ const current = store ? readPollState(store, apiBase) : null
73
+ if (!store || !current) {
74
+ setBrowserState(null)
75
+ return
76
+ }
77
+ const next = recordActiveDay(current, Date.now())
78
+ writePollState(store, apiBase, next)
79
+ setBrowserState(next)
80
+ }
81
+ count()
82
+ const onVisible = () => {
83
+ if (document.visibilityState === 'visible') count()
84
+ }
85
+ document.addEventListener('visibilitychange', onVisible)
86
+ return () => document.removeEventListener('visibilitychange', onVisible)
87
+ }, [apiBase, pollOn])
88
+
89
+ const updateBrowserState = useCallback(
90
+ (patch: Partial<BrowserPollState>) => {
91
+ const store = storage()
92
+ const next = store ? mergePollState(store, apiBase, patch) : null
93
+ if (next) setBrowserState(next)
94
+ },
95
+ [apiBase],
96
+ )
97
+
98
+ const allowed =
99
+ offerable &&
100
+ !!status.data?.eligible &&
101
+ status.data.round === CURRENT_ROUND.id &&
102
+ Date.now() < Date.parse(CURRENT_ROUND.endsAt) &&
103
+ browserAllows(browserState, CURRENT_ROUND.id, Date.now())
104
+
105
+ const [delayPassed, setDelayPassed] = useState(false)
106
+ useEffect(() => {
107
+ if (!allowed) return
108
+ const t = window.setTimeout(() => setDelayPassed(true), CARD_DELAY_MS)
109
+ return () => window.clearTimeout(t)
110
+ }, [allowed])
111
+
112
+ const [searchParams] = useSearchParams()
113
+ // Read once: navigating inside the app drops the parameter, and a preview
114
+ // must never turn into a poll that sends.
115
+ const [preview] = useState(() => searchParams.has(PREVIEW_PARAM))
116
+ const [previewSendFails] = useState(() => searchParams.get(PREVIEW_PARAM) === PREVIEW_SEND_FAILS)
117
+ const [phase, setPhase] = useState<'idle' | 'card' | 'dialog' | 'done'>('idle')
118
+ // The dialog mounts on Sure and stays mounted through its closing animation.
119
+ const [opened, setOpened] = useState(false)
120
+ const othersShowing = useOtherNudgeVisible(NUDGE_ID)
121
+
122
+ useEffect(() => {
123
+ if (preview && offerable && !othersShowing) setPhase((p) => (p === 'idle' ? 'card' : p))
124
+ }, [preview, offerable, othersShowing])
125
+
126
+ useEffect(() => {
127
+ if (preview || phase !== 'idle' || !allowed || !delayPassed || othersShowing) return
128
+ // One ask per visit: a load that already showed another nudge (an upgrade's
129
+ // What's New, the usage-stats card, a star callout) is not the one to poll.
130
+ if (otherNudgeSeenThisLoad(NUDGE_ID)) return
131
+ // Another tab may have shown, dismissed or answered the poll since this
132
+ // one loaded; its storage write is the only signal that reaches here.
133
+ const store = storage()
134
+ const fresh = store ? readPollState(store, apiBase) : null
135
+ if (!browserAllows(fresh, CURRENT_ROUND.id, Date.now())) {
136
+ setPhase('done')
137
+ return
138
+ }
139
+ setPhase('card')
140
+ recordPollShown()
141
+ updateBrowserState({ lastShownAt: Date.now() })
142
+ }, [preview, phase, allowed, delayPassed, othersShowing, updateBrowserState, apiBase])
143
+
144
+ // The card also steps aside for a nudge that arrives after it, such as an
145
+ // update notice whose version check lands late. The dialog, once opened, is
146
+ // the person's choice and stays.
147
+ const cardVisible = phase === 'card' && !othersShowing
148
+ useNudgeVisible(NUDGE_ID, cardVisible || phase === 'dialog')
149
+
150
+ const later = () => {
151
+ if (!preview) dismissPoll('snooze')
152
+ setPhase('done')
153
+ }
154
+ const never = () => {
155
+ if (!preview) {
156
+ dismissPoll('never')
157
+ updateBrowserState({ never: true })
158
+ }
159
+ setPhase('done')
160
+ }
161
+
162
+ return (
163
+ <>
164
+ <PollCard
165
+ show={cardVisible}
166
+ onAccept={() => {
167
+ setOpened(true)
168
+ setPhase('dialog')
169
+ }}
170
+ onLater={later}
171
+ onNever={never}
172
+ />
173
+ {opened && (
174
+ <PollDialog
175
+ open={phase === 'dialog'}
176
+ cloudHints={cloudHints}
177
+ onClose={() => setPhase('done')}
178
+ onSubmitted={() => {
179
+ if (!preview) updateBrowserState({ submittedRound: CURRENT_ROUND.id })
180
+ }}
181
+ preview={preview}
182
+ previewSendFails={previewSendFails}
183
+ contactAllowed={preview || status.data?.contactAllowed === true}
184
+ />
185
+ )}
186
+ </>
187
+ )
188
+ }
189
+
190
+ function PollCard({ show,
191
+ onAccept,
192
+ onLater,
193
+ onNever,
194
+ }: {
195
+ show: boolean
196
+ onAccept: () => void
197
+ onLater: () => void
198
+ onNever: () => void
199
+ }) {
200
+ const { shouldRender, isOpen } = useAnimatedUnmount(show, overlayExitMs('menu'))
201
+ if (!shouldRender) return null
202
+ // Built like the usage-stats card, which uses the same corner.
203
+ return (
204
+ <div
205
+ role="dialog"
206
+ aria-labelledby="oss-poll-card-title"
207
+ aria-describedby="oss-poll-card-body"
208
+ inert={!show || undefined}
209
+ className={clsx(
210
+ 'fixed bottom-4 right-4 z-40 w-[21rem] max-w-[calc(100vw-2rem)] rounded-xl border border-theme-border bg-theme-surface shadow-theme-lg overflow-hidden origin-bottom-right',
211
+ TRANSITION_MENU,
212
+ isOpen ? 'opacity-100 translate-y-0 scale-100' : 'opacity-0 translate-y-1 scale-[0.97]',
213
+ !show && 'pointer-events-none',
214
+ )}
215
+ style={overlayTransitionStyle(isOpen, 'menu')}
216
+ >
217
+ <div className="relative flex gap-3 p-3.5 pr-9">
218
+ <button
219
+ type="button"
220
+ onClick={onLater}
221
+ aria-label="Close"
222
+ className="absolute top-2.5 right-2.5 p-1 rounded text-theme-text-tertiary hover:text-theme-text-primary hover:bg-theme-elevated"
223
+ >
224
+ <X className="w-3.5 h-3.5" />
225
+ </button>
226
+ <span className="flex items-center justify-center w-8 h-8 shrink-0 rounded-lg bg-accent-muted text-accent">
227
+ <MessageSquareHeart className="w-4 h-4" aria-hidden />
228
+ </span>
229
+ <div className="min-w-0">
230
+ <p id="oss-poll-card-title" className="text-sm font-medium text-theme-text-primary text-pretty">
231
+ {POLL_COPY.cardTitle}
232
+ </p>
233
+ <p id="oss-poll-card-body" className="mt-0.5 text-xs leading-relaxed text-theme-text-secondary">
234
+ {POLL_COPY.cardBody}
235
+ </p>
236
+ <div className="flex flex-wrap items-center gap-x-1 gap-y-1.5 mt-2.5">
237
+ <button
238
+ type="button"
239
+ onClick={onAccept}
240
+ className="btn-brand mr-1 px-3 py-1 text-xs font-medium rounded-md whitespace-nowrap"
241
+ >
242
+ {POLL_COPY.cardAccept}
243
+ </button>
244
+ <button
245
+ type="button"
246
+ onClick={onLater}
247
+ className="px-2 py-1 text-xs font-medium rounded-md whitespace-nowrap text-theme-text-secondary hover:text-theme-text-primary hover:bg-theme-elevated"
248
+ >
249
+ {POLL_COPY.cardLater}
250
+ </button>
251
+ <button
252
+ type="button"
253
+ onClick={onNever}
254
+ className="px-2 py-1 text-xs rounded-md whitespace-nowrap text-theme-text-tertiary hover:text-theme-text-primary hover:bg-theme-elevated"
255
+ >
256
+ {POLL_COPY.cardNever}
257
+ </button>
258
+ </div>
259
+ </div>
260
+ </div>
261
+ </div>
262
+ )
263
+ }
264
+
265
+ type SendState =
266
+ | { kind: 'idle' }
267
+ | { kind: 'sending' }
268
+ | { kind: 'failed'; message: string }
269
+ | { kind: 'closed' }
270
+
271
+ type ContactState = 'none' | 'ok' | 'failed' | 'resending'
272
+
273
+ function PollDialog({
274
+ open,
275
+ cloudHints,
276
+ onClose,
277
+ onSubmitted,
278
+ preview,
279
+ previewSendFails,
280
+ contactAllowed,
281
+ }: {
282
+ open: boolean
283
+ cloudHints: boolean
284
+ onClose: () => void
285
+ onSubmitted: () => void
286
+ preview: boolean
287
+ previewSendFails: boolean
288
+ contactAllowed: boolean
289
+ }) {
290
+ const [answers, setAnswers] = useState<PollAnswers>({})
291
+ const screens = useMemo(() => pollScreens(answers), [answers])
292
+ const [step, setStep] = useState(0)
293
+ const [phase, setPhase] = useState<'questions' | 'contact' | 'thanks'>('questions')
294
+ const [email, setEmail] = useState('')
295
+ const [emailMissing, setEmailMissing] = useState(false)
296
+ const [send, setSend] = useState<SendState>({ kind: 'idle' })
297
+ const [contact, setContact] = useState<ContactState>('none')
298
+ const [submitted, setSubmitted] = useState<PollAnswers>({})
299
+ // One order per person for the shuffled lists, fixed for the whole poll.
300
+ const [seed] = useState(() => Math.floor(Math.random() * 0x7fffffff))
301
+ // One id for the whole response, so every send updates the same one and a
302
+ // retry after a timeout can't be counted twice.
303
+ const submissionId = useRef(newSubmissionId())
304
+ // Answers go out as the person moves past each screen, so a poll left halfway
305
+ // still counts. Preview sends nothing.
306
+ // A 410 on any step means the round closed, so say so at once rather than
307
+ // at the end.
308
+ const sender = useMemo(
309
+ () => (preview ? null : createPollSender(submitPoll, submissionId.current, (err) => {
310
+ if (err instanceof PollSubmitError && err.status === 410) setSend({ kind: 'closed' })
311
+ })),
312
+ [preview],
313
+ )
314
+ const emailRef = useRef<HTMLInputElement>(null)
315
+
316
+ const screen = screens[Math.min(step, screens.length - 1)]
317
+ const setAnswer = (id: string, next: { choices?: string[]; text?: string }) =>
318
+ setAnswers((prev) => ({ ...prev, [id]: { ...prev[id], ...next } }))
319
+
320
+ const next = () => {
321
+ // Without the call step, the last screen's send is the finished one.
322
+ if (step + 1 >= screens.length && !contactAllowed) {
323
+ void finish(false)
324
+ return
325
+ }
326
+ sender?.progress(pruneAnswers(answers))
327
+ if (step + 1 < screens.length) setStep(step + 1)
328
+ else setPhase('contact')
329
+ }
330
+ const back = () => {
331
+ if (send.kind === 'failed') setSend({ kind: 'idle' })
332
+ if (phase === 'contact') {
333
+ setPhase('questions')
334
+ setStep(screens.length - 1)
335
+ } else if (step > 0) setStep(step - 1)
336
+ }
337
+
338
+ const trimmedEmail = email.trim()
339
+
340
+ const finish = async (withCall: boolean) => {
341
+ if (withCall && !looksLikeEmail(trimmedEmail)) {
342
+ setEmailMissing(true)
343
+ emailRef.current?.focus()
344
+ return
345
+ }
346
+ const clean = pruneAnswers(answers)
347
+ if (preview && previewSendFails) {
348
+ setSend({ kind: 'failed', message: POLL_COPY.sendFailed })
349
+ return
350
+ }
351
+ if (preview) {
352
+ console.info('[poll preview] would send', { answers: clean, email: withCall ? trimmedEmail : undefined })
353
+ setSubmitted(clean)
354
+ setContact(withCall ? 'ok' : 'none')
355
+ setPhase('thanks')
356
+ return
357
+ }
358
+ setSend({ kind: 'sending' })
359
+ try {
360
+ const result = await sender!.finish({
361
+ answers: clean,
362
+ ...(withCall ? { email: trimmedEmail, wantsCall: true } : {}),
363
+ })
364
+ setSubmitted(clean)
365
+ setContact(withCall ? (result.contact === 'ok' ? 'ok' : 'failed') : 'none')
366
+ setSend({ kind: 'idle' })
367
+ setPhase('thanks')
368
+ onSubmitted()
369
+ } catch (err) {
370
+ if (err instanceof PollSubmitError && err.status === 410) setSend({ kind: 'closed' })
371
+ else if (err instanceof PollSubmitError && err.status === 413) setSend({ kind: 'failed', message: POLL_COPY.tooLong })
372
+ else setSend({ kind: 'failed', message: POLL_COPY.sendFailed })
373
+ }
374
+ }
375
+
376
+ const resendContact = async () => {
377
+ setContact('resending')
378
+ try {
379
+ const result = await submitPoll({
380
+ submissionId: submissionId.current,
381
+ answers: {},
382
+ email: trimmedEmail,
383
+ wantsCall: true,
384
+ contactOnly: true,
385
+ })
386
+ setContact(result.contact === 'ok' ? 'ok' : 'failed')
387
+ } catch {
388
+ setContact('failed')
389
+ }
390
+ }
391
+
392
+ const titleId = 'oss-poll-dialog-title'
393
+ // The call step and the thank-you replace the button that had focus; move
394
+ // it to their heading so the new screen is announced.
395
+ useEffect(() => {
396
+ if (phase !== 'questions') document.getElementById(titleId)?.focus()
397
+ }, [phase])
398
+ const suggestion = answers.better?.text?.trim()
399
+
400
+ return (
401
+ <DialogPortal open={open} onClose={onClose} ariaLabelledBy={titleId} className="w-[600px] max-w-[calc(100vw-2rem)]">
402
+ <div className="relative flex flex-col max-h-[85vh]">
403
+ <button
404
+ type="button"
405
+ onClick={onClose}
406
+ aria-label="Close"
407
+ className="absolute top-4 right-4 p-1 rounded text-theme-text-tertiary hover:text-theme-text-primary hover:bg-theme-hover transition-colors"
408
+ >
409
+ <X className="w-4 h-4" />
410
+ </button>
411
+
412
+ {phase === 'questions' && screen && (
413
+ <>
414
+ <div className="px-7 pt-6 overflow-y-auto min-h-[min(22rem,55vh)]">
415
+ <div className="flex items-center gap-3 pr-8">
416
+ <p className="shrink-0 text-[11px] font-medium text-theme-text-tertiary tabular-nums">
417
+ {step + 1} of {screens.length}
418
+ </p>
419
+ <div className="h-1 flex-1 overflow-hidden rounded-full bg-theme-elevated" aria-hidden>
420
+ <div className="h-full rounded-full bg-accent" style={{ width: `${((step + 1) / screens.length) * 100}%` }} />
421
+ </div>
422
+ </div>
423
+ {step === 0 && <p className="mt-3 text-xs leading-relaxed text-theme-text-secondary">{POLL_COPY.intro}</p>}
424
+ <ScreenView
425
+ key={screen.id}
426
+ titleId={titleId}
427
+ screen={screen}
428
+ seed={seed}
429
+ answers={answers}
430
+ onChange={setAnswer}
431
+ />
432
+ {/* Without the call step, the last screen sends; say so if it can't. */}
433
+ {send.kind === 'failed' && (
434
+ <p className="mt-4 text-xs text-red-600 dark:text-red-400" role="alert">
435
+ {send.message}
436
+ </p>
437
+ )}
438
+ {send.kind === 'closed' && (
439
+ <p className="mt-4 text-xs text-theme-text-secondary" role="status">
440
+ {POLL_COPY.closed}
441
+ </p>
442
+ )}
443
+ </div>
444
+ <Footer
445
+ onBack={step > 0 && send.kind !== 'sending' ? back : undefined}
446
+ primary={
447
+ send.kind === 'closed'
448
+ ? { label: POLL_COPY.done, onClick: onClose }
449
+ : {
450
+ label: step + 1 < screens.length || contactAllowed ? POLL_COPY.next : send.kind === 'sending' ? POLL_COPY.sending : POLL_COPY.finish,
451
+ onClick: next,
452
+ disabled: send.kind === 'sending',
453
+ }
454
+ }
455
+ />
456
+ </>
457
+ )}
458
+
459
+ {phase === 'contact' && (
460
+ <>
461
+ <div className="px-7 pt-6 overflow-y-auto min-h-[min(22rem,55vh)]">
462
+ {/* Same header row as the questions, so the last step doesn't look detached. */}
463
+ <div className="flex items-center gap-3 pr-8 mb-4">
464
+ <p className="shrink-0 text-[11px] font-medium text-theme-text-tertiary">{POLL_COPY.almostDone}</p>
465
+ <div className="h-1 flex-1 overflow-hidden rounded-full bg-accent" aria-hidden />
466
+ </div>
467
+ {suggestion ? (
468
+ <>
469
+ <p className="text-sm text-theme-text-secondary">{POLL_COPY.contactYouWrote}</p>
470
+ <p className="mt-1.5 pl-3 border-l-2 border-theme-border text-sm italic text-theme-text-primary line-clamp-3">
471
+ “{suggestion}”
472
+ </p>
473
+ <p className="mt-3 text-sm text-theme-text-secondary">{POLL_COPY.contactMore}</p>
474
+ <h3 id={titleId} tabIndex={-1} className="outline-none mt-1 text-base font-semibold text-theme-text-primary">
475
+ {POLL_COPY.contactAsk}
476
+ </h3>
477
+ <p className="mt-1 text-sm text-theme-text-secondary">{POLL_COPY.contactNotSales}</p>
478
+ </>
479
+ ) : (
480
+ <>
481
+ <h3 id={titleId} tabIndex={-1} className="outline-none text-base font-semibold text-theme-text-primary pr-8">
482
+ {POLL_COPY.contactAsk}
483
+ </h3>
484
+ <p className="mt-1.5 text-sm text-theme-text-secondary">{POLL_COPY.contactBody}</p>
485
+ </>
486
+ )}
487
+ <label className="block mt-5 text-sm font-medium text-theme-text-primary" htmlFor="oss-poll-email">
488
+ {POLL_COPY.emailLabel}
489
+ </label>
490
+ <input
491
+ ref={emailRef}
492
+ id="oss-poll-email"
493
+ type="email"
494
+ autoComplete="email"
495
+ placeholder={POLL_COPY.emailPlaceholder}
496
+ value={email}
497
+ onChange={(e) => {
498
+ setEmail(e.target.value)
499
+ if (emailMissing && looksLikeEmail(e.target.value)) setEmailMissing(false)
500
+ }}
501
+ aria-describedby="oss-poll-email-help"
502
+ aria-invalid={emailMissing || undefined}
503
+ className="mt-1.5 w-full rounded-md border border-theme-border bg-theme-base px-3 py-2 text-sm text-theme-text-primary placeholder:text-theme-text-tertiary focus:outline-none focus:ring-2 focus:ring-accent/40"
504
+ />
505
+ <p id="oss-poll-email-help" className="mt-1.5 text-xs text-theme-text-secondary">
506
+ {POLL_COPY.emailHelp}
507
+ </p>
508
+ {emailMissing && (
509
+ <p className="mt-2 text-xs text-warning-text" role="alert">
510
+ {POLL_COPY.emailNeeded}
511
+ </p>
512
+ )}
513
+ {send.kind === 'failed' && (
514
+ <p className="mt-4 text-xs text-red-600 dark:text-red-400" role="alert">
515
+ {send.message}
516
+ </p>
517
+ )}
518
+ {send.kind === 'closed' && (
519
+ <p className="mt-4 text-xs text-theme-text-secondary" role="status">
520
+ {POLL_COPY.closed}
521
+ </p>
522
+ )}
523
+ </div>
524
+ <div className="flex items-center justify-between gap-3 px-7 py-4 mt-5 border-t border-theme-border">
525
+ {send.kind === 'sending' ? (
526
+ <span className="text-sm text-theme-text-secondary">{POLL_COPY.sending}</span>
527
+ ) : (
528
+ <button
529
+ type="button"
530
+ onClick={back}
531
+ className="inline-flex items-center gap-1.5 -ml-1 px-1 py-1.5 text-sm text-theme-text-secondary hover:text-theme-text-primary transition-colors"
532
+ >
533
+ <ArrowLeft className="w-3.5 h-3.5" /> {POLL_COPY.back}
534
+ </button>
535
+ )}
536
+ {send.kind === 'closed' ? (
537
+ <button type="button" onClick={onClose} className="btn-brand text-sm font-medium px-4 py-1.5">
538
+ {POLL_COPY.done}
539
+ </button>
540
+ ) : (
541
+ <div className="flex items-center gap-2">
542
+ <button type="button" onClick={() => finish(false)} disabled={send.kind === 'sending'} className={CONTACT_BUTTON}>
543
+ {POLL_COPY.contactNo}
544
+ </button>
545
+ <button type="button" onClick={() => finish(true)} disabled={send.kind === 'sending'} className={CONTACT_BUTTON}>
546
+ {POLL_COPY.contactYes}
547
+ </button>
548
+ </div>
549
+ )}
550
+ </div>
551
+ </>
552
+ )}
553
+
554
+ {phase === 'thanks' && (
555
+ <ThankYou
556
+ titleId={titleId}
557
+ preview={preview}
558
+ line={closingLine(submitted, cloudHints)}
559
+ contact={contact}
560
+ onResendContact={resendContact}
561
+ onClose={onClose}
562
+ open={open}
563
+ />
564
+ )}
565
+ </div>
566
+ </DialogPortal>
567
+ )
568
+ }
569
+
570
+ // Two answers of equal weight: neither is the "right" one.
571
+ const CONTACT_BUTTON =
572
+ 'px-3.5 py-1.5 text-sm font-medium rounded-md border border-theme-border text-theme-text-primary bg-theme-surface hover:bg-theme-hover whitespace-nowrap transition-colors disabled:opacity-60'
573
+
574
+ function Footer({
575
+ onBack,
576
+ primary,
577
+ }: {
578
+ onBack?: () => void
579
+ primary: { label: string; onClick: () => void; disabled?: boolean }
580
+ }) {
581
+ return (
582
+ <div className="flex items-center justify-between gap-3 px-7 py-4 mt-5 border-t border-theme-border">
583
+ {onBack ? (
584
+ <button
585
+ type="button"
586
+ onClick={onBack}
587
+ className="inline-flex items-center gap-1.5 -ml-1 px-1 py-1.5 text-sm text-theme-text-secondary hover:text-theme-text-primary transition-colors"
588
+ >
589
+ <ArrowLeft className="w-3.5 h-3.5" /> {POLL_COPY.back}
590
+ </button>
591
+ ) : (
592
+ <span />
593
+ )}
594
+ <div className="flex items-center gap-2">
595
+ <button type="button" onClick={primary.onClick} disabled={primary.disabled} className="btn-brand text-sm font-medium px-4 py-1.5 whitespace-nowrap disabled:opacity-60">
596
+ {primary.label}
597
+ </button>
598
+ </div>
599
+ </div>
600
+ )
601
+ }
602
+
603
+ function ScreenView({
604
+ titleId,
605
+ screen,
606
+ seed,
607
+ answers,
608
+ onChange,
609
+ }: {
610
+ titleId: string
611
+ screen: PollScreen
612
+ seed: number
613
+ answers: PollAnswers
614
+ onChange: (id: string, next: { choices?: string[]; text?: string }) => void
615
+ }) {
616
+ const headingRef = useRef<HTMLHeadingElement>(null)
617
+ // A new screen: move focus to its heading so screen readers announce it
618
+ // instead of staying on the Next button.
619
+ useEffect(() => {
620
+ headingRef.current?.focus()
621
+ }, [])
622
+ const grouped = screen.questions.length > 1
623
+ return (
624
+ <div className="mt-3">
625
+ {screen.title && (
626
+ <h3 ref={headingRef} tabIndex={-1} id={titleId} className="text-base font-semibold text-theme-text-primary pr-8 outline-none">
627
+ {screen.title}
628
+ </h3>
629
+ )}
630
+ {screen.questions.map((q, i) => (
631
+ <QuestionView
632
+ key={q.id}
633
+ headingRef={!screen.title && i === 0 ? headingRef : undefined}
634
+ titleId={!screen.title && i === 0 ? titleId : undefined}
635
+ question={q}
636
+ seed={seed}
637
+ compact={grouped && !!screen.title}
638
+ first={i === 0}
639
+ answer={answers[q.id]}
640
+ onChange={(a) => onChange(q.id, a)}
641
+ />
642
+ ))}
643
+ </div>
644
+ )
645
+ }
646
+
647
+ function QuestionView({
648
+ headingRef,
649
+ titleId,
650
+ question,
651
+ seed,
652
+ compact,
653
+ first,
654
+ answer,
655
+ onChange,
656
+ }: {
657
+ headingRef?: React.RefObject<HTMLHeadingElement | null>
658
+ titleId?: string
659
+ question: PollQuestion
660
+ seed: number
661
+ compact: boolean
662
+ first: boolean
663
+ answer: { choices?: string[]; text?: string } | undefined
664
+ onChange: (next: { choices?: string[]; text?: string }) => void
665
+ }) {
666
+ const options = orderedOptions(question, seed)
667
+ const chosen = answer?.choices ?? []
668
+ const showText =
669
+ question.kind === 'text' || (question.textOption !== undefined && chosen.includes(question.textOption))
670
+ const inputType = question.kind === 'single' ? 'radio' : 'checkbox'
671
+ const legendId = `${question.id}-legend`
672
+
673
+ return (
674
+ <fieldset className={clsx(compact ? (first ? 'mt-4' : 'mt-5') : first ? 'mt-0' : 'mt-6')} aria-labelledby={titleId ?? legendId}>
675
+ {headingRef ? (
676
+ <h3 ref={headingRef} tabIndex={-1} id={titleId} className="text-base font-semibold text-theme-text-primary pr-8 outline-none">
677
+ {question.title}
678
+ </h3>
679
+ ) : (
680
+ <p id={legendId} className={clsx(compact ? 'text-sm font-medium text-theme-text-primary' : 'text-base font-semibold text-theme-text-primary pr-8')}>
681
+ {question.title}
682
+ </p>
683
+ )}
684
+ {question.hint && <p className="mt-1 text-xs text-theme-text-tertiary">{question.hint}</p>}
685
+
686
+ {options.length > 0 && (
687
+ <div className={clsx(compact ? 'mt-2 grid grid-cols-2 gap-1.5' : 'mt-4 space-y-1.5')}>
688
+ {options.map((o) => {
689
+ const checked = chosen.includes(o.id)
690
+ return (
691
+ <label
692
+ key={o.id}
693
+ className={clsx(
694
+ 'flex items-start gap-2.5 rounded-md border px-3 py-2 text-sm cursor-pointer transition-colors',
695
+ checked
696
+ ? 'border-accent/60 bg-accent-muted text-theme-text-primary'
697
+ : 'border-theme-border text-theme-text-secondary hover:bg-theme-hover hover:text-theme-text-primary',
698
+ )}
699
+ >
700
+ <input
701
+ type={inputType}
702
+ name={question.id}
703
+ checked={checked}
704
+ onChange={() => onChange({ choices: toggleChoice(question, chosen, o.id) })}
705
+ // A checked radio fires no change when clicked again; this is
706
+ // what lets an optional single-choice answer be cleared.
707
+ onClick={() => {
708
+ if (question.kind === 'single' && checked) onChange({ choices: [] })
709
+ }}
710
+ className="mt-0.5 accent-skyhook-600"
711
+ />
712
+ <span>{o.label}</span>
713
+ </label>
714
+ )
715
+ })}
716
+ </div>
717
+ )}
718
+
719
+ {showText && (
720
+ <div className="mt-3">
721
+ {question.kind !== 'text' && (
722
+ <label htmlFor={`${question.id}-text`} className="block text-sm font-medium text-theme-text-primary mb-1.5">
723
+ {POLL_COPY.otherPlaceholder}
724
+ </label>
725
+ )}
726
+ <textarea
727
+ id={`${question.id}-text`}
728
+ aria-label={question.kind === 'text' ? question.title : undefined}
729
+ value={answer?.text ?? ''}
730
+ maxLength={2000}
731
+ rows={question.kind === 'text' ? 4 : 2}
732
+ placeholder={question.textPlaceholder}
733
+ onChange={(e) => onChange({ text: e.target.value })}
734
+ className="w-full resize-y rounded-md border border-theme-border bg-theme-base px-3 py-2 text-sm text-theme-text-primary placeholder:text-theme-text-tertiary focus:outline-none focus:ring-2 focus:ring-accent/40"
735
+ />
736
+ </div>
737
+ )}
738
+ </fieldset>
739
+ )
740
+ }
741
+
742
+ function ThankYou({
743
+ titleId,
744
+ preview,
745
+ line,
746
+ contact,
747
+ onResendContact,
748
+ onClose,
749
+ open,
750
+ }: {
751
+ titleId: string
752
+ preview: boolean
753
+ line: ClosingLine
754
+ contact: ContactState
755
+ onResendContact: () => void
756
+ onClose: () => void
757
+ open: boolean
758
+ }) {
759
+ return (
760
+ <>
761
+ <div className="px-7 pt-6 overflow-y-auto space-y-4">
762
+ <h3 id={titleId} tabIndex={-1} className="outline-none text-base font-semibold text-theme-text-primary pr-8">
763
+ {POLL_COPY.thanks}
764
+ </h3>
765
+ {preview && <p className="text-xs text-theme-text-tertiary">Preview: nothing was sent.</p>}
766
+
767
+ {contact === 'failed' || contact === 'resending' ? (
768
+ <div className="text-sm text-theme-text-secondary">
769
+ <p>{POLL_COPY.contactFailed}</p>
770
+ <button
771
+ type="button"
772
+ onClick={onResendContact}
773
+ disabled={contact === 'resending'}
774
+ className="mt-1.5 text-sm text-accent underline underline-offset-2 disabled:opacity-60"
775
+ >
776
+ {contact === 'resending' ? POLL_COPY.sending : POLL_COPY.contactRetry}
777
+ </button>
778
+ </div>
779
+ ) : null}
780
+
781
+ {line?.kind === 'enough' && <p className="text-sm text-theme-text-secondary">{POLL_COPY.enough}</p>}
782
+ {line && line.kind !== 'enough' && <CloudPointerLine line={line} onOpen={onClose} glow={open} />}
783
+ </div>
784
+ <Footer primary={{ label: POLL_COPY.done, onClick: onClose }} />
785
+ </>
786
+ )
787
+ }
788
+
789
+ type CloudReply = Exclude<ClosingLine, null | { kind: 'enough' }>
790
+
791
+ const POINTER_LEADS = {
792
+ first_heard: POLL_COPY.pointerLeadFirstHeard,
793
+ heard: POLL_COPY.pointerLeadHeard,
794
+ looked: POLL_COPY.pointerLeadLooked,
795
+ } as const
796
+
797
+ // One sentence that answers what the person said, then a pointer at the
798
+ // header's Radar Cloud button, which glows while this screen is up.
799
+ function CloudPointerLine({ line, onOpen, glow }: { line: CloudReply; onOpen: () => void; glow: boolean }) {
800
+ const text =
801
+ line.kind === 'self_host'
802
+ ? POLL_COPY.selfHost
803
+ : line.kind === 'free_tier'
804
+ ? POLL_COPY.freeTier
805
+ : line.lead
806
+ ? `${POINTER_LEADS[line.lead]} ${POLL_COPY.pointerWhat}`
807
+ : POLL_COPY.pointerWhat
808
+ const open = () => {
809
+ onOpen()
810
+ openCloudFromPoll(line.kind === 'self_host' ? 'self-managed' : 'pitch')
811
+ }
812
+ return (
813
+ <div className="pt-4 border-t border-theme-border text-sm text-theme-text-secondary">
814
+ <p>{text}</p>
815
+ <button
816
+ type="button"
817
+ onClick={open}
818
+ className="mt-2 inline-flex items-center gap-1.5 text-left text-theme-text-primary hover:underline underline-offset-2"
819
+ >
820
+ <Cloud className="w-3.5 h-3.5 shrink-0 text-emerald-500" aria-hidden />
821
+ {POLL_COPY.pointerWhere}
822
+ </button>
823
+ {glow && <CloudButtonGlow onOpen={open} />}
824
+ </div>
825
+ )
826
+ }
827
+
828
+ // Draws over the header's Radar Cloud button, above the dialog's dimmed
829
+ // backdrop, so the real button reads clearly and glows in Radar's green.
830
+ // Clicking it opens the Radar Cloud dialog, as the button itself would.
831
+ // Nothing renders where the button doesn't exist (hints off, embedded).
832
+ function CloudButtonGlow({ onOpen }: { onOpen: () => void }) {
833
+ const [rect, setRect] = useState<DOMRect | null>(null)
834
+ useLayoutEffect(() => {
835
+ const el = document.querySelector('[data-radar-cloud-button]')
836
+ if (!el) return
837
+ const measure = () => {
838
+ const r = el.getBoundingClientRect()
839
+ // A hidden button has no size; there is nothing to point at.
840
+ setRect(r.width > 0 && r.height > 0 ? r : null)
841
+ }
842
+ measure()
843
+ const observer = new ResizeObserver(measure)
844
+ observer.observe(el)
845
+ observer.observe(document.body)
846
+ window.addEventListener('resize', measure)
847
+ return () => {
848
+ observer.disconnect()
849
+ window.removeEventListener('resize', measure)
850
+ }
851
+ }, [])
852
+ if (!rect) return null
853
+ // aria-hidden and out of the tab order: the line in the dialog is the
854
+ // accessible way to the same action.
855
+ return createPortal(
856
+ <div aria-hidden className="fixed z-[60]" style={{ top: rect.top, left: rect.left, width: rect.width, height: rect.height }}>
857
+ <span className="cloud-glow-halo pointer-events-none absolute -inset-3 rounded-2xl bg-emerald-400/60 blur-lg" />
858
+ <span className="cloud-glow-ring pointer-events-none absolute -inset-1 rounded-lg ring-2 ring-emerald-400" />
859
+ <button
860
+ type="button"
861
+ tabIndex={-1}
862
+ onClick={onOpen}
863
+ className="relative flex items-center justify-center w-full h-full rounded-md bg-theme-surface text-emerald-600 dark:text-emerald-400 ring-2 ring-emerald-500 shadow-theme-lg"
864
+ >
865
+ <Cloud className="w-4 h-4" />
866
+ </button>
867
+ </div>,
868
+ document.body,
869
+ )
870
+ }
871
+