mirror of
https://github.com/drawdb-io/drawdb.git
synced 2025-05-24 10:29:11 +00:00
Update email api endpoints (#414)
This commit is contained in:
parent
9e245cf550
commit
3c29049c2b
9
src/api/email.js
Normal file
9
src/api/email.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import axios from "axios";
|
||||||
|
|
||||||
|
export async function send(subject, message, attachments) {
|
||||||
|
return await axios.post(`${import.meta.env.VITE_BACKEND_URL}/email/send`, {
|
||||||
|
subject,
|
||||||
|
message,
|
||||||
|
attachments,
|
||||||
|
});
|
||||||
|
}
|
7
src/api/index.js
Normal file
7
src/api/index.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import { send } from "./email";
|
||||||
|
|
||||||
|
export const api = {
|
||||||
|
email: {
|
||||||
|
send,
|
||||||
|
},
|
||||||
|
};
|
@ -14,9 +14,9 @@ import { editorConfig } from "../data/editorConfig";
|
|||||||
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
||||||
import { $generateHtmlFromNodes } from "@lexical/html";
|
import { $generateHtmlFromNodes } from "@lexical/html";
|
||||||
import { CLEAR_EDITOR_COMMAND } from "lexical";
|
import { CLEAR_EDITOR_COMMAND } from "lexical";
|
||||||
import axios from "axios";
|
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
import { socials } from "../data/socials";
|
import { socials } from "../data/socials";
|
||||||
|
import { api } from "../api";
|
||||||
|
|
||||||
function Form({ theme }) {
|
function Form({ theme }) {
|
||||||
const [editor] = useLexicalComposerContext();
|
const [editor] = useLexicalComposerContext();
|
||||||
@ -65,21 +65,19 @@ function Form({ theme }) {
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
editor.update(() => {
|
editor.update(() => {
|
||||||
const sendMail = async () => {
|
const sendMail = async () => {
|
||||||
await axios
|
try {
|
||||||
.post(`${import.meta.env.VITE_BACKEND_URL}/send_email`, {
|
await api.email.send(
|
||||||
subject: `[BUG REPORT]: ${data.title}`,
|
`[BUG REPORT]: ${data.title}`,
|
||||||
message: $generateHtmlFromNodes(editor),
|
$generateHtmlFromNodes(editor),
|
||||||
attachments: data.attachments,
|
data.attachments,
|
||||||
})
|
);
|
||||||
.then(() => {
|
|
||||||
Toast.success("Bug reported!");
|
Toast.success("Bug reported!");
|
||||||
editor.dispatchCommand(CLEAR_EDITOR_COMMAND, null);
|
editor.dispatchCommand(CLEAR_EDITOR_COMMAND, null);
|
||||||
resetForm();
|
resetForm();
|
||||||
})
|
} catch {
|
||||||
.catch(() => {
|
|
||||||
Toast.error("Oops! Something went wrong.");
|
Toast.error("Oops! Something went wrong.");
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
});
|
}
|
||||||
};
|
};
|
||||||
sendMail();
|
sendMail();
|
||||||
});
|
});
|
||||||
|
@ -20,8 +20,8 @@ import { $generateHtmlFromNodes } from "@lexical/html";
|
|||||||
import { CLEAR_EDITOR_COMMAND } from "lexical";
|
import { CLEAR_EDITOR_COMMAND } from "lexical";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
import RichEditor from "../components/LexicalEditor/RichEditor";
|
import RichEditor from "../components/LexicalEditor/RichEditor";
|
||||||
import axios from "axios";
|
|
||||||
import { questions } from "../data/surveyQuestions";
|
import { questions } from "../data/surveyQuestions";
|
||||||
|
import { api } from "../api";
|
||||||
|
|
||||||
function SurveyForm({ theme }) {
|
function SurveyForm({ theme }) {
|
||||||
const [editor] = useLexicalComposerContext();
|
const [editor] = useLexicalComposerContext();
|
||||||
@ -55,24 +55,20 @@ function SurveyForm({ theme }) {
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
editor.update(() => {
|
editor.update(() => {
|
||||||
const sendMail = async () => {
|
const sendMail = async () => {
|
||||||
await axios
|
try {
|
||||||
.post(`${import.meta.env.VITE_BACKEND_URL}/send_email`, {
|
await api.email.send(
|
||||||
subject: `[SURVEY]: ${new Date().toDateString()}`,
|
`[SURVEY]: ${new Date().toDateString()}`,
|
||||||
message: `${Object.keys(form).map(
|
`${Object.keys(form)
|
||||||
(k) => `<div>${questions[k]}</div><div>${form[k]}</div>`
|
.map((k) => `<div>${questions[k]}</div><div>${form[k]}</div>`)
|
||||||
)}<div>How can we make drawDB a better experience for you?</div>${$generateHtmlFromNodes(
|
.join("\n\n")}<br/>${$generateHtmlFromNodes(editor)}`,
|
||||||
editor
|
);
|
||||||
)}`,
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
Toast.success("Thanks for the feedback!");
|
Toast.success("Thanks for the feedback!");
|
||||||
editor.dispatchCommand(CLEAR_EDITOR_COMMAND, undefined);
|
editor.dispatchCommand(CLEAR_EDITOR_COMMAND, null);
|
||||||
resetForm();
|
resetForm();
|
||||||
})
|
} catch {
|
||||||
.catch(() => {
|
|
||||||
Toast.error("Oops! Something went wrong.");
|
Toast.error("Oops! Something went wrong.");
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
});
|
}
|
||||||
};
|
};
|
||||||
sendMail();
|
sendMail();
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user