import { useEffect, useState, useCallback } from "react"; import logo_light from "../assets/logo_light_160.png"; import logo_dark from "../assets/logo_dark_160.png"; import { Banner, Button, Toast, Spin, Slider, Radio, RadioGroup, Select, TextArea, } from "@douyinfe/semi-ui"; import { IconSun, IconMoon } from "@douyinfe/semi-icons"; import { LexicalComposer } from "@lexical/react/LexicalComposer"; import { editorConfig } from "../data/editorConfig"; import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext"; import { $generateHtmlFromNodes } from "@lexical/html"; import { CLEAR_EDITOR_COMMAND } from "lexical"; import { Link } from "react-router-dom"; import RichEditor from "../components/LexicalEditor/RichEditor"; import axios from "axios"; import { questions } from "../data/surveyQuestions"; function SurveyForm({ theme }) { const [editor] = useLexicalComposerContext(); 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_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]); 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}