Skip to content

Commit 35e2bb5

Browse files
committed
refactor: update newsletter
1 parent e697a24 commit 35e2bb5

File tree

2 files changed

+8
-107
lines changed

2 files changed

+8
-107
lines changed

app/_components/subscribe.tsx

Lines changed: 7 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,120 +1,22 @@
11
"use client";
22

3-
import { Button } from "@/app/_components/ui/button";
4-
import { Input } from "@/app/_components/ui/input";
5-
import { cn } from "@/app/_utils/cn";
6-
import { LoaderCircle } from "lucide-react";
73
import { usePlausible } from "next-plausible";
8-
import { useState } from "react";
9-
import { ROUTES } from "../_constants/routes";
10-
11-
type FormStatus = "idle" | "loading" | "success" | "error";
4+
import { LinkCustom } from "./link-custom";
125

136
export const SubscribeForm = () => {
147
const plausible = usePlausible()
15-
const [formState, setFormState] = useState({
16-
email: "",
17-
status: "idle" as FormStatus,
18-
message: "",
19-
});
20-
21-
const isLoading = formState.status === "loading";
22-
23-
const handleSubmit = async (e: React.FormEvent) => {
24-
e.preventDefault();
25-
setFormState((prev) => ({ ...prev, status: "loading", message: "" }));
26-
27-
try {
28-
const response = await fetch(ROUTES.email, {
29-
method: "POST",
30-
headers: {
31-
"Content-Type": "application/json",
32-
},
33-
body: JSON.stringify({ email: formState.email }),
34-
});
35-
36-
const data = await response.json();
37-
38-
if (!response.ok) {
39-
throw new Error(data.message || "Failed to subscribe");
40-
}
41-
42-
if (data.success) {
43-
setFormState({
44-
email: "",
45-
status: "success",
46-
message: "Thanks for subscribing! Please check your inbox for a confirmation email (it may be in your spam folder)."
47-
});
48-
} else {
49-
setFormState((prev) => ({
50-
...prev,
51-
status: "error",
52-
message: data.message || "Failed to subscribe"
53-
}));
54-
}
55-
} catch (error) {
56-
console.error("Subscription error:", error);
57-
setFormState((prev) => ({
58-
...prev,
59-
status: "error",
60-
message: error instanceof Error ? error.message : "Failed to subscribe"
61-
}));
62-
}
63-
};
648

659
return (
6610
<section className="flex flex-col mt-10 items-center justify-center py-10 px-4 text-center border border-neutral-400 dark:border-neutral-600 rounded-xl" aria-labelledby="subscribe-title">
6711
<h2 id="subscribe-title" className="text-2xl font-bold mb-5 text-foreground">
6812
Get notified when new patterns are added!
6913
</h2>
70-
<form onSubmit={handleSubmit} className="space-y-4">
71-
<div className="space-y-2">
72-
<div className="flex flex-col md:flex-row gap-2">
73-
<Input
74-
placeholder="[email protected]"
75-
type="email"
76-
className="w-full md:w-[300px]"
77-
value={formState.email}
78-
onChange={(e) => setFormState((prev) => ({ ...prev, email: e.target.value }))}
79-
disabled={isLoading}
80-
required
81-
/>
82-
<Button
83-
type="submit"
84-
disabled={isLoading}
85-
data-loading={isLoading}
86-
variant="outline"
87-
onClick={() => plausible('subscribe')}
88-
>
89-
<span className="group-data-[loading=true]:text-transparent">
90-
Notify me
91-
</span>
92-
{isLoading && (
93-
<div className="absolute inset-0 flex items-center justify-center">
94-
<LoaderCircle
95-
className="animate-spin"
96-
size={16}
97-
strokeWidth={2}
98-
aria-hidden="true"
99-
/>
100-
</div>
101-
)}
102-
</Button>
103-
</div>
104-
{formState.message && (
105-
<p
106-
className={cn(
107-
"mt-2 text-sm",
108-
formState.status === "error" ? "text-destructive" : "text-muted-foreground",
109-
)}
110-
role="alert"
111-
aria-live="polite"
112-
>
113-
{formState.message}
114-
</p>
115-
)}
116-
</div>
117-
</form>
14+
<p className="text-muted-foreground max-w-xl mx-auto mb-5">
15+
Subscribe to my newsletter "David's Dev Diary" for the latest updates on UX Patterns for Devs.
16+
</p>
17+
18+
<LinkCustom variant="neutral" href="https://thedaviddias.substack.com/" onClick={() => plausible('subscribe')}>Subscribe</LinkCustom>
19+
11820
</section>
11921
);
12022
}

next.config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import bundleAnalyzer from '@next/bundle-analyzer';
22
import { withSentryConfig } from '@sentry/nextjs';
3-
import { withPlausible } from 'next-plausible';
43
import nextra from 'nextra';
54

65
const withNextra = nextra({
@@ -77,7 +76,7 @@ const nextConfig = withBundleAnalyzer(
7776
})
7877
)
7978

80-
export default withSentryConfig(withPlausible(nextConfig), {
79+
export default withSentryConfig(nextConfig, {
8180
// For all available options, see:
8281
// https://github.com/getsentry/sentry-webpack-plugin#options
8382

0 commit comments

Comments
 (0)