feat(emails): implement transactional email system with Resend
Some checks failed
Build and Deploy / build (push) Has been cancelled
Some checks failed
Build and Deploy / build (push) Has been cancelled
- Add Resend email integration with @react-email/render - Create email templates: OrderConfirmation, OrderShipped, OrderCancelled, OrderPaid - Implement webhook handler for ORDER_CREATED and other events - Add multi-language support for customer emails - Admin emails in English with order details - Update checkout page with auto-scroll on order completion - Configure DASHBOARD_URL environment variable
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { Resend } from "resend";
|
||||
import { render } from "@react-email/render";
|
||||
|
||||
let resendClient: Resend | null = null;
|
||||
|
||||
@@ -30,17 +31,22 @@ export async function sendEmail({
|
||||
idempotencyKey?: string;
|
||||
}) {
|
||||
const resend = getResendClient();
|
||||
const { data, error } = await resend.emails.send(
|
||||
{
|
||||
from: "ManoonOils <support@manoonoils.com>",
|
||||
to: Array.isArray(to) ? to : [to],
|
||||
subject,
|
||||
react,
|
||||
text,
|
||||
tags,
|
||||
...(idempotencyKey && { idempotencyKey }),
|
||||
}
|
||||
);
|
||||
|
||||
// Render React component to HTML
|
||||
const html = await render(react, {
|
||||
pretty: true,
|
||||
});
|
||||
|
||||
const { data, error } = await resend.emails.send({
|
||||
from: "ManoonOils <support@mail.manoonoils.com>",
|
||||
replyTo: "support@manoonoils.com",
|
||||
to: Array.isArray(to) ? to : [to],
|
||||
subject,
|
||||
html,
|
||||
text,
|
||||
tags,
|
||||
...(idempotencyKey && { idempotencyKey }),
|
||||
});
|
||||
|
||||
if (error) {
|
||||
console.error("Failed to send email:", error);
|
||||
|
||||
@@ -152,3 +152,24 @@ export const CHECKOUT_EMAIL_UPDATE = gql`
|
||||
}
|
||||
${CHECKOUT_FRAGMENT}
|
||||
`;
|
||||
|
||||
export const CHECKOUT_METADATA_UPDATE = gql`
|
||||
mutation CheckoutMetadataUpdate($checkoutId: ID!, $metadata: [MetadataInput!]!) {
|
||||
updateMetadata(id: $checkoutId, input: $metadata) {
|
||||
item {
|
||||
... on Checkout {
|
||||
id
|
||||
metadata {
|
||||
key
|
||||
value
|
||||
}
|
||||
}
|
||||
}
|
||||
errors {
|
||||
field
|
||||
message
|
||||
code
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
Reference in New Issue
Block a user