projectUserFeedback.tsx 3.7 KB

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