ErrorMatcher.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. 'use client'
  2. import { ErrorDisplay, SupportFormParams } from 'ui-patterns/ErrorDisplay/ErrorDisplay'
  3. import { getMappingForError } from './ErrorMatcher.utils'
  4. import { useTrack } from '@/lib/telemetry/track'
  5. interface ErrorMatcherProps {
  6. title: string
  7. error: string | { message: string }
  8. supportFormParams?: SupportFormParams
  9. className?: string
  10. }
  11. export function ErrorMatcher({ title, error, supportFormParams, className }: ErrorMatcherProps) {
  12. const track = useTrack()
  13. const message = typeof error === 'string' ? error : error.message
  14. const mapping = getMappingForError(error)
  15. const Troubleshooting = mapping?.Troubleshooting
  16. return (
  17. <ErrorDisplay
  18. title={title}
  19. errorMessage={message}
  20. supportFormParams={supportFormParams}
  21. className={className}
  22. onRender={() => {
  23. track('dashboard_error_created', {
  24. source: 'error_display',
  25. errorType: mapping?.id,
  26. hasTroubleshooting: !!mapping,
  27. })
  28. if (mapping) {
  29. track('inline_error_troubleshooter_exposed', { errorType: mapping.id })
  30. }
  31. }}
  32. onSupportClick={
  33. mapping
  34. ? () =>
  35. track('inline_error_troubleshooter_action_clicked', {
  36. errorType: mapping.id,
  37. ctaType: 'contact_support',
  38. })
  39. : undefined
  40. }
  41. >
  42. {Troubleshooting && <Troubleshooting />}
  43. </ErrorDisplay>
  44. )
  45. }