Add design approval workflow infrastructure: PATCH endpoint, email notifications, and message types
- Add PATCH method to /api/designs/[id]/route.ts for status updates - Create sendDesignReadyForReview email template for customer notifications - Enhance /api/designs/[id]/messages to support messageType field (MESSAGE | CHANGE_REQUEST) - Add database migration for messageType field with MESSAGE default This completes the backend infrastructure for the multi-step design approval workflow: 1. Admin edits and sends design to customer for review 2. Customer approves design or requests changes 3. Admin receives notifications for change requests Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Haiku 4.5
parent
4d124b1550
commit
ac27cc554b
@@ -240,3 +240,38 @@ export async function sendDesignApprovedEmail({
|
||||
return { sent: false as const, reason: err instanceof Error ? err.message : 'Unknown error sending email' };
|
||||
}
|
||||
}
|
||||
|
||||
type SendDesignReadyForReviewArgs = {
|
||||
customerName: string;
|
||||
customerEmail: string;
|
||||
productName: string;
|
||||
reviewLink: string;
|
||||
};
|
||||
|
||||
export async function sendDesignReadyForReview({
|
||||
customerName,
|
||||
customerEmail,
|
||||
productName,
|
||||
reviewLink,
|
||||
}: SendDesignReadyForReviewArgs) {
|
||||
if (!process.env.SMTP_HOST) {
|
||||
return { sent: false, reason: 'SMTP not configured — set SMTP_HOST etc. in .env' as const };
|
||||
}
|
||||
|
||||
const transporter = getTransporter();
|
||||
|
||||
const greeting = customerName ? `Hi ${customerName},` : 'Hi,';
|
||||
|
||||
try {
|
||||
await transporter.sendMail({
|
||||
from: process.env.MAIL_FROM ?? process.env.SMTP_USER,
|
||||
to: customerEmail,
|
||||
subject: `Your ${productName} design is ready for review`,
|
||||
text: `${greeting}\n\nYour ${productName} design is ready for you to review and approve.\n\nReview it here:\n${reviewLink}\n\nYou can approve the design to proceed to checkout, or request changes from the admin.\n\n— Craft2Prints`,
|
||||
html: `<p>${greeting}</p><p>Your ${productName} design is ready for you to review and approve.</p><p><a href="${reviewLink}">${reviewLink}</a></p><p>You can approve the design to proceed to checkout, or request changes from the admin.</p><p>— Craft2Prints</p>`,
|
||||
});
|
||||
return { sent: true as const };
|
||||
} catch (err) {
|
||||
return { sent: false as const, reason: err instanceof Error ? err.message : 'Unknown error sending email' };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user