|
| 1 | +import { useState } from "react"; |
| 2 | +import { |
| 3 | + FeelbackTaggedMessage, |
| 4 | + Question, |
| 5 | + PRESET_YESNO_LIKE_DISLIKE, |
| 6 | +} from "@feelback/react"; |
| 7 | +import useDocusaurusContext from "@docusaurus/useDocusaurusContext"; |
| 8 | + |
| 9 | +const YES_TAGS = [ |
| 10 | + { |
| 11 | + value: "accurate", |
| 12 | + title: "Accurate", |
| 13 | + description: "Accurately describes the product or feature.", |
| 14 | + }, |
| 15 | + { |
| 16 | + value: "problem-solved", |
| 17 | + title: "Solved my problem", |
| 18 | + description: "Helped me resolve an issue.", |
| 19 | + }, |
| 20 | + { |
| 21 | + value: "clear", |
| 22 | + title: "Easy to understand", |
| 23 | + description: "Easy to follow and comprehend.", |
| 24 | + }, |
| 25 | + { |
| 26 | + value: "product-chosen", |
| 27 | + title: "Helped me decide to use the product", |
| 28 | + description: "Convinced me to adopt the product or feature.", |
| 29 | + }, |
| 30 | + { value: "other-yes", title: "Another reason" }, |
| 31 | +]; |
| 32 | + |
| 33 | +const NO_TAGS = [ |
| 34 | + { |
| 35 | + value: "inaccurate", |
| 36 | + title: "Inaccurate", |
| 37 | + description: "Doesn't accurately describe the product or feature.", |
| 38 | + }, |
| 39 | + { |
| 40 | + value: "missing-info", |
| 41 | + title: "Couldn't find what I was looking for", |
| 42 | + description: "Missing important information.", |
| 43 | + }, |
| 44 | + { |
| 45 | + value: "unclear", |
| 46 | + title: "Hard to understand", |
| 47 | + description: "Too complicated or unclear.", |
| 48 | + }, |
| 49 | + { |
| 50 | + value: "bad-examples", |
| 51 | + title: "Code samples errors", |
| 52 | + description: "One or more code samples are incorrect.", |
| 53 | + }, |
| 54 | + { value: "other-no", title: "Another reason" }, |
| 55 | +]; |
| 56 | + |
| 57 | +const Feedback = () => { |
| 58 | + const [choice, setChoice] = useState<"y" | "n">(); |
| 59 | + const { siteConfig } = useDocusaurusContext(); |
| 60 | + const { FEEDBACK_CONTENT_SET_ID } = siteConfig.customFields; |
| 61 | + |
| 62 | + return ( |
| 63 | + <div className="alert alert--info feedback-component"> |
| 64 | + <div className="feelback-container"> |
| 65 | + {!choice ? ( |
| 66 | + <Question |
| 67 | + text="Was this page helpful?" |
| 68 | + items={PRESET_YESNO_LIKE_DISLIKE} |
| 69 | + showLabels |
| 70 | + onClick={(option: "y" | "n") => setChoice(option)} |
| 71 | + /> |
| 72 | + ) : ( |
| 73 | + <FeelbackTaggedMessage |
| 74 | + contentSetId={FEEDBACK_CONTENT_SET_ID as string} |
| 75 | + layout="radio-group" |
| 76 | + tags={choice === "y" ? YES_TAGS : NO_TAGS} |
| 77 | + title={choice === "y" ? "What did you like?" : "What went wrong?"} |
| 78 | + placeholder="(optional) Please, further detail the feedback" |
| 79 | + /> |
| 80 | + )} |
| 81 | + </div> |
| 82 | + </div> |
| 83 | + ); |
| 84 | +}; |
| 85 | + |
| 86 | +export default Feedback; |
0 commit comments