TroubleshootingAccordion.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. 'use client'
  2. import { ReactNode } from 'react'
  3. import { Accordion, cn } from 'ui'
  4. import { useTrack } from '@/lib/telemetry/track'
  5. interface TroubleshootingAccordionProps {
  6. children: ReactNode
  7. /** Error mapping ID — used for telemetry */
  8. errorType: string
  9. /** Step titles keyed by step number — used for telemetry */
  10. stepTitles?: Record<number, string>
  11. /** Which step to expand by default (1-indexed), defaults to 1 */
  12. defaultExpandedStep?: number
  13. className?: string
  14. }
  15. export function TroubleshootingAccordion({
  16. children,
  17. errorType,
  18. stepTitles,
  19. defaultExpandedStep = 1,
  20. className,
  21. }: TroubleshootingAccordionProps) {
  22. const track = useTrack()
  23. const defaultValue = defaultExpandedStep > 0 ? `step-${defaultExpandedStep}` : undefined
  24. return (
  25. <Accordion
  26. type="single"
  27. collapsible
  28. defaultValue={defaultValue}
  29. className={cn('w-full', className)}
  30. onValueChange={(value) => {
  31. const expanded = Boolean(value)
  32. const step = expanded ? parseInt(value.replace('step-', ''), 10) : null
  33. track('inline_error_troubleshooter_step_clicked', {
  34. errorType,
  35. step,
  36. stepTitle: step !== null ? stepTitles?.[step] : undefined,
  37. expanded,
  38. })
  39. }}
  40. >
  41. {children}
  42. </Accordion>
  43. )
  44. }