Skip to content

Commit c322ee6

Browse files
committed
Let user submit feedback without providing email address closes #307
1 parent 828615d commit c322ee6

File tree

3 files changed

+53
-6
lines changed

3 files changed

+53
-6
lines changed

app/support/page.tsx

+6-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { sendFeedbackEmail } from "@/lib/email/sendFeedbackEmail";
2020
import { Copy } from "lucide-react";
2121

2222
const formSchema = z.object({
23-
email: z.string().email(),
23+
email: z.string().email().optional(),
2424
message: z.string(),
2525
});
2626

@@ -34,15 +34,14 @@ export default function SupportPage() {
3434
const form = useForm<z.infer<typeof formSchema>>({
3535
resolver: zodResolver(formSchema),
3636
defaultValues: {
37-
email: "",
3837
message: "",
3938
},
4039
});
4140

4241
async function onSubmit(values: z.infer<typeof formSchema>) {
4342
const { email, message } = values;
4443

45-
await sendFeedbackEmail(email, message);
44+
await sendFeedbackEmail({ emailAddress: email, body: message });
4645

4746
toast({
4847
title: "Feedback sent :)",
@@ -66,7 +65,10 @@ export default function SupportPage() {
6665
render={({ field }) => (
6766
<FormItem>
6867
<FormControl>
69-
<Input placeholder="Email" {...field} />
68+
<Input
69+
placeholder="Email (optional)"
70+
{...field}
71+
/>
7072
</FormControl>
7173
<FormMessage />
7274
</FormItem>

lib/email/sendFeedbackEmail.ts

+18-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,31 @@
22

33
import { Resend } from "resend";
44
import { z } from "zod";
5+
import { envServer } from "../env/server";
56

67
const resend = new Resend(process.env.RESEND_API_KEY);
78

89
const sendFeebackEmailToBilalSchema = z.object({
9-
emailAddress: z.string(),
10+
emailAddress: z.string().optional(),
1011
body: z.string(),
1112
});
1213

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+
1430
try {
1531
sendFeebackEmailToBilalSchema.parse({
1632
emailAddress,

tests/pages/feeback-page.spec.ts

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
});

0 commit comments

Comments
 (0)