SingleStat.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // @ts-nocheck
  2. import Link from 'next/link'
  3. import type { ReactNode } from 'react'
  4. import { cn } from 'ui'
  5. import { useSendEventMutation } from '@/data/telemetry/send-event-mutation'
  6. import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
  7. import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
  8. type SingleStatProps = {
  9. icon: ReactNode
  10. label: ReactNode
  11. value: ReactNode
  12. className?: string
  13. href?: string
  14. onClick?: () => void
  15. trackingProperties?: {
  16. stat_type: 'migrations' | 'backups' | 'branches'
  17. stat_value: number
  18. }
  19. }
  20. export const SingleStat = ({
  21. icon,
  22. label,
  23. value,
  24. className,
  25. href,
  26. onClick,
  27. trackingProperties,
  28. }: SingleStatProps) => {
  29. const { mutate: sendEvent } = useSendEventMutation()
  30. const { data: project } = useSelectedProjectQuery()
  31. const { data: organization } = useSelectedOrganizationQuery()
  32. const trackActivityStat = () => {
  33. if (trackingProperties && project?.ref && organization?.slug) {
  34. sendEvent({
  35. action: 'home_activity_stat_clicked',
  36. properties: trackingProperties,
  37. groups: {
  38. project: project.ref,
  39. organization: organization.slug,
  40. },
  41. })
  42. }
  43. }
  44. const content = (
  45. <div className={cn('group flex items-center gap-4 p-0 text-base justify-start', className)}>
  46. <div className="min-w-16 w-16 h-16 rounded-md bg-surface-75 group-hover:bg-muted border flex items-center justify-center">
  47. {icon}
  48. </div>
  49. <div className="truncate">
  50. <div className="text-left heading-meta text-foreground-light">{label}</div>
  51. <div className="text-foreground truncate h-[34px] flex items-center capitalize-sentence">
  52. {value}
  53. </div>
  54. </div>
  55. </div>
  56. )
  57. if (href) {
  58. return (
  59. <Link className="group block" href={href} onClick={trackActivityStat}>
  60. {content}
  61. </Link>
  62. )
  63. }
  64. if (onClick) {
  65. return (
  66. <button className="group" onClick={onClick}>
  67. {content}
  68. </button>
  69. )
  70. }
  71. return content
  72. }