userFeedbackEmpty.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import {useCallback, 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 {useFeedbackOnboardingSidebarPanel} from 'sentry/components/feedback/useFeedbackOnboarding';
  9. import OnboardingPanel from 'sentry/components/onboardingPanel';
  10. import {t} from 'sentry/locale';
  11. import {trackAnalytics} from 'sentry/utils/analytics';
  12. import {useLocation} from 'sentry/utils/useLocation';
  13. import {useNavigate} from 'sentry/utils/useNavigate';
  14. import useOrganization from 'sentry/utils/useOrganization';
  15. import useProjects from 'sentry/utils/useProjects';
  16. type Props = {
  17. issueTab?: boolean;
  18. projectIds?: string[];
  19. };
  20. export function UserFeedbackEmpty({projectIds, issueTab = false}: Props) {
  21. const {projects, initiallyLoaded} = useProjects();
  22. const loadingProjects = !initiallyLoaded;
  23. const organization = useOrganization();
  24. const location = useLocation();
  25. const selectedProjects = projectIds?.length
  26. ? projects.filter(({id}) => projectIds.includes(id))
  27. : projects;
  28. const hasAnyFeedback = selectedProjects.some(({hasUserReports}) => hasUserReports);
  29. const {activateSidebarIssueDetails} = useFeedbackOnboardingSidebarPanel();
  30. const navigate = useNavigate();
  31. const setProjId = useCallback(() => {
  32. navigate({
  33. pathname: location.pathname,
  34. query: {...location.query, project: projectIds?.[0]},
  35. hash: location.hash,
  36. });
  37. }, [location.hash, location.query, location.pathname, projectIds, navigate]);
  38. useEffect(() => {
  39. if (issueTab) {
  40. setProjId();
  41. }
  42. // eslint-disable-next-line react-hooks/exhaustive-deps
  43. }, []);
  44. useEffect(() => {
  45. window.sentryEmbedCallback = function (embed) {
  46. // Mock the embed's submit xhr to always be successful
  47. // NOTE: this will not have errors if the form is empty
  48. embed.submit = function (_body) {
  49. this._submitInProgress = true;
  50. setTimeout(() => {
  51. this._submitInProgress = false;
  52. this.onSuccess();
  53. }, 500);
  54. };
  55. };
  56. if (hasAnyFeedback === false) {
  57. // send to reload only due to higher event volume
  58. trackAnalytics('user_feedback.viewed', {
  59. organization,
  60. projects: projectIds?.join(',') || '',
  61. });
  62. }
  63. return () => {
  64. window.sentryEmbedCallback = null;
  65. };
  66. }, [hasAnyFeedback, organization, projectIds]);
  67. function trackAnalyticsInternal(
  68. eventKey: 'user_feedback.docs_clicked' | 'user_feedback.dialog_opened'
  69. ) {
  70. trackAnalytics(eventKey, {
  71. organization,
  72. projects: selectedProjects?.join(','),
  73. });
  74. }
  75. // Show no user reports if waiting for projects to load or if there is no feedback
  76. if (loadingProjects || hasAnyFeedback !== false) {
  77. return (
  78. <EmptyStateWarning>
  79. <p>{t('Sorry, no user reports match your filters.')}</p>
  80. </EmptyStateWarning>
  81. );
  82. }
  83. // Show landing page after projects have loaded and it is confirmed no projects have feedback
  84. return (
  85. <OnboardingPanel
  86. data-test-id="user-feedback-empty"
  87. image={<img src={emptyStateImg} />}
  88. >
  89. <h3>{t('What do users think?')}</h3>
  90. <p>
  91. {t(
  92. `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.`
  93. )}
  94. </p>
  95. <ButtonList gap={1}>
  96. <Button
  97. priority="primary"
  98. onClick={activateSidebarIssueDetails}
  99. analyticsEventName="Clicked Feedback Onboarding Setup - Issue Details"
  100. analyticsEventKey="feedback.issue-details-click-onboarding-setup"
  101. >
  102. {t('Set up now')}
  103. </Button>
  104. <Button
  105. onClick={() => {
  106. Sentry.showReportDialog({
  107. // should never make it to the Sentry API, but just in case, use throwaway id
  108. eventId: '00000000000000000000000000000000',
  109. });
  110. trackAnalyticsInternal('user_feedback.dialog_opened');
  111. }}
  112. >
  113. {t('See an example')}
  114. </Button>
  115. </ButtonList>
  116. </OnboardingPanel>
  117. );
  118. }
  119. const ButtonList = styled(ButtonBar)`
  120. grid-template-columns: repeat(auto-fit, minmax(130px, max-content));
  121. `;