feedbackWidget.tsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import {useEffect} from 'react';
  2. import {css, Global} from '@emotion/react';
  3. import {Feedback, getCurrentHub} from '@sentry/react';
  4. import ConfigStore from 'sentry/stores/configStore';
  5. import {useLegacyStore} from 'sentry/stores/useLegacyStore';
  6. import theme from 'sentry/utils/theme';
  7. /**
  8. * Use this to display the Feedback widget in certain routes/components
  9. */
  10. export default function FeedbackWidget() {
  11. const config = useLegacyStore(ConfigStore);
  12. const widgetTheme = config.theme === 'dark' ? 'dark' : 'light';
  13. useEffect(() => {
  14. const hub = getCurrentHub();
  15. const feedback = hub.getIntegration(Feedback);
  16. const widget = feedback?.createWidget({
  17. colorScheme: widgetTheme,
  18. buttonLabel: 'Give Feedback',
  19. submitButtonLabel: 'Send Feedback',
  20. messagePlaceholder: 'What did you expect?',
  21. formTitle: 'Give Feedback',
  22. });
  23. return () => {
  24. feedback?.removeWidget(widget);
  25. };
  26. }, [widgetTheme]);
  27. // z-index needs to be below our indicators which is 10001
  28. return (
  29. <Global
  30. styles={css`
  31. #sentry-feedback {
  32. --z-index: ${theme.zIndex.toast - 1};
  33. }
  34. `}
  35. />
  36. );
  37. }