Skip to content

Commit b6b027c

Browse files
feat(react-email): better resend integration flow (#2647)
Co-authored-by: Zeno Rocha <zno.rocha@gmail.com>
1 parent 4cbb83f commit b6b027c

File tree

7 files changed

+88
-34
lines changed

7 files changed

+88
-34
lines changed

.changeset/cold-olives-begin.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-email": patch
3+
---
4+
5+
improved integration setup flow

.changeset/early-paths-cross.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@react-email/preview-server": patch
3+
---
4+
5+
advise `npx` to run email setup command

packages/preview-server/src/components/toolbar.tsx

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import * as Tabs from '@radix-ui/react-tabs';
44
import { LayoutGroup } from 'framer-motion';
55
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
6+
import type { ComponentProps } from 'react';
67
import * as React from 'react';
78
import type { CompatibilityCheckingResult } from '../actions/email-validation/check-compatibility';
89
import { isBuilding } from '../app/env';
@@ -183,7 +184,7 @@ const ToolbarInner = ({
183184
(activeTab === 'compatibility' &&
184185
'The Compatibility tab shows how well the HTML/CSS is supported across mail clients like Outlook, Gmail, etc. Powered by Can I Email.') ||
185186
(activeTab === 'resend' &&
186-
"The Resend tab allows you to upload your React Email's HTML using the Templates API. It does not yet upload with variables.") ||
187+
'The Resend tab allows you to upload your React Email code using the Resend Templates API.') ||
187188
'Info'
188189
}
189190
>
@@ -288,9 +289,12 @@ const ToolbarInner = ({
288289
) : (
289290
<SuccessWrapper>
290291
<SuccessTitle>Connect to Resend</SuccessTitle>
291-
<SuccessDescription>
292-
Run <CodeSnippet>email resend setup re_xxxxxx</CodeSnippet>{' '}
293-
to connect your Resend account and refresh.
292+
<SuccessDescription className="max-w-lg">
293+
Run{' '}
294+
<CodeSnippet>
295+
npx react-email@latest resend setup
296+
</CodeSnippet>{' '}
297+
on your terminal to connect your Resend account.
294298
</SuccessDescription>
295299
</SuccessWrapper>
296300
)}
@@ -340,15 +344,34 @@ const SuccessIcon = () => {
340344
);
341345
};
342346

343-
const SuccessTitle = ({ children }) => {
347+
const SuccessTitle = ({
348+
children,
349+
className,
350+
...props
351+
}: ComponentProps<'h3'>) => {
344352
return (
345-
<h3 className="text-slate-12 font-medium text-base mb-1">{children}</h3>
353+
<h3
354+
className={cn('text-slate-12 font-medium text-base mb-1', className)}
355+
{...props}
356+
>
357+
{children}
358+
</h3>
346359
);
347360
};
348361

349-
const SuccessDescription = ({ children }) => {
362+
const SuccessDescription = ({
363+
children,
364+
className,
365+
...props
366+
}: ComponentProps<'p'>) => {
350367
return (
351-
<p className="text-slate-11 text-sm text-center max-w-[320px]">
368+
<p
369+
className={cn(
370+
'text-slate-11 text-sm text-center max-w-[320px]',
371+
className,
372+
)}
373+
{...props}
374+
>
352375
{children}
353376
</p>
354377
);

packages/react-email/src/commands/resend-setup.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import logSymbols from 'log-symbols';
2+
import { conf } from '../../utils/conf.js';
3+
4+
export async function resendReset() {
5+
conf.delete('resendApiKey');
6+
7+
console.info(`${logSymbols.success} Resend API Key successfully deleted`);
8+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import logSymbols from 'log-symbols';
2+
import prompts from 'prompts';
3+
import { conf } from '../../utils/conf.js';
4+
import { styleText } from '../../utils/style-text.js';
5+
6+
export async function resendSetup() {
7+
const previousValue = conf.get('resendApiKey');
8+
if (typeof previousValue === 'string' && previousValue.length > 0) {
9+
console.info(
10+
`You already have a Resend API Key configured (${styleText('grey', previousValue.slice(0, 11))}...), continuing will replace it.`,
11+
);
12+
}
13+
14+
const { apiKey } = await prompts({
15+
type: 'password',
16+
name: 'apiKey',
17+
message: 'Enter your API Key (make sure it has "Full Access")',
18+
});
19+
20+
if (apiKey?.trim().length > 0) {
21+
conf.set('resendApiKey', apiKey);
22+
console.info(
23+
`${logSymbols.success} Resend integration successfully set up`,
24+
);
25+
console.info(
26+
`You can always remove it with ${styleText('green', 'npx react-email@latest resend reset')}`,
27+
);
28+
}
29+
}

packages/react-email/src/index.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { program } from 'commander';
33
import { build } from './commands/build.js';
44
import { dev } from './commands/dev.js';
55
import { exportTemplates } from './commands/export.js';
6-
import { resendSetup } from './commands/resend-setup.js';
6+
import { resendReset } from './commands/resend/reset.js';
7+
import { resendSetup } from './commands/resend/setup.js';
78
import { start } from './commands/start.js';
89
import { packageJson } from './utils/packageJson.js';
910

@@ -53,13 +54,18 @@ program
5354
exportTemplates(outDir, srcDir, { silent, plainText, pretty }),
5455
);
5556

56-
program
57-
.command('resend')
57+
const resend = program.command('resend');
58+
59+
resend
5860
.command('setup')
5961
.description(
6062
'Sets up the integration between the React Email CLI, and your Resend account through an API Key',
6163
)
62-
.argument('apiKey', 'API Key for use setting up the integration')
6364
.action(resendSetup);
6465

66+
resend
67+
.command('reset')
68+
.description('Deletes your API Key from the React Email configuration')
69+
.action(resendReset);
70+
6571
program.parse();

0 commit comments

Comments
 (0)