Add localStorage to remember email subscription status

- Check localStorage on component mount to show thank you screen if already subscribed
- Save subscription status after successful signup
- Add 'Subscribe with different email' button to reset localStorage
- Prevents duplicate subscription attempts and improves UX
This commit is contained in:
Mary Kate Fain committed 2025-09-24 11:08:47 -05:00
1 parent 399e9a0262
commit 3751cb23fc
1 file changed
+31 -7
+31 -7
View File
@@ -1,4 +1,4 @@
import { useState } from 'react';
import { useState, useEffect } from 'react';
import { ArrowLeft, Mail, CheckCircle } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { Button } from '@/components/ui/button';
@@ -22,6 +22,14 @@ export function EmailSettings() {
const [isSubmitting, setIsSubmitting] = useState(false);
const [isSubmitted, setIsSubmitted] = useState(false);
// Check localStorage on component mount
useEffect(() => {
const hasSubscribed = localStorage.getItem('shakespeare-email-subscribed');
if (hasSubscribed === 'true') {
setIsSubmitted(true);
}
}, []);
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
@@ -108,6 +116,9 @@ export function EmailSettings() {
document.body.removeChild(form);
}, 1000);
// Save subscription status to localStorage
localStorage.setItem('shakespeare-email-subscribed', 'true');
setIsSubmitted(true);
toast({
title: "Successfully subscribed!",
@@ -155,12 +166,25 @@ export function EmailSettings() {
You can opt out at any time using the unsubscribe link in our emails.
</p>
</div>
<Button
onClick={() => navigate('/settings')}
className="w-full"
>
Back to Settings
</Button>
<div className="space-y-2">
<Button
onClick={() => navigate('/settings')}
className="w-full"
>
Back to Settings
</Button>
<Button
onClick={() => {
localStorage.removeItem('shakespeare-email-subscribed');
setIsSubmitted(false);
setEmail('');
}}
variant="outline"
className="w-full text-xs"
>
Subscribe with different email
</Button>
</div>
</div>
</CardContent>
</Card>