error-assistant-ai-paywall-notification.tsx 894 B

123456789101112131415161718192021222324252627282930
  1. import { useCallback, useEffect, useState } from 'react'
  2. import AiPaywallNotification from '@/shared/components/ai-paywall-notification'
  3. import { useDetachCompileContext as useCompileContext } from '@/shared/context/detach-compile-context'
  4. import useEventListener from '@/shared/hooks/use-event-listener'
  5. export default function ErrorAssistantAiPaywallNotification() {
  6. const { showLogs } = useCompileContext()
  7. const [hasTriggered, setHasTriggered] = useState(false)
  8. useEventListener(
  9. 'aiAssist:showPaywall',
  10. useCallback((event: CustomEvent<{ origin?: string }>) => {
  11. if (event.detail?.origin === 'suggest-fix') {
  12. setHasTriggered(true)
  13. }
  14. }, [])
  15. )
  16. useEffect(() => {
  17. if (!showLogs) {
  18. setHasTriggered(false)
  19. }
  20. }, [showLogs])
  21. if (!hasTriggered) {
  22. return null
  23. }
  24. return <AiPaywallNotification featureLocation="errorAssist" />
  25. }