From 84910b9bc05dfc245301855d2627b4255423b495 Mon Sep 17 00:00:00 2001 From: Abdellah Hariti Date: Mon, 20 Jan 2025 18:23:03 +0100 Subject: [PATCH 01/13] feat: send content feedback plausible events --- src/components/docFeedback/index.tsx | 34 ++++++++++++++++++++++++++++ src/components/docPage/index.tsx | 3 +++ src/hooks/usePlausibleEvent.tsx | 4 ++++ 3 files changed, 41 insertions(+) create mode 100644 src/components/docFeedback/index.tsx diff --git a/src/components/docFeedback/index.tsx b/src/components/docFeedback/index.tsx new file mode 100644 index 00000000000000..b5180cb237b6e0 --- /dev/null +++ b/src/components/docFeedback/index.tsx @@ -0,0 +1,34 @@ +'use client'; +import {usePlausibleEvent} from 'sentry-docs/hooks/usePlausibleEvent'; + +type Props = { + pathname: string; +}; + +export function DocFeedback({pathname}: Props) { + const {emit} = usePlausibleEvent(); + + const handleFeedback = (helpful: boolean) => { + emit('Doc Feedback', {props: {page: pathname, helpful}}); + }; + + return ( +
+ Was this helpful? + + +
+ ); +} diff --git a/src/components/docPage/index.tsx b/src/components/docPage/index.tsx index 10da08e5c9ec1b..1797f7c7821878 100644 --- a/src/components/docPage/index.tsx +++ b/src/components/docPage/index.tsx @@ -12,6 +12,7 @@ import './type.scss'; import {Banner} from '../banner'; import {Breadcrumbs} from '../breadcrumbs'; import {CodeContextProvider} from '../codeContext'; +import {DocFeedback} from '../docFeedback'; import {GitHubCTA} from '../githubCTA'; import {Header} from '../header'; import Mermaid from '../mermaid'; @@ -91,6 +92,8 @@ export function DocPage({ {children} + +
{previousPage && } diff --git a/src/hooks/usePlausibleEvent.tsx b/src/hooks/usePlausibleEvent.tsx index 071eeb5fdf6ca2..8124e464908541 100644 --- a/src/hooks/usePlausibleEvent.tsx +++ b/src/hooks/usePlausibleEvent.tsx @@ -4,6 +4,10 @@ import {ReadProgressMilestone} from 'sentry-docs/types/plausible'; // Adding custom events here will make them available via the hook type PlausibleEventProps = { + ['Doc Feedback']: { + helpful: boolean; + page: string; + }; ['Read Progress']: { page: string; readProgress: ReadProgressMilestone; From db3d320297b2e6a4e0833cdd23deaf64c8ee5488 Mon Sep 17 00:00:00 2001 From: Abdellah Hariti Date: Mon, 20 Jan 2025 18:29:57 +0100 Subject: [PATCH 02/13] clearer buttons --- src/components/docFeedback/index.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/docFeedback/index.tsx b/src/components/docFeedback/index.tsx index b5180cb237b6e0..b8f2f4ccf9e00f 100644 --- a/src/components/docFeedback/index.tsx +++ b/src/components/docFeedback/index.tsx @@ -17,17 +17,17 @@ export function DocFeedback({pathname}: Props) { Was this helpful?
); From 54cdff0cbceb68e8b89f36aa5ae8e0cabbe3bd3a Mon Sep 17 00:00:00 2001 From: Abdellah Hariti Date: Mon, 20 Jan 2025 19:48:10 +0100 Subject: [PATCH 03/13] collect content feedback using Sentry User Feedbak --- src/components/docFeedback/index.tsx | 115 +++++++++++++++++++++++---- src/components/modal/index.tsx | 100 +++++++++++++++++++++++ 2 files changed, 199 insertions(+), 16 deletions(-) create mode 100644 src/components/modal/index.tsx diff --git a/src/components/docFeedback/index.tsx b/src/components/docFeedback/index.tsx index b8f2f4ccf9e00f..7c7faf46520dd4 100644 --- a/src/components/docFeedback/index.tsx +++ b/src/components/docFeedback/index.tsx @@ -1,34 +1,117 @@ 'use client'; +import {Fragment, useState} from 'react'; +import * as Sentry from '@sentry/browser'; + import {usePlausibleEvent} from 'sentry-docs/hooks/usePlausibleEvent'; +import {Modal} from '../modal'; + type Props = { pathname: string; }; export function DocFeedback({pathname}: Props) { const {emit} = usePlausibleEvent(); + const [showFeedbackModal, setShowFeedbackModal] = useState(false); + const [feedbackSubmitted, setFeedbackSubmitted] = useState(false); const handleFeedback = (helpful: boolean) => { emit('Doc Feedback', {props: {page: pathname, helpful}}); + + if (!helpful) { + setShowFeedbackModal(true); + } + }; + + const handleSubmitFeedback = (e: React.FormEvent) => { + e.preventDefault(); + const formData = new FormData(e.currentTarget); + const comments = formData.get('comments') as string; + + try { + Sentry.captureFeedback( + {message: comments}, + {captureContext: {tags: {page: pathname}}} + ); + setFeedbackSubmitted(true); + } catch (error) { + // eslint-disable-next-line no-console + console.error('Failed to submit feedback:', error); + } }; return ( -
- Was this helpful? - - + +
+ + { + setShowFeedbackModal(false); + setFeedbackSubmitted(false); + }} + title="Help us improve" > - No 👎 - -
+ {feedbackSubmitted ? ( +
+

Thank you for your feedback!

+

+ We appreciate your help in making our documentation better. +

+
+ ) : ( +
+

+ We'd love to hear more about how we can improve this page. Your feedback + helps us make our documentation better for everyone. +

+
+ +