userFeedbackEmpty.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import {useEffect} from 'react';
  2. import styled from '@emotion/styled';
  3. import * as Sentry from '@sentry/react';
  4. import emptyStateImg from 'sentry-images/spot/feedback-empty-state.svg';
  5. import {Button} from 'sentry/components/button';
  6. import ButtonBar from 'sentry/components/buttonBar';
  7. import EmptyStateWarning from 'sentry/components/emptyStateWarning';
  8. import OnboardingPanel from 'sentry/components/onboardingPanel';
  9. import {t} from 'sentry/locale';
  10. import {trackAnalytics} from 'sentry/utils/analytics';
  11. import useOrganization from 'sentry/utils/useOrganization';
  12. import useProjects from 'sentry/utils/useProjects';
  13. type Props = {
  14. projectIds?: string[];
  15. };
  16. export function UserFeedbackEmpty({projectIds}: Props) {
  17. const {projects, initiallyLoaded} = useProjects();
  18. const loadingProjects = !initiallyLoaded;
  19. const organization = useOrganization();
  20. const selectedProjects =
  21. projectIds && projectIds.length
  22. ? projects.filter(({id}) => projectIds.includes(id))
  23. : projects;
  24. const hasAnyFeedback = selectedProjects.some(({hasUserReports}) => hasUserReports);
  25. useEffect(() => {
  26. window.sentryEmbedCallback = function (embed) {
  27. // Mock the embed's submit xhr to always be successful
  28. // NOTE: this will not have errors if the form is empty
  29. embed.submit = function (_body) {
  30. this._submitInProgress = true;
  31. setTimeout(() => {
  32. this._submitInProgress = false;
  33. this.onSuccess();
  34. }, 500);
  35. };
  36. };
  37. if (hasAnyFeedback === false) {
  38. // send to reload only due to higher event volume
  39. trackAnalytics('user_feedback.viewed', {
  40. organization,
  41. projects: projectIds?.join(',') || '',
  42. });
  43. }
  44. return () => {
  45. window.sentryEmbedCallback = null;
  46. };
  47. }, [hasAnyFeedback, organization, projectIds]);
  48. function trackAnalyticsInternal(
  49. eventKey: 'user_feedback.docs_clicked' | 'user_feedback.dialog_opened'
  50. ) {
  51. trackAnalytics(eventKey, {
  52. organization,
  53. projects: selectedProjects?.join(','),
  54. });
  55. }
  56. // Show no user reports if waiting for projects to load or if there is no feedback
  57. if (loadingProjects || hasAnyFeedback !== false) {
  58. return (
  59. <EmptyStateWarning>
  60. <p>{t('Sorry, no user reports match your filters.')}</p>
  61. </EmptyStateWarning>
  62. );
  63. }
  64. // Show landing page after projects have loaded and it is confirmed no projects have feedback
  65. return (
  66. <OnboardingPanel
  67. data-test-id="user-feedback-empty"
  68. image={<img src={emptyStateImg} />}
  69. >
  70. <h3>{t('What do users think?')}</h3>
  71. <p>
  72. {t(
  73. `You can't read minds. At least we hope not. Ask users for feedback on the impact of their crashes or bugs and you shall receive.`
  74. )}
  75. </p>
  76. <ButtonList gap={1}>
  77. <Button
  78. external
  79. priority="primary"
  80. onClick={() => trackAnalyticsInternal('user_feedback.docs_clicked')}
  81. href="https://docs.sentry.io/product/user-feedback/"
  82. >
  83. {t('Read the docs')}
  84. </Button>
  85. <Button
  86. onClick={() => {
  87. Sentry.showReportDialog({
  88. // should never make it to the Sentry API, but just in case, use throwaway id
  89. eventId: '00000000000000000000000000000000',
  90. });
  91. trackAnalyticsInternal('user_feedback.dialog_opened');
  92. }}
  93. >
  94. {t('See an example')}
  95. </Button>
  96. </ButtonList>
  97. </OnboardingPanel>
  98. );
  99. }
  100. const ButtonList = styled(ButtonBar)`
  101. grid-template-columns: repeat(auto-fit, minmax(130px, max-content));
  102. `;