feedback form now sends actual emails!
This commit is contained in:
parent
87d6cbf72a
commit
d602287190
4 changed files with 61 additions and 6 deletions
|
@ -6,9 +6,37 @@ const beeline = require("honeycomb-beeline")({
|
||||||
: "Dress to Impress (2020, dev)",
|
: "Dress to Impress (2020, dev)",
|
||||||
serviceName: "impress-2020-gql-server",
|
serviceName: "impress-2020-gql-server",
|
||||||
});
|
});
|
||||||
|
import sendgridMail from "@sendgrid/mail";
|
||||||
|
|
||||||
|
sendgridMail.setApiKey(process.env.SENDGRID_API_KEY);
|
||||||
|
|
||||||
async function handle(req, res) {
|
async function handle(req, res) {
|
||||||
res.status(500).send("TODO! This is a fake error case.");
|
const { content, email } = req.body;
|
||||||
|
if (!content) {
|
||||||
|
return res.status(400).send("Content must not be empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
let contentSummary = content.trim();
|
||||||
|
if (contentSummary.length > 60) {
|
||||||
|
contentSummary = contentSummary.slice(0, 40) + "…";
|
||||||
|
}
|
||||||
|
|
||||||
|
console.info(`Sending from ${email || "<anonymous>"}:\n${content}`);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await sendgridMail.send({
|
||||||
|
to: "matchu@openneo.net",
|
||||||
|
from: "impress-2020-feedback@openneo.net",
|
||||||
|
subject: `DTI feedback: ${contentSummary}`,
|
||||||
|
replyTo: email,
|
||||||
|
text: content,
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
return res.status(500).send("Error sending message, see logs");
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.status(200).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
"@chakra-ui/icons": "^1.0.0-rc.3",
|
"@chakra-ui/icons": "^1.0.0-rc.3",
|
||||||
"@chakra-ui/theme": "^1.0.0-rc.3",
|
"@chakra-ui/theme": "^1.0.0-rc.3",
|
||||||
"@loadable/component": "^5.12.0",
|
"@loadable/component": "^5.12.0",
|
||||||
|
"@sendgrid/mail": "^7.2.6",
|
||||||
"@testing-library/jest-dom": "^4.2.4",
|
"@testing-library/jest-dom": "^4.2.4",
|
||||||
"@testing-library/react": "^9.3.2",
|
"@testing-library/react": "^9.3.2",
|
||||||
"@testing-library/user-event": "^7.1.2",
|
"@testing-library/user-event": "^7.1.2",
|
||||||
|
|
|
@ -398,13 +398,10 @@ function FeedbackForm({ isDisabled, onClose, emailFieldRef }) {
|
||||||
(e) => {
|
(e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
const formData = new FormData();
|
|
||||||
formData.set("content", content);
|
|
||||||
formData.set("email", email);
|
|
||||||
|
|
||||||
fetch("/api/sendFeedback", {
|
fetch("/api/sendFeedback", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: formData,
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({ content, email }),
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
|
|
29
yarn.lock
29
yarn.lock
|
@ -3400,6 +3400,30 @@
|
||||||
resolved "https://registry.yarnpkg.com/@react-types/shared/-/shared-3.2.0.tgz#531c320e6b8f01f614336c14cee50ecf9fca4a4d"
|
resolved "https://registry.yarnpkg.com/@react-types/shared/-/shared-3.2.0.tgz#531c320e6b8f01f614336c14cee50ecf9fca4a4d"
|
||||||
integrity sha512-0oVULza+qc8+j7I9OB74FVjbrH6JzUAYDAkTYXbsaPt/w4quAlgd4ADy9yxIVYyN1GCXp/z0AUuocaYDHA8O6Q==
|
integrity sha512-0oVULza+qc8+j7I9OB74FVjbrH6JzUAYDAkTYXbsaPt/w4quAlgd4ADy9yxIVYyN1GCXp/z0AUuocaYDHA8O6Q==
|
||||||
|
|
||||||
|
"@sendgrid/client@^7.2.6":
|
||||||
|
version "7.2.6"
|
||||||
|
resolved "https://registry.yarnpkg.com/@sendgrid/client/-/client-7.2.6.tgz#28374927b5d9b3b351b9426f4a218d23d590c958"
|
||||||
|
integrity sha512-AOB3IVlB76SMYdaLEtWGm6/GwrOv0xlAOkyCqk5+XifJRqL2pl8a9lfxFZ9BEnWrdqPJPJ1/omopj0P7d5ZPmw==
|
||||||
|
dependencies:
|
||||||
|
"@sendgrid/helpers" "^7.2.6"
|
||||||
|
axios "^0.19.2"
|
||||||
|
|
||||||
|
"@sendgrid/helpers@^7.2.6":
|
||||||
|
version "7.2.6"
|
||||||
|
resolved "https://registry.yarnpkg.com/@sendgrid/helpers/-/helpers-7.2.6.tgz#5d15b8914940147c0635c9a3d2a93fed8c73dc71"
|
||||||
|
integrity sha512-J2xniPBOVo4ASzx+xc735OovHGj/v9oNrDo1Bb5fwTg/kmUxWxeoKZRkB+KLdciwmTtVrZjYLdQB3pMFIe9lAw==
|
||||||
|
dependencies:
|
||||||
|
chalk "^2.0.1"
|
||||||
|
deepmerge "^4.2.2"
|
||||||
|
|
||||||
|
"@sendgrid/mail@^7.2.6":
|
||||||
|
version "7.2.6"
|
||||||
|
resolved "https://registry.yarnpkg.com/@sendgrid/mail/-/mail-7.2.6.tgz#8f6a398ad75fb1ed7a35a9bb18cbdac111637ef6"
|
||||||
|
integrity sha512-eP9MuqEZIgt4bHaoufWqKGUY4Bo7FUgST3WGNYIDXIe1rP2dV6/JR7Ac2Dl9iW22gy15nc58fLGIGa41XbwtuA==
|
||||||
|
dependencies:
|
||||||
|
"@sendgrid/client" "^7.2.6"
|
||||||
|
"@sendgrid/helpers" "^7.2.6"
|
||||||
|
|
||||||
"@sheerun/mutationobserver-shim@^0.3.2":
|
"@sheerun/mutationobserver-shim@^0.3.2":
|
||||||
version "0.3.3"
|
version "0.3.3"
|
||||||
resolved "https://registry.yarnpkg.com/@sheerun/mutationobserver-shim/-/mutationobserver-shim-0.3.3.tgz#5405ee8e444ed212db44e79351f0c70a582aae25"
|
resolved "https://registry.yarnpkg.com/@sheerun/mutationobserver-shim/-/mutationobserver-shim-0.3.3.tgz#5405ee8e444ed212db44e79351f0c70a582aae25"
|
||||||
|
@ -8030,6 +8054,11 @@ deepmerge@^3.2.0:
|
||||||
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-3.3.0.tgz#d3c47fd6f3a93d517b14426b0628a17b0125f5f7"
|
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-3.3.0.tgz#d3c47fd6f3a93d517b14426b0628a17b0125f5f7"
|
||||||
integrity sha512-GRQOafGHwMHpjPx9iCvTgpu9NojZ49q794EEL94JVEw6VaeA8XTUyBKvAkOOjBX9oJNiV6G3P+T+tihFjo2TqA==
|
integrity sha512-GRQOafGHwMHpjPx9iCvTgpu9NojZ49q794EEL94JVEw6VaeA8XTUyBKvAkOOjBX9oJNiV6G3P+T+tihFjo2TqA==
|
||||||
|
|
||||||
|
deepmerge@^4.2.2:
|
||||||
|
version "4.2.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-4.2.2.tgz#44d2ea3679b8f4d4ffba33f03d865fc1e7bf4955"
|
||||||
|
integrity sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg==
|
||||||
|
|
||||||
default-gateway@^4.2.0:
|
default-gateway@^4.2.0:
|
||||||
version "4.2.0"
|
version "4.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/default-gateway/-/default-gateway-4.2.0.tgz#167104c7500c2115f6dd69b0a536bb8ed720552b"
|
resolved "https://registry.yarnpkg.com/default-gateway/-/default-gateway-4.2.0.tgz#167104c7500c2115f6dd69b0a536bb8ed720552b"
|
||||||
|
|
Loading…
Reference in a new issue