-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat: send content feedback plausible events #12400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
84910b9
feat: send content feedback plausible events
a-hariti db3d320
clearer buttons
a-hariti 54cdff0
collect content feedback using Sentry User Feedbak
a-hariti 89c80fa
improve spacing
a-hariti 3efa2c7
dedupe classanme
a-hariti dce9496
make ui reflect reception of feedback
a-hariti b43503d
adjust feedback modal copy
a-hariti 766ac4e
auto close feedback modal after submission
a-hariti 4c707c3
capture feedback submission error
a-hariti f8261af
move content feedback below next/prev navigation
a-hariti 3a392a3
change emojies
a-hariti 0f70b5e
capture feedback comments for both types of feedback in an inline form
a-hariti 4e96a48
improve styles
a-hariti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +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<HTMLFormElement>) => { | ||
| 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); | ||
a-hariti marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <Fragment> | ||
| <div className="flex items-center gap-2 py-4 border-t border-[var(--gray-6)]"> | ||
| <span className="text-sm">Was this helpful?</span> | ||
| <button | ||
| onClick={() => handleFeedback(true)} | ||
| className="py-2 px-4 gap-4 hover:bg-[var(--gray-3)] rounded-full flex items-center justify-center" | ||
| aria-label="Yes, this was helpful" | ||
| > | ||
| Yes 👍 | ||
| </button> | ||
| <button | ||
| onClick={() => handleFeedback(false)} | ||
| className="py-2 px-4 gap-4 hover:bg-[var(--gray-3)] rounded-full flex items-center justify-center" | ||
| aria-label="No, this wasn't helpful" | ||
| > | ||
| No 👎 | ||
| </button> | ||
| </div> | ||
|
|
||
| <Modal | ||
| isOpen={showFeedbackModal} | ||
| onClose={() => { | ||
| setShowFeedbackModal(false); | ||
| setFeedbackSubmitted(false); | ||
| }} | ||
| title="Help us improve" | ||
a-hariti marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| > | ||
| {feedbackSubmitted ? ( | ||
| <div className="text-center"> | ||
| <h3 className="text-lg font-medium mb-2">Thank you for your feedback!</h3> | ||
| <p className="text-[var(--gray-11)] p-0 m-0"> | ||
| We appreciate your help in making our documentation better. | ||
| </p> | ||
| </div> | ||
| ) : ( | ||
| <form onSubmit={handleSubmitFeedback} className="space-y-4"> | ||
| <p className="text-[var(--gray-11)] p-0 m-0"> | ||
| We'd love to hear more about how we can improve this page. Your feedback | ||
| helps us make our documentation better for everyone. | ||
| </p> | ||
| <div> | ||
| <label htmlFor="comments" className="block text-sm font-medium mb-4"> | ||
| What could we improve? | ||
| </label> | ||
| <textarea | ||
| id="comments" | ||
| name="comments" | ||
| required | ||
| rows={4} | ||
| className="w-full px-3 py-2 border border-[var(--gray-6)] rounded-lg focus:outline-none focus:ring-2 focus:ring-[var(--accent)] bg-transparent" | ||
| placeholder="Please share your suggestions..." | ||
| /> | ||
| </div> | ||
| <div className="flex justify-end gap-3"> | ||
| <button | ||
| type="button" | ||
| onClick={() => setShowFeedbackModal(false)} | ||
| className="px-4 py-2 text-sm hover:bg-[var(--gray-3)] rounded-lg" | ||
| > | ||
| Cancel | ||
| </button> | ||
| <button | ||
| type="submit" | ||
| className="px-4 py-2 text-sm bg-[var(--accent-purple)] rounded-lg" | ||
| > | ||
| Submit feedback | ||
| </button> | ||
| </div> | ||
| </form> | ||
| )} | ||
| </Modal> | ||
| </Fragment> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| 'use client'; | ||
| import {useEffect, useRef} from 'react'; | ||
|
|
||
| type Props = { | ||
| children: React.ReactNode; | ||
| isOpen: boolean; | ||
| onClose: () => void; | ||
| title: string; | ||
| }; | ||
|
|
||
| export function Modal({isOpen, onClose, children, title}: Props) { | ||
| const modalRef = useRef<HTMLDialogElement>(null); | ||
|
|
||
| useEffect(() => { | ||
| if (isOpen) { | ||
| modalRef.current?.showModal(); | ||
| document.body.style.overflow = 'hidden'; | ||
| } else { | ||
| modalRef.current?.close(); | ||
| document.body.style.overflow = 'unset'; | ||
| } | ||
| }, [isOpen]); | ||
|
|
||
| const handleClose = () => { | ||
| onClose(); | ||
| }; | ||
|
|
||
| const handleBackdropClick = (e: React.MouseEvent<HTMLDialogElement>) => { | ||
| if (e.target === modalRef.current) { | ||
| handleClose(); | ||
| } | ||
| }; | ||
|
|
||
| if (!isOpen) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <dialog | ||
| ref={modalRef} | ||
| className="backdrop:bg-[var(--gray-12)]/50 backdrop:backdrop-blur-sm p-0 bg-transparent w-full max-w-lg m-auto data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-top-[2%] data-[state=open]:slide-in-from-top-[2%] duration-200" | ||
| onClick={handleBackdropClick} | ||
| > | ||
| <div className="bg-[var(--gray-1)] rounded-lg shadow-lg border border-[var(--gray-6)] motion-safe:animate-modal-enter px-4"> | ||
| <div className="flex items-center justify-between py-5 border-b border-[var(--gray-6)] px-4"> | ||
| <h2 className="text-lg font-medium p!-0 !m-0">{title}</h2> | ||
| <button | ||
| onClick={handleClose} | ||
| className="p-2 hover:bg-[var(--gray-3)] rounded-full transition-colors" | ||
| aria-label="Close modal" | ||
| > | ||
| <svg width="12" height="12" viewBox="0 0 12 12"> | ||
| <path | ||
| d="M6 4.586l4.293-4.293 1.414 1.414L7.414 6l4.293 4.293-1.414 1.414L6 7.414l-4.293 4.293-1.414-1.414L4.586 6 .293 1.707 1.707.293 6 4.586z" | ||
| fill="currentColor" | ||
| /> | ||
| </svg> | ||
| </button> | ||
| </div> | ||
| <div className="p-4">{children}</div> | ||
| </div> | ||
|
|
||
| <style>{` | ||
| @keyframes modal-enter { | ||
| from { | ||
| opacity: 0; | ||
| transform: translate3d(0, -1rem, 0); | ||
| } | ||
| to { | ||
| opacity: 1; | ||
| transform: translate3d(0, 0, 0); | ||
| } | ||
| } | ||
|
|
||
| .animate-modal-enter { | ||
| animation: modal-enter 0.2s cubic-bezier(0.4, 0, 0.2, 1); | ||
| } | ||
|
|
||
| ::backdrop { | ||
| -webkit-backdrop-filter: blur(4px); | ||
| backdrop-filter: blur(4px); | ||
| background: rgba(var(--gray-12-rgb), 0.5); | ||
| transition: all 0.2s ease-in-out; | ||
| } | ||
|
|
||
| dialog[open]::backdrop { | ||
| opacity: 1; | ||
| } | ||
|
|
||
| dialog:not([open])::backdrop { | ||
| opacity: 0; | ||
| } | ||
|
|
||
| dialog::backdrop { | ||
| opacity: 0; | ||
| } | ||
| `}</style> | ||
| </dialog> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.