|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import {useEffect, useState} from 'react'; |
| 4 | +import * as Sentry from "@sentry/nextjs"; |
| 5 | + |
| 6 | +type FeedbackIntegration = ReturnType<typeof Sentry.getFeedback>; |
| 7 | + |
| 8 | +export default function TranslatedFeedbackForm() { |
| 9 | + const [feedback, setFeedback] = useState<FeedbackIntegration>(); |
| 10 | + // Read `getFeedback` on the client only, to avoid hydration errors when server rendering |
| 11 | + useEffect(() => { |
| 12 | + setFeedback(Sentry.getFeedback()); |
| 13 | + }, []); |
| 14 | + |
| 15 | + // Don't render custom feedback button if Feedback integration isn't installed |
| 16 | + if (!feedback) { |
| 17 | + return null; |
| 18 | + } |
| 19 | + |
| 20 | + return ( |
| 21 | + <button |
| 22 | + className="hover:bg-hover px-4 py-2 rounded-md" |
| 23 | + type="button" |
| 24 | + onClick={async () => { |
| 25 | + const form = await feedback.createForm({ |
| 26 | + tags: {component: 'TranslatedFeedbackForm'}, |
| 27 | + |
| 28 | + /** |
| 29 | + * The label for the Feedback widget button that opens the dialog |
| 30 | + */ |
| 31 | + triggerLabel: 'Lets get started', |
| 32 | + /** |
| 33 | + * The aria label for the Feedback widget button that opens the dialog |
| 34 | + */ |
| 35 | + triggerAriaLabel: 'Send it!', |
| 36 | + /** |
| 37 | + * The label for the Feedback form cancel button that closes dialog |
| 38 | + */ |
| 39 | + cancelButtonLabel: 'Nevermind', |
| 40 | + /** |
| 41 | + * The label for the Feedback form submit button that sends feedback |
| 42 | + */ |
| 43 | + submitButtonLabel: 'Send it!', |
| 44 | + /** |
| 45 | + * The label for the Screenshot editor cancel buttons |
| 46 | + */ |
| 47 | + confirmButtonLabel: 'I confirm', |
| 48 | + /** |
| 49 | + * The title of the Feedback form |
| 50 | + */ |
| 51 | + formTitle: 'Feedback Test Area', |
| 52 | + /** |
| 53 | + * Label for the email input |
| 54 | + */ |
| 55 | + emailLabel: 'Email or contact info', |
| 56 | + /** |
| 57 | + * Placeholder text for Feedback email input |
| 58 | + */ |
| 59 | + emailPlaceholder: 'you@example.com or (555) 555-5555', |
| 60 | + /** |
| 61 | + * Label for the message input |
| 62 | + */ |
| 63 | + messageLabel: "What's up?", |
| 64 | + /** |
| 65 | + * Placeholder text for Feedback message input |
| 66 | + */ |
| 67 | + messagePlaceholder: 'Tell me about it', |
| 68 | + /** |
| 69 | + * Label for the name input |
| 70 | + */ |
| 71 | + nameLabel: 'Who dis?', |
| 72 | + /** |
| 73 | + * Placeholder text for Feedback name input |
| 74 | + */ |
| 75 | + namePlaceholder: 'Name, nickname, etc.', |
| 76 | + /** |
| 77 | + * Message after feedback was sent successfully |
| 78 | + */ |
| 79 | + successMessageText: 'Thanks, we got it!', |
| 80 | + /** |
| 81 | + * Text which indicates that a field is required |
| 82 | + */ |
| 83 | + isRequiredLabel: 'critical', |
| 84 | + /** |
| 85 | + * The label for the button that adds a screenshot and renders the image editor |
| 86 | + */ |
| 87 | + addScreenshotButtonLabel: 'Add a pic', |
| 88 | + /** |
| 89 | + * The label for the button that removes a screenshot and hides the image editor |
| 90 | + */ |
| 91 | + removeScreenshotButtonLabel: 'Drop the pic', |
| 92 | + /** |
| 93 | + * The label for the button that highlights portions ofthe screenshot |
| 94 | + */ |
| 95 | + highlightToolText: 'Spotlight it', |
| 96 | + /** |
| 97 | + * The label for the button that hides portions of the screenshot |
| 98 | + */ |
| 99 | + hideToolText: 'Not this part', |
| 100 | + /** |
| 101 | + * The label for the button that removed a highlight/hidden section of the screenshot. |
| 102 | + */ |
| 103 | + removeHighlightText: 'Take it out', |
| 104 | + }); |
| 105 | + form.appendToDom(); |
| 106 | + form.open(); |
| 107 | + }} |
| 108 | + > |
| 109 | + Give me feedback (translated) |
| 110 | + </button> |
| 111 | + ); |
| 112 | +} |
0 commit comments