import { 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/RichEditor"; 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({ satisfaction: 5, ease: 5, wouldRecommend: 5, hadDifficulty: "", difficulty: "", triedOtherApps: "", comparison: "", occupation: "", }); setLoading(false); }; const onSubmit = useCallback( () => { setLoading(true); editor.update(() => { const sendMail = async () => { await axios .post(`${import.meta.env.VITE_API_BACKEND_URL}/send_email`, { subject: `[SURVEY]: ${new Date().toDateString()}`, message: `${Object.keys(form).map( (k) => `
${questions[k]}
${form[k]}
` )}
How can we make drawDB a better experience for you?
${$generateHtmlFromNodes( editor )}`, }) .then(() => { Toast.success("Thanks for the feedback!"); editor.dispatchCommand(CLEAR_EDITOR_COMMAND, undefined); resetForm(); }) .catch(() => { 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}