projectUserFeedback.tsx 4.0 KB

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