Ship 23 transactional templates, shared brand tokens/logo, preview UI, render API, CHANGELOG, and docs for Ecom/Admin/B2B consumers. Co-authored-by: Cursor <cursoragent@cursor.com>
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import React from 'react';
|
|
import { render } from '@react-email/render';
|
|
import { NextResponse } from 'next/server';
|
|
import { templateMap } from '../../../../emails/registry';
|
|
import { resolveLocale } from '../../../../emails/i18n/types';
|
|
import type { ShopSummaryPeriod } from '../../../../emails/shop-summary';
|
|
|
|
export async function GET(
|
|
request: Request,
|
|
context: { params: Promise<{ template: string }> }
|
|
) {
|
|
const { template } = await context.params;
|
|
const entry = templateMap[template];
|
|
|
|
if (!entry) {
|
|
return NextResponse.json({ error: 'Template not found' }, { status: 404 });
|
|
}
|
|
|
|
const { searchParams } = new URL(request.url);
|
|
const locale = resolveLocale(searchParams.get('locale') || undefined);
|
|
const period = (searchParams.get('period') ||
|
|
entry.defaultProps?.period ||
|
|
'weekly') as ShopSummaryPeriod;
|
|
|
|
const html = await render(
|
|
React.createElement(entry.component, {
|
|
locale,
|
|
...(entry.id === 'shop-summary' ? { period } : {}),
|
|
...entry.defaultProps,
|
|
})
|
|
);
|
|
|
|
return new NextResponse(html, {
|
|
headers: {
|
|
'Content-Type': 'text/html; charset=utf-8',
|
|
},
|
|
});
|
|
}
|