cronsFeedbackButton.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import {useEffect, useRef} from 'react';
  2. import {BrowserClient, getCurrentHub} from '@sentry/react';
  3. import {Feedback} from '@sentry-internal/feedback';
  4. import {Button} from 'sentry/components/button';
  5. import {IconMegaphone} from 'sentry/icons/iconMegaphone';
  6. import ConfigStore from 'sentry/stores/configStore';
  7. import {useLegacyStore} from 'sentry/stores/useLegacyStore';
  8. function CronsFeedbackButton() {
  9. const config = useLegacyStore(ConfigStore);
  10. const ref = useRef(null);
  11. const title = 'Give Feedback';
  12. const widgetTheme = config.theme === 'dark' ? 'dark' : 'light';
  13. const hub = getCurrentHub();
  14. const client = hub && hub.getClient<BrowserClient>();
  15. const feedback = client?.getIntegration(Feedback);
  16. useEffect(() => {
  17. const widget =
  18. ref.current &&
  19. feedback?.attachTo(ref.current, {
  20. colorScheme: widgetTheme,
  21. formTitle: title,
  22. submitButtonLabel: 'Send Feedback',
  23. messagePlaceholder: 'What did you expect?',
  24. });
  25. return () => {
  26. if (widget && feedback) {
  27. feedback.removeWidget(widget);
  28. }
  29. };
  30. }, [widgetTheme, feedback]);
  31. // Do not show button if Feedback integration is not enabled
  32. if (!feedback) {
  33. return null;
  34. }
  35. return (
  36. <Button ref={ref} data-feedback="crons" size="sm" icon={<IconMegaphone />}>
  37. {title}
  38. </Button>
  39. );
  40. }
  41. export default CronsFeedbackButton;