feat: wip invoice paper template server-side

This commit is contained in:
Ahmed Bouhuolia
2024-11-05 13:33:22 +02:00
parent 51aec8d8b3
commit 22ea557337
5 changed files with 136 additions and 90 deletions

View File

@@ -0,0 +1,36 @@
import { renderToString } from 'react-dom/server';
import createCache from '@emotion/cache';
import {
InvoicePaperTemplate,
InvoicePaperTemplateProps,
} from '../components/InvoicePaperTemplate';
import { PaperTemplateLayout } from '../components/PaperTemplateLayout';
import { extractCritical } from '@emotion/server';
export const renderInvoicePaperTemplateHtml = (
props: InvoicePaperTemplateProps
) => {
const key = 'invoice-paper-template';
const cache = createCache({ key });
const renderedHtml = renderToString(
<PaperTemplateLayout cache={cache}>
<InvoicePaperTemplate {...props} />
</PaperTemplateLayout>
);
const { html, css, ids } = extractCritical(renderedHtml);
return `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Invoice</title>
<style data-emotion="${key} ${ids.join(' ')}">${css}</style>
</head>
<body>
<div id="root">${html}</div>
</body>
</html>`;
};