Skip to content

Commit 7fc5334

Browse files
committed
Email preview improvements
1 parent a6a71d3 commit 7fc5334

File tree

2 files changed

+42
-27
lines changed

2 files changed

+42
-27
lines changed

apps/dashboard/src/components/email-preview.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,29 @@ import ResizableContainer from './resizable-container';
77

88
class EmailPreviewErrorBoundary extends Component<
99
{ children: ReactNode },
10-
{ hasError: boolean }
10+
{ error: KnownErrors["EmailRenderingError"] | null }
1111
> {
1212
constructor(props: { children: ReactNode }) {
1313
super(props);
14-
this.state = { hasError: false };
14+
this.state = { error: null };
1515
}
1616

1717
static getDerivedStateFromError(error: Error) {
1818
if (error instanceof KnownErrors.EmailRenderingError) {
19-
return { hasError: true };
19+
return { error: error as KnownErrors["EmailRenderingError"] };
2020
}
2121
throw error;
2222
}
2323

2424
render() {
25-
if (this.state.hasError) {
25+
if (this.state.error) {
2626
return (
2727
<div className="flex flex-col items-center p-4 h-full justify-center">
2828
<Typography type="h3" className="mb-2" variant="destructive">
2929
Email Rendering Error
3030
</Typography>
31-
<Typography variant="secondary">
32-
Please check your theme / template source code.
31+
<Typography variant="secondary" className="whitespace-pre-wrap">
32+
{this.state.error.message}
3333
</Typography>
3434
</div>
3535
);

packages/stack-shared/src/helpers/emails.ts

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,46 @@
1-
export const previewTemplateSource = `
1+
import { deindent } from "../utils/strings";
2+
3+
export const previewTemplateSource = deindent`
4+
import { Heading, Section, Button, Link, Column } from "@react-email/components";
25
export const variablesSchema = v => v;
36
export function EmailTemplate() {
4-
return (
5-
<div>
6-
<h2 className="mb-4 text-2xl font-bold">
7+
return <>
8+
<Heading as="h2" className="mb-4 text-2xl font-bold">
79
Header text
8-
</h2>
9-
<p className="mb-4">
10+
</Heading>
11+
<Section className="mb-4">
1012
Body text content with some additional information.
11-
</p>
12-
</div>
13-
);
13+
</Section>
14+
<Row className="mb-4">
15+
<Column>
16+
<Button href="https://example.com">
17+
A button
18+
</Button>
19+
</Column>
20+
<Column>
21+
<Link href="https://example.com">
22+
A link
23+
</Link>
24+
</Column>
25+
</Row>
26+
</>;
1427
}
1528
`;
1629

17-
export const emptyEmailTheme = `import { Html, Tailwind, Body } from '@react-email/components';
18-
export function EmailTheme({ children }: { children: React.ReactNode }) {
19-
return (
20-
<Html>
21-
<Tailwind>
22-
<Body>
23-
{children}
24-
</Body>
25-
</Tailwind>
26-
</Html>
27-
);
28-
}`;
30+
export const emptyEmailTheme = deindent`
31+
import { Html, Tailwind, Body } from '@react-email/components';
32+
export function EmailTheme({ children }: { children: React.ReactNode }) {
33+
return (
34+
<Html>
35+
<Tailwind>
36+
<Body>
37+
{children}
38+
</Body>
39+
</Tailwind>
40+
</Html>
41+
);
42+
}
43+
`;
2944

3045
export const LightEmailTheme = `import { Html, Head, Tailwind, Body, Container } from '@react-email/components';
3146

0 commit comments

Comments
 (0)