
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}
+
+ )}
+
+
+ {questions.triedOtherApps}
+
+
+ setForm((prev) => ({ ...prev, triedOtherApps: e.target.value }))
+ }
+ >
+ Yes
+ No
+
+
+ {form.triedOtherApps === "yes" && (
+
+
{questions.comparison}
+
+ )}
+
+
{questions.occupation}
+
+
+ How can we make drawDB a better experience for you?
+
+
+
+
+ Styling with markdown is
+ supported
+
+
+
+
+ );
+}
export default function Survey() {
- return
Survey
;
+ const [theme, setTheme] = useState("");
+
+ useEffect(() => {
+ const t = localStorage.getItem("theme");
+ setTheme(t);
+ if (t === "dark") {
+ const body = document.body;
+ if (body.hasAttribute("theme-mode")) {
+ body.setAttribute("theme-mode", "dark");
+ }
+ } else {
+ const body = document.body;
+ if (body.hasAttribute("theme-mode")) {
+ body.setAttribute("theme-mode", "light");
+ }
+ }
+ document.title = "Share you feedback | drawDB";
+ document.body.setAttribute("class", "theme");
+ }, [setTheme]);
+
+ const changeTheme = () => {
+ const body = document.body;
+ const t = body.getAttribute("theme-mode");
+ if (t === "dark") {
+ if (body.hasAttribute("theme-mode")) {
+ body.setAttribute("theme-mode", "light");
+ setTheme("light");
+ }
+ } else {
+ if (body.hasAttribute("theme-mode")) {
+ body.setAttribute("theme-mode", "dark");
+ setTheme("dark");
+ }
+ }
+ };
+
+ return (
+ <>
+
+
+

+
+ Share your feedback
+
+
+
+
+ ) : (
+
+ )
+ }
+ theme="borderless"
+ onClick={changeTheme}
+ >
+
+
+
+
+
+ Thanks for taking this survey! We highly value your feedback and
+ strive to make drawDB fit your needs better.
+
+ }
+ />
+
+
+
+