1
- 'use client' ;
1
+ import { VercelInviteUserEmail } from '../emails/vercel-invite-user' ;
2
+ import { Resend } from 'resend' ;
2
3
3
4
export default function Page ( ) {
4
- const onSubmit = async ( e ) => {
5
- e . preventDefault ( ) ;
6
- const email = e . target . email . value ;
5
+ async function send ( formData : FormData ) {
6
+ 'use server' ;
7
7
8
- try {
9
- const response = await fetch ( '/api/send' , {
10
- method : 'POST' ,
11
- headers : { 'Content-Type' : 'application/json' } ,
12
- body : JSON . stringify ( { email } ) ,
13
- } ) ;
8
+ const resend = new Resend ( process . env . RESEND_API_KEY ) ;
9
+ const email = formData . get ( 'email' ) as string ;
14
10
15
- if ( ! response . ok ) {
16
- alert ( 'Failed to send email. Try again later.' ) ;
17
- return ;
18
- }
11
+ const { data, error } = await resend . emails . send ( {
12
+ from :
'Vercel <[email protected] >' ,
13
+ to : [ email ] ,
14
+ subject : 'Join team on Vercel' ,
15
+ react : VercelInviteUserEmail ( { } ) ,
16
+ } ) ;
19
17
20
- const json = await response . json ( ) ;
21
- alert ( `Email sent: ${ json . data . id } ` ) ;
18
+ if ( error ) {
19
+ console . log ( error ) ;
22
20
}
23
- catch ( error ) {
24
- console . error ( error ) ;
25
- }
26
- } ;
21
+
22
+ console . log ( data ) ;
23
+ }
27
24
28
25
return (
29
26
< div className = "bg-zinc-950 py-16 sm:py-24 h-[100vh]" >
@@ -35,12 +32,12 @@ export default function Page() {
35
32
< p className = "mx-auto mt-2 max-w-xl text-center text-lg leading-8 text-gray-300" >
36
33
Type your email address to get invited to a team.
37
34
</ p >
38
- < form className = "mx-auto mt-10 flex max-w-md gap-x-4" onSubmit = { onSubmit } >
39
- < label htmlFor = "email-address " className = "sr-only" >
35
+ < form className = "mx-auto mt-10 flex max-w-md gap-x-4" action = { send } >
36
+ < label htmlFor = "email" className = "sr-only" >
40
37
Email address
41
38
</ label >
42
39
< input
43
- id = "email-address "
40
+ id = "email"
44
41
name = "email"
45
42
type = "email"
46
43
required
0 commit comments