From fb190398c618a44f4a9b87c57c2722bc6eb435f8 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 21 Oct 2023 17:39:39 -0500 Subject: [PATCH] Add a Sentry feedback form which does not work --- src/components/site-error-boundary.tsx | 50 +++++++++++++++++++++++--- src/sentry.ts | 17 +++++++-- 2 files changed, 60 insertions(+), 7 deletions(-) diff --git a/src/components/site-error-boundary.tsx b/src/components/site-error-boundary.tsx index 85ed50cacc..2d6bb92e0f 100644 --- a/src/components/site-error-boundary.tsx +++ b/src/components/site-error-boundary.tsx @@ -3,9 +3,9 @@ import { ErrorBoundary } from 'react-error-boundary'; import { FormattedMessage } from 'react-intl'; import { NODE_ENV } from 'soapbox/build-config'; -import { HStack, Text, Stack, Textarea } from 'soapbox/components/ui'; +import { HStack, Text, Stack, Textarea, Form, Button, FormGroup, FormActions } from 'soapbox/components/ui'; import { useSoapboxConfig } from 'soapbox/hooks'; -import { captureSentryException } from 'soapbox/sentry'; +import { captureSentryException, captureSentryFeedback } from 'soapbox/sentry'; import KVStore from 'soapbox/storage/kv-store'; import sourceCode from 'soapbox/utils/code'; import { unregisterSW } from 'soapbox/utils/sw'; @@ -24,6 +24,9 @@ const SiteErrorBoundary: React.FC = ({ children }) => { const [error, setError] = useState(); const [componentStack, setComponentStack] = useState(); const [browser, setBrowser] = useState(); + const [sentryEventId, setSentryEventId] = useState(); + const [feedback, setFeedback] = useState(); + const [isSubmittingFeedback, setIsSubmittingFeedback] = useState(false); const sentryEnabled = Boolean(sentryDsn); const isProduction = NODE_ENV === 'production'; @@ -49,6 +52,23 @@ const SiteErrorBoundary: React.FC = ({ children }) => { document.execCommand('copy'); }; + const handleFeedbackChange: React.ChangeEventHandler = (e) => { + setFeedback(e.target.value); + }; + + const handleSubmitFeedback: React.FormEventHandler = async (_e) => { + if (!feedback || !sentryEventId) return; + setIsSubmittingFeedback(true); + + await captureSentryFeedback({ + event_id: sentryEventId, + comments: feedback, + }).catch(console.error); + + setFeedback(''); + setIsSubmittingFeedback(false); + }; + function handleError(error: Error, info: ErrorInfo) { setError(error); setComponentStack(info.componentStack); @@ -58,7 +78,9 @@ const SiteErrorBoundary: React.FC = ({ children }) => { // Allow page crashes to be easily searched in Sentry. ErrorBoundary: 'yes', }, - }); + }) + .then((eventId) => setSentryEventId(eventId)) + .catch(console.error); import('bowser') .then(({ default: Bowser }) => setBrowser(Bowser.getParser(window.navigator.userAgent))) @@ -116,8 +138,26 @@ const SiteErrorBoundary: React.FC = ({ children }) => {
- {(isProduction && sentryEnabled) ? ( - <>{/* TODO: Sentry report form. */} + {(isProduction) ? ( + (sentryEnabled && sentryEventId) && ( +
+ +