projectUserFeedback.tsx 3.5 KB

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