Skip to content

Commit e155434

Browse files
liamrosspsugihara
andauthored
fix: prevent intercept error when from is object (#393)
* fix: prevent error when `from` is object this prevents the preview page breaking when `from` is an object instead of a string * ammend intercepts/mock as manual test * add changeset Co-authored-by: Peter Sugihara <[email protected]>
1 parent aaee45b commit e155434

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

.changeset/sweet-berries-know.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"mailing": patch
3+
"mailing-core": patch
4+
---
5+
6+
fix: prevent intercept error when from is object

packages/cli/src/components/Intercept.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,14 @@ const Intercept: React.FC<InterceptProps> = ({ data }) => {
101101
<div>
102102
<div>Subject: {data.subject ? `"${data.subject}"` : "MISSING"}</div>
103103
{data.to && <div>To: {data.to}</div>}
104-
<div>From: {data.from || "MISSING"}</div>
104+
<div>
105+
From:{' '}
106+
{!data.from
107+
? 'MISSING'
108+
: typeof data.from === 'string'
109+
? data.from
110+
: `${data.from.name} <${data.from.address}>`}
111+
</div>
105112
{data.cc && <div>CC: {data.cc}</div>}
106113
{data.bcc && <div>BCC: {data.bcc}</div>}
107114
</div>

packages/cli/src/custom.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ type Intercept = {
22
id: string;
33
html: string;
44
to?: string | string[];
5-
from?: string;
5+
from?: string | { name: string; address: string };
66
subject?: string;
77
cc?: string | string[];
88
bcc?: string | string[];

packages/cli/src/pages/intercepts/mock.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const ShowIntercept = () => {
55
id: "mock",
66
html: "<html><body><h1>Title</h1>hope it's not too strict</body></html>",
77
to: "peter s. <[email protected]>",
8-
8+
from: { name: "peter", address: "peter[email protected]" },
99
subject: "A test email",
1010
};
1111

0 commit comments

Comments
 (0)