projectUserFeedback.tsx 4.1 KB

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