File tree 3 files changed +53
-6
lines changed
3 files changed +53
-6
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ import { sendFeedbackEmail } from "@/lib/email/sendFeedbackEmail";
20
20
import { Copy } from "lucide-react" ;
21
21
22
22
const formSchema = z . object ( {
23
- email : z . string ( ) . email ( ) ,
23
+ email : z . string ( ) . email ( ) . optional ( ) ,
24
24
message : z . string ( ) ,
25
25
} ) ;
26
26
@@ -34,15 +34,14 @@ export default function SupportPage() {
34
34
const form = useForm < z . infer < typeof formSchema > > ( {
35
35
resolver : zodResolver ( formSchema ) ,
36
36
defaultValues : {
37
- email : "" ,
38
37
message : "" ,
39
38
} ,
40
39
} ) ;
41
40
42
41
async function onSubmit ( values : z . infer < typeof formSchema > ) {
43
42
const { email, message } = values ;
44
43
45
- await sendFeedbackEmail ( email , message ) ;
44
+ await sendFeedbackEmail ( { emailAddress : email , body : message } ) ;
46
45
47
46
toast ( {
48
47
title : "Feedback sent :)" ,
@@ -66,7 +65,10 @@ export default function SupportPage() {
66
65
render = { ( { field } ) => (
67
66
< FormItem >
68
67
< FormControl >
69
- < Input placeholder = "Email" { ...field } />
68
+ < Input
69
+ placeholder = "Email (optional)"
70
+ { ...field }
71
+ />
70
72
</ FormControl >
71
73
< FormMessage />
72
74
</ FormItem >
Original file line number Diff line number Diff line change 2
2
3
3
import { Resend } from "resend" ;
4
4
import { z } from "zod" ;
5
+ import { envServer } from "../env/server" ;
5
6
6
7
const resend = new Resend ( process . env . RESEND_API_KEY ) ;
7
8
8
9
const sendFeebackEmailToBilalSchema = z . object ( {
9
- emailAddress : z . string ( ) ,
10
+ emailAddress : z . string ( ) . optional ( ) ,
10
11
body : z . string ( ) ,
11
12
} ) ;
12
13
13
- export async function sendFeedbackEmail ( emailAddress : string , body : string ) {
14
+ export async function sendFeedbackEmail ( {
15
+ emailAddress,
16
+ body,
17
+ } : {
18
+ emailAddress ?: string ;
19
+ body : string ;
20
+ } ) {
21
+ if ( envServer . CI ) {
22
+ console . log ( "Skipping email sending on CI" ) ;
23
+ return ;
24
+ }
25
+ if ( envServer . VERCEL_ENV === "development" ) {
26
+ console . log ( "Skipping email sending on development environment" ) ;
27
+ return ;
28
+ }
29
+
14
30
try {
15
31
sendFeebackEmailToBilalSchema . parse ( {
16
32
emailAddress,
Original file line number Diff line number Diff line change
1
+ import { test , expect } from "@playwright/test" ;
2
+
3
+ test . beforeEach ( async ( { page } ) => {
4
+ await page . goto ( "http://localhost:3000/support" ) ;
5
+ } ) ;
6
+
7
+ test ( "Lets user submit feedback without an email address" , async ( { page } ) => {
8
+ await page . getByPlaceholder ( "Enter your message here..." ) . click ( ) ;
9
+ await page
10
+ . getByPlaceholder ( "Enter your message here..." )
11
+ . fill ( "feedback with no email address entered just body" ) ;
12
+ await page . getByRole ( "button" , { name : "Submit" } ) . click ( ) ;
13
+ await expect (
14
+ page . getByText ( "Feedback sent :)" , { exact : true } ) ,
15
+ ) . toBeVisible ( ) ;
16
+ } ) ;
17
+
18
+ test ( "Lets user submit feedback with an email address" , async ( { page } ) => {
19
+ await page . getByPlaceholder ( "Email" ) . click ( ) ;
20
+ await page . getByPlaceholder ( "Email" ) . fill ( "[email protected] " ) ;
21
+ await page . getByPlaceholder ( "Enter your message here..." ) . click ( ) ;
22
+ await page
23
+ . getByPlaceholder ( "Enter your message here..." )
24
+ . fill ( "feedback with no email address entered just body" ) ;
25
+ await page . getByRole ( "button" , { name : "Submit" } ) . click ( ) ;
26
+ await expect (
27
+ page . getByText ( "Feedback sent :)" , { exact : true } ) ,
28
+ ) . toBeVisible ( ) ;
29
+ } ) ;
You can’t perform that action at this time.
0 commit comments