MCPcopy
hub / github.com/srcbookdev/srcbook / MailingListCard

Function MailingListCard

packages/web/src/components/mailing-list-card.tsx:10–84  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

8import { useSettings } from '@/components/use-settings';
9
10export default function MailingListCard() {
11 const { subscriptionEmail, updateConfig } = useSettings();
12 const [isVisible, setIsVisible] = useState(!subscriptionEmail);
13 const [email, setEmail] = useState('');
14 const [subscribed, setSubscribed] = useState(false);
15
16 const handleClose = async () => {
17 await updateConfig({ subscriptionEmail: 'dismissed' });
18 setIsVisible(false);
19 };
20
21 const handleSubmit: React.FormEventHandler<HTMLFormElement> = async (e) => {
22 e.preventDefault();
23 try {
24 const response = await subscribeToMailingList(email);
25 if (response.success) {
26 setSubscribed(true);
27 await updateConfig({ subscriptionEmail: email });
28 setTimeout(() => {
29 setIsVisible(false);
30 }, 3000);
31 } else {
32 toast.error('There was an error subscribing to the mailing list. Please try again later.');
33 }
34 } catch (error) {
35 toast.error('There was an error subscribing to the mailing list. Please try again later.');
36 console.error('Subscription error:', error);
37 }
38 };
39
40 if (!isVisible) return null;
41
42 return (
43 <Card className="fixed bottom-6 left-6 w-[460px] shadow-lg z-30">
44 <div className="relative">
45 <button
46 className="absolute top-2 right-2 hover:bg-muted p-1 rounded-sm"
47 onClick={handleClose}
48 >
49 <X className="h-4 w-4" />
50 <span className="sr-only">Close</span>
51 </button>
52 <CardContent className="p-6">
53 <div className="flex flex-col gap-2">
54 <Mailbox size={24} />
55 {subscribed ? (
56 <>
57 <h1 className="mt-2 text-lg font-medium">Thank you for subscribing!</h1>
58 <p>We'll keep you updated with the latest news and features.</p>
59 </>
60 ) : (
61 <>
62 <h1 className="mt-2 text-lg font-medium">Join our mailing list!</h1>
63 <p className="">
64 Get the latest updates, early access features, and expert tips delivered to your
65 inbox.
66 </p>
67 <form onSubmit={handleSubmit} className="flex gap-1 py-3">

Callers

nothing calls this directly

Calls 1

useSettingsFunction · 0.90

Tested by

no test coverage detected