ProjectUsageSection.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { AlertCircle } from 'lucide-react'
  2. import ProjectUsage from './ProjectUsage'
  3. import { ProjectUsageLoadingState } from '@/components/layouts/ProjectLayout/LoadingState'
  4. import InformationBox from '@/components/ui/InformationBox'
  5. import { useProjectLogRequestsCountQuery } from '@/data/analytics/project-log-requests-count-query'
  6. import { useProjectLogStatsQuery } from '@/data/analytics/project-log-stats-query'
  7. import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
  8. export const ProjectUsageSection = () => {
  9. const { data: project } = useSelectedProjectQuery()
  10. const { error, isPending: isLoading } = useProjectLogRequestsCountQuery({
  11. projectRef: project?.ref,
  12. })
  13. // wait for the stats to load before showing the usage section to eliminate multiple spinners
  14. const { isPending: isLogsStatsLoading } = useProjectLogStatsQuery({
  15. projectRef: project?.ref,
  16. interval: '1hr',
  17. })
  18. if (isLoading || isLogsStatsLoading) {
  19. return <ProjectUsageLoadingState />
  20. }
  21. if (error) {
  22. return (
  23. <InformationBox
  24. hideCollapse
  25. defaultVisibility
  26. icon={<AlertCircle size={18} strokeWidth={2} />}
  27. title="There was an issue loading the usage details of your project"
  28. />
  29. )
  30. }
  31. return <ProjectUsage />
  32. }