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 }));
}}
/>
{questions.ease}
{
setForm((prev) => ({ ...prev, ease: v }));
}}
/>
{questions.wouldRecommend}
{
setForm((prev) => ({ ...prev, wouldRecommend: v }));
}}
/>
{questions.hadDifficulty}
setForm((prev) => ({ ...prev, hadDifficulty: e.target.value }))
}
>
Yes
No
{form.hadDifficulty === "yes" && (
)}
{questions.triedOtherApps}
setForm((prev) => ({ ...prev, triedOtherApps: e.target.value }))
}
>
Yes
No
{form.triedOtherApps === "yes" && (
)}
{questions.occupation}
How can we make drawDB a better experience for you?
Styling with markdown is
supported
);
}
export default function Survey() {
const [theme, setTheme] = useState("");
useEffect(() => window.scroll(0, 0));
useEffect(() => {
setTheme(localStorage.getItem("theme"));
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.
}
/>
© 2024 drawDB - All right reserved.
);
}