cronsFeedbackButton.tsx 1.2 KB

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