ReportChartUpsell.tsx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import Link from 'next/link'
  2. import { useRef, useState } from 'react'
  3. import { Button, Card, cn } from 'ui'
  4. import { LazyComposedChartHandler } from '@/components/ui/Charts/ComposedChartHandler'
  5. interface ReportsChartUpsellProps {
  6. report: {
  7. label: string
  8. requiredPlan?: string
  9. }
  10. orgSlug: string
  11. }
  12. export const ReportChartUpsell = ({ report, orgSlug }: ReportsChartUpsellProps) => {
  13. const startDate = '2025-01-01'
  14. const endDate = '2025-01-02'
  15. const [isHoveringUpgrade, setIsHoveringUpgrade] = useState(false)
  16. const getExpDemoChartData = () =>
  17. new Array(20).fill(0).map((_, index) => ({
  18. period_start: new Date(startDate).getTime() + index * 1000,
  19. demo: Math.floor(Math.pow(1.25, index) * 10),
  20. max_demo: 1000,
  21. }))
  22. const getDemoChartData = () =>
  23. new Array(20).fill(0).map((_, index) => ({
  24. period_start: new Date(startDate).getTime() + index * 1000,
  25. demo: Math.floor(Math.random() * 10) + 1,
  26. max_demo: 1000,
  27. }))
  28. const demoChartData = useRef(getDemoChartData())
  29. const exponentialChartData = useRef(getExpDemoChartData())
  30. const demoData = isHoveringUpgrade ? exponentialChartData.current : demoChartData.current
  31. return (
  32. <Card className={cn('h-[280px] relative')}>
  33. <div className="z-10 flex flex-col items-center justify-center space-y-2 h-full absolute top-0 left-0 w-full bg-surface-100/70 backdrop-blur-md">
  34. <h2 className="text-sm">{report.label}</h2>
  35. <p className="text-sm text-foreground-light">
  36. {report.requiredPlan
  37. ? `Available on the ${report.requiredPlan} Plan and above`
  38. : `Your plan does not include access to ${report.label}`}
  39. </p>
  40. <Button
  41. asChild
  42. type="primary"
  43. onMouseEnter={() => setIsHoveringUpgrade(true)}
  44. onMouseLeave={() => setIsHoveringUpgrade(false)}
  45. className="mt-4"
  46. >
  47. <Link href={`/org/${orgSlug || '_'}/billing?panel=subscriptionPlan&source=reports`}>
  48. {report.requiredPlan ? `Upgrade to ${report.requiredPlan}` : 'Upgrade'}
  49. </Link>
  50. </Button>
  51. </div>
  52. <div className="absolute top-0 left-0 w-full h-full z-0">
  53. <LazyComposedChartHandler
  54. attributes={[
  55. {
  56. attribute: 'demo',
  57. enabled: true,
  58. label: 'Demo',
  59. provider: 'logs',
  60. },
  61. ]}
  62. label="Sample Report"
  63. startDate={startDate}
  64. endDate={endDate}
  65. data={demoData as any}
  66. isLoading={false}
  67. highlightedValue={0}
  68. updateDateRange={() => {}}
  69. />
  70. </div>
  71. </Card>
  72. )
  73. }