APIDocsButton.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // @ts-nocheck
  2. import { useParams } from 'common'
  3. import { BookOpenText } from 'lucide-react'
  4. import { ButtonTooltip } from './ButtonTooltip'
  5. import { useSendEventMutation } from '@/data/telemetry/send-event-mutation'
  6. import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
  7. import { useAppStateSnapshot } from '@/state/app-state'
  8. interface APIDocsButtonProps {
  9. section?: string[]
  10. source: string
  11. label?: string
  12. tooltip?: string
  13. }
  14. export const APIDocsButton = ({ section, source, label, tooltip }: APIDocsButtonProps) => {
  15. const snap = useAppStateSnapshot()
  16. const { ref } = useParams()
  17. const { data: org } = useSelectedOrganizationQuery()
  18. const { mutate: sendEvent } = useSendEventMutation()
  19. return (
  20. <ButtonTooltip
  21. size="tiny"
  22. type="default"
  23. onClick={() => {
  24. if (section) snap.setActiveDocsSection(section)
  25. snap.setShowProjectApiDocs(true)
  26. sendEvent({
  27. action: 'api_docs_opened',
  28. properties: {
  29. source,
  30. },
  31. groups: {
  32. project: ref ?? 'Unknown',
  33. organization: org?.slug ?? 'Unknown',
  34. },
  35. })
  36. }}
  37. icon={<BookOpenText />}
  38. className={label ? undefined : 'w-7'}
  39. tooltip={{
  40. content: {
  41. side: 'bottom',
  42. text: tooltip ?? 'API Docs',
  43. },
  44. }}
  45. >
  46. {label}
  47. </ButtonTooltip>
  48. )
  49. }