This repository has been archived on 2026-08-11. You can view files and clone it, but cannot push or open issues or pull requests.
Gishen-Email-Templates/app/api/email/[template]/route.ts
Kirubel-Kibru-Yaltopia f9fa3bc83b feat: add Gishen React Email demo with en/am templates
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>
2026-08-07 22:12:21 +03:00

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',
},
});
}