Files
calendar/packages/emails/src/renderEmail.ts
T
Omar LópezandGitHub 7c749299bb Enforces explicit type imports (#7158)
* Enforces explicit type imports

* Upgrades typescript-eslint

* Upgrades eslint related dependencies

* Update config

* Sync packages mismatches

* Syncs prettier version

* Linting

* Relocks node version

* Fixes

* Locks @vitejs/plugin-react to 1.3.2

* Linting
2023-02-16 15:39:57 -07:00

24 lines
735 B
TypeScript

import * as ReactDOMServer from "react-dom/server";
import * as templates from "./templates";
function renderEmail<K extends keyof typeof templates>(
template: K,
props: React.ComponentProps<(typeof templates)[K]>
) {
const Component = templates[template];
return (
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
ReactDOMServer.renderToStaticMarkup(Component(props))
// Remove `<RawHtml />` injected scripts
.replace(/<script><\/script>/g, "")
.replace(
"<html>",
`<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">`
)
);
}
export default renderEmail;