diff --git a/src/components/control_panel.jsx b/src/components/control_panel.jsx index a77ccda..aa386f4 100644 --- a/src/components/control_panel.jsx +++ b/src/components/control_panel.jsx @@ -978,8 +978,8 @@ export default function ControlPanel(props) { "Report a bug": { function: () => window.open("/bug_report", "_blank"), }, - "Suggest a feature": { - function: () => {}, + "Give feedback": { + function: () => window.open("/survey", "_blank"), }, }, }; diff --git a/src/components/rich_editor.jsx b/src/components/rich_editor.jsx index b5c4ebf..aba271e 100644 --- a/src/components/rich_editor.jsx +++ b/src/components/rich_editor.jsx @@ -6,7 +6,7 @@ import LexicalErrorBoundary from "@lexical/react/LexicalErrorBoundary"; import { LinkPlugin } from "@lexical/react/LexicalLinkPlugin"; import { ListPlugin } from "@lexical/react/LexicalListPlugin"; import { MarkdownShortcutPlugin } from "@lexical/react/LexicalMarkdownShortcutPlugin"; -import { ClearEditorPlugin } from '@lexical/react/LexicalClearEditorPlugin'; +import { ClearEditorPlugin } from "@lexical/react/LexicalClearEditorPlugin"; import { TRANSFORMERS } from "@lexical/markdown"; import ToolbarPlugin from "../plugins/ToolbarPlugin"; @@ -15,18 +15,18 @@ import CodeHighlightPlugin from "../plugins/CodeHighlightPlugin"; import AutoLinkPlugin from "../plugins/AutoLinkPlugin"; import "../styles/richeditor.css"; -function Placeholder() { - return
Describe the bug
; +function Placeholder({ text }) { + return
{text || ""}
; } -export default function RichEditor({ theme }) { +export default function RichEditor({ theme, placeholder }) { return (
} - placeholder={} + placeholder={} ErrorBoundary={LexicalErrorBoundary} /> @@ -37,7 +37,7 @@ export default function RichEditor({ theme }) { - +
); diff --git a/src/pages/bug_report.jsx b/src/pages/bug_report.jsx index 7330c5a..78997eb 100644 --- a/src/pages/bug_report.jsx +++ b/src/pages/bug_report.jsx @@ -93,7 +93,7 @@ function Form({ theme }) { value={data.title} onChange={(v) => setData((prev) => ({ ...prev, title: v }))} /> - +
-
+
logo diff --git a/src/pages/survey.jsx b/src/pages/survey.jsx index 031e8a8..2583749 100644 --- a/src/pages/survey.jsx +++ b/src/pages/survey.jsx @@ -1,5 +1,316 @@ -import React from "react"; +import React, { useEffect, useState, useCallback, useMemo } from "react"; +import logo_light from "../assets/logo_light_46.png"; +import logo_dark from "../assets/logo_dark_46.png"; +import { + Banner, + Button, + Toast, + Spin, + Slider, + Radio, + RadioGroup, + Select, + TextArea, +} from "@douyinfe/semi-ui"; +import { IconSun, IconMoon } from "@douyinfe/semi-icons"; +import RichEditor from "../components/rich_editor"; +import { LexicalComposer } from "@lexical/react/LexicalComposer"; +import { editorConfig } from "../data/editor_config"; +import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext"; +import { $generateHtmlFromNodes } from "@lexical/html"; +import { CLEAR_EDITOR_COMMAND } from "lexical"; +import axios from "axios"; + +function SurveyForm({ theme }) { + const [editor] = useLexicalComposerContext(); + const questions = useMemo( + () => ({ + satisfaction: "How satisfied are you with drawDB?", + ease: "How easy was it to get started with drawDB?", + wouldRecommend: "How likely are you to recommend drawDB?", + hadDifficulty: + "Did you encounter any difficulties when navigating drawDB?", + difficulty: "What were the difficulties you faced?", + triedOtherApps: "Have you tried apps like drawDB?", + comparison: "How did you find drawDB as compared to other apps?", + occupation: "What is your occupation?", + }), + [] + ); + const [form, setForm] = useState({ + satisfaction: 5, + ease: 5, + wouldRecommend: 5, + hadDifficulty: "", + difficulty: "", + triedOtherApps: "", + comparison: "", + occupation: "", + }); + const [loading, setLoading] = useState(false); + + const resetForm = () => { + setForm({}); + setLoading(false); + }; + + const onSubmit = useCallback( + (e) => { + setLoading(true); + editor.update(() => { + const sendMail = async () => { + await axios + .post(`${process.env.REACT_APP_BACKEND_URL}/report_bug`, { + subject: `[SURVEY]: ${new Date().toDateString()}`, + message: `${Object.keys(questions).map( + (k) => `
${questions[k]}
${form[k]}
` + )}
Anything else?
${$generateHtmlFromNodes(editor)}`, + }) + .then((res) => { + Toast.success("Thanks for the feedback!"); + editor.dispatchCommand(CLEAR_EDITOR_COMMAND, undefined); + resetForm(); + }) + .catch((err) => { + Toast.error("Oops! Something went wrong."); + setLoading(false); + }); + }; + sendMail(); + }); + }, + [editor, form, questions] + ); + + return ( +
+
+
{questions.satisfaction}
+ { + setForm((prev) => ({ ...prev, satisfaction: v })); + }} + /> +
+
Not at all
+
Extremely
+
+
+
+
{questions.ease}
+ { + setForm((prev) => ({ ...prev, ease: v })); + }} + /> +
+
Not at all
+
Extremely
+
+
+
+
+ {questions.wouldRecommend} +
+ { + setForm((prev) => ({ ...prev, wouldRecommend: v })); + }} + /> +
+
Not at all
+
Extremely
+
+
+
+
{questions.hadDifficulty}
+ + setForm((prev) => ({ ...prev, hadDifficulty: e.target.value })) + } + > + Yes + No + +
+ {form.hadDifficulty === "yes" && ( +
+
{questions.difficulty}
+