Skip to content

Commit

Permalink
Email Notifications
Browse files Browse the repository at this point in the history
G-Yachts is notified whenever a new message is received on form submission
  • Loading branch information
gregory-buffard committed Sep 25, 2024
1 parent add9fde commit 719d19c
Show file tree
Hide file tree
Showing 6 changed files with 414 additions and 26 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ jobs:
echo "MAILCHIMP_LIST_ID=${{secrets.MAILCHIMP_LIST_ID}}" >> .env
echo "MAILCHIMP_SERVER=${{secrets.MAILCHIMP_SERVER}}" >> .env
echo "GOOGLE_ANALYTICS_ID=${{secrets.GOOGLE_ANALYTICS_ID}}" >> .env
echo "RESEND_API_KEY=${{secrets.RESEND_API_KEY}}" >> .env
# WEB
echo "NEXT_PUBLIC_ADMIN_BASE_URI=http://admin:3000" >> .env
Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ services:
volumes:
- /etc/nginx/sites-available/web:/etc/nginx/sites-enabled/web
- /etc/nginx/nginx.conf:/etc/nginx/nginx.conf
- /var/www/pictures:/var/www/pictures
- /var/www/images:/var/www/images
- /var/www/videos:/var/www/videos
- /etc/letsencrypt:/etc/letsencrypt:ro
networks:
Expand All @@ -30,6 +30,7 @@ services:
- MAILCHIMP_LIST_ID=${MAILCHIMP_LIST_ID}
- MAILCHIMP_SERVER=${MAILCHIMP_SERVER}
- GOOGLE_ANALYTICS_ID=${GOOGLE_ANALYTICS_ID}
- RESEND_API_KEY=${RESEND_API_KEY}
ports:
- "3000:3000"
depends_on:
Expand Down
53 changes: 28 additions & 25 deletions web/actions/contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { getClient } from "@/apollo";
import { gql } from "@apollo/client";
import { checkField } from "@/utils/contact";
import mailchimp from "@mailchimp/mailchimp_marketing";
import IContact from "@/types/contact";
import { Resend } from "resend";
import Email from "@/components/contact/notification";
const md5 = require("md5");

export const subscribe = async (formData: FormData) => {
Expand Down Expand Up @@ -56,33 +59,24 @@ export const contact = async ({
formData: FormData;
params: { locale: string; page: string; prefix?: string };
}) => {
const client = getClient();
const mutation = gql`
mutation CreateMessage($data: mutationMessageInput!) {
createMessage(data: $data) {
id
name
email
tel
message
page
newsletter
status
const client = getClient(),
mutation = gql`
mutation CreateMessage($data: mutationMessageInput!) {
createMessage(data: $data) {
id
name
email
tel
message
page
newsletter
status
}
}
}
`;
`,
resend = new Resend(process.env.RESEND_API_KEY);

const variables: {
data: {
name: string;
email: string;
message: string;
page: string;
status: "pending";
tel?: string;
newsletter: boolean;
};
} = {
const variables: IContact = {
data: {
name: checkField(formData.get("name")),
email: checkField(formData.get("email")),
Expand All @@ -91,6 +85,7 @@ export const contact = async ({
status: "pending",
newsletter: formData.get("newsletter") === "on",
},
received: new Date(),
};

if (formData.get("tel") && params.prefix) {
Expand All @@ -116,5 +111,13 @@ export const contact = async ({
await subscribe(formData);
}

await resend.emails.send({
from: `Notification <notification@g-yachts.com>`,
to: ["info@g-yachts.com", "alban@g-yachts.com"],
reply_to: variables.data.email,
subject: "New Message received",
react: Email(variables),
});

return data.createMessage;
};
Loading

0 comments on commit 719d19c

Please sign in to comment.