Skip to content

Update email api endpoints #414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/api/email.js
Original file line number Diff line number Diff line change
@@ -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 changes: 7 additions & 0 deletions src/api/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { send } from "./email";

export const api = {
email: {
send,
},
};
30 changes: 14 additions & 16 deletions src/pages/BugReport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import { editorConfig } from "../data/editorConfig";
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
import { $generateHtmlFromNodes } from "@lexical/html";
import { CLEAR_EDITOR_COMMAND } from "lexical";
import axios from "axios";
import { Link } from "react-router-dom";
import { socials } from "../data/socials";
import { api } from "../api";

function Form({ theme }) {
const [editor] = useLexicalComposerContext();
Expand Down Expand Up @@ -65,21 +65,19 @@ function Form({ theme }) {
setLoading(true);
editor.update(() => {
const sendMail = async () => {
await axios
.post(`${import.meta.env.VITE_BACKEND_URL}/send_email`, {
subject: `[BUG REPORT]: ${data.title}`,
message: $generateHtmlFromNodes(editor),
attachments: data.attachments,
})
.then(() => {
Toast.success("Bug reported!");
editor.dispatchCommand(CLEAR_EDITOR_COMMAND, null);
resetForm();
})
.catch(() => {
Toast.error("Oops! Something went wrong.");
setLoading(false);
});
try {
await api.email.send(
`[BUG REPORT]: ${data.title}`,
$generateHtmlFromNodes(editor),
data.attachments,
);
Toast.success("Bug reported!");
editor.dispatchCommand(CLEAR_EDITOR_COMMAND, null);
resetForm();
} catch {
Toast.error("Oops! Something went wrong.");
setLoading(false);
}
};
sendMail();
});
Expand Down
34 changes: 15 additions & 19 deletions src/pages/Survey.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ 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";
import { api } from "../api";

function SurveyForm({ theme }) {
const [editor] = useLexicalComposerContext();
Expand Down Expand Up @@ -55,24 +55,20 @@ function SurveyForm({ theme }) {
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) => `<div>${questions[k]}</div><div>${form[k]}</div>`
)}<div>How can we make drawDB a better experience for you?</div>${$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);
});
try {
await api.email.send(
`[SURVEY]: ${new Date().toDateString()}`,
`${Object.keys(form)
.map((k) => `<div>${questions[k]}</div><div>${form[k]}</div>`)
.join("\n\n")}<br/>${$generateHtmlFromNodes(editor)}`,
);
Toast.success("Thanks for the feedback!");
editor.dispatchCommand(CLEAR_EDITOR_COMMAND, null);
resetForm();
} catch {
Toast.error("Oops! Something went wrong.");
setLoading(false);
}
};
sendMail();
});
Expand Down