projectUserFeedback.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import {RouteComponentProps} from 'react-router';
  2. import styled from '@emotion/styled';
  3. import * as Sentry from '@sentry/react';
  4. import Access from 'sentry/components/acl/access';
  5. import {Button} from 'sentry/components/button';
  6. import Form from 'sentry/components/forms/form';
  7. import JsonForm from 'sentry/components/forms/jsonForm';
  8. import formGroups from 'sentry/data/forms/userFeedback';
  9. import {t} from 'sentry/locale';
  10. import {space} from 'sentry/styles/space';
  11. import {Organization} from 'sentry/types';
  12. import routeTitleGen from 'sentry/utils/routeTitle';
  13. import withOrganization from 'sentry/utils/withOrganization';
  14. import AsyncView from 'sentry/views/asyncView';
  15. import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader';
  16. import TextBlock from 'sentry/views/settings/components/text/textBlock';
  17. type RouteParams = {
  18. projectId: string;
  19. };
  20. type Props = RouteComponentProps<RouteParams, {}> & {
  21. organization: Organization;
  22. };
  23. class ProjectUserFeedbackSettings extends AsyncView<Props> {
  24. submitTimeout: number | undefined = undefined;
  25. componentDidMount() {
  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. window.setTimeout(() => {
  32. this._submitInProgress = false;
  33. this.onSuccess();
  34. }, 500);
  35. };
  36. };
  37. }
  38. componentWillUnmount() {
  39. window.sentryEmbedCallback = null;
  40. }
  41. getEndpoints(): ReturnType<AsyncView['getEndpoints']> {
  42. const {organization} = this.props;
  43. const {projectId} = this.props.params;
  44. return [
  45. ['keyList', `/projects/${organization.slug}/${projectId}/keys/`],
  46. ['project', `/projects/${organization.slug}/${projectId}/`],
  47. ];
  48. }
  49. getTitle(): string {
  50. const {projectId} = this.props.params;
  51. return routeTitleGen(t('User Feedback'), projectId, false);
  52. }
  53. handleClick = () => {
  54. Sentry.showReportDialog({
  55. // should never make it to the Sentry API, but just in case, use throwaway id
  56. eventId: '00000000000000000000000000000000',
  57. });
  58. };
  59. renderBody() {
  60. const {organization} = this.props;
  61. const {projectId} = this.props.params;
  62. return (
  63. <div>
  64. <SettingsPageHeader title={t('User Feedback')} />
  65. <TextBlock>
  66. {t(
  67. `Don't rely on stack traces and graphs alone to understand
  68. the cause and impact of errors. Enable User Feedback to collect
  69. your users' comments when they encounter a crash or bug.`
  70. )}
  71. </TextBlock>
  72. <TextBlock>
  73. {t(
  74. `When configured, your users will be presented with a dialog prompting
  75. them for additional information. That information will get attached to
  76. the issue in Sentry.`
  77. )}
  78. </TextBlock>
  79. <ButtonList>
  80. <Button external href="https://docs.sentry.io/product/user-feedback/">
  81. {t('Read the docs')}
  82. </Button>
  83. <Button priority="primary" onClick={this.handleClick}>
  84. {t('Open the report dialog')}
  85. </Button>
  86. </ButtonList>
  87. <Form
  88. saveOnBlur
  89. apiMethod="PUT"
  90. apiEndpoint={`/projects/${organization.slug}/${projectId}/`}
  91. initialData={this.state.project.options}
  92. >
  93. <Access access={['project:write']}>
  94. {({hasAccess}) => <JsonForm disabled={!hasAccess} forms={formGroups} />}
  95. </Access>
  96. </Form>
  97. </div>
  98. );
  99. }
  100. }
  101. const ButtonList = styled('div')`
  102. display: inline-grid;
  103. grid-auto-flow: column;
  104. gap: ${space(1)};
  105. margin-bottom: ${space(2)};
  106. `;
  107. export default withOrganization(ProjectUserFeedbackSettings);