From e9c73693cedb72a7738ecc022ab737aa2d1198bc Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 27 Sep 2025 14:29:18 -0500 Subject: [PATCH] Move email newsletter into Settings --- src/AppRouter.tsx | 3 +- src/components/EmailSubscription.tsx | 204 +++++++++++++++++++ src/components/SettingsLayout.tsx | 9 +- src/lib/i18n.ts | 18 -- src/pages/AboutSettings.tsx | 95 ++++----- src/pages/EmailSettings.tsx | 292 --------------------------- src/pages/Settings.tsx | 9 +- 7 files changed, 257 insertions(+), 373 deletions(-) create mode 100644 src/components/EmailSubscription.tsx delete mode 100644 src/pages/EmailSettings.tsx diff --git a/src/AppRouter.tsx b/src/AppRouter.tsx index c0d70908..5558d2db 100644 --- a/src/AppRouter.tsx +++ b/src/AppRouter.tsx @@ -11,7 +11,7 @@ import AISettings from "./pages/AISettings"; import GitSettings from "./pages/GitSettings"; import DataSettings from "./pages/DataSettings"; import AboutSettings from "./pages/AboutSettings"; -import EmailSettings from "./pages/EmailSettings"; + import GitHubOAuth from "./pages/GitHubOAuth"; import { NIP19Page } from "./pages/NIP19Page"; import NotFound from "./pages/NotFound"; @@ -34,7 +34,6 @@ export function AppRouter() { } /> } /> } /> - } /> } /> } /> diff --git a/src/components/EmailSubscription.tsx b/src/components/EmailSubscription.tsx new file mode 100644 index 00000000..3337864a --- /dev/null +++ b/src/components/EmailSubscription.tsx @@ -0,0 +1,204 @@ +import { useState, useEffect } from 'react'; +import { Mail, CheckCircle } from 'lucide-react'; +import { useTranslation } from 'react-i18next'; +import { Button } from '@/components/ui/button'; +import { Input } from '@/components/ui/input'; +import { Label } from '@/components/ui/label'; +import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; +import { useCurrentUser } from '@/hooks/useCurrentUser'; +import { useToast } from '@/hooks/useToast'; +import { nip19 } from 'nostr-tools'; + +export function EmailSubscription() { + const { t } = useTranslation(); + const { user } = useCurrentUser(); + const { toast } = useToast(); + + const [email, setEmail] = useState(''); + const [isSubmitting, setIsSubmitting] = useState(false); + const [isSubmitted, setIsSubmitted] = useState(false); + + const url = new URL('https://pub.us7.list-manage.com/subscribe/post?u=f1f718a93795f42a604d558d8&id=f7271442a0&f_id=00ffa3e4f0'); + const honeypot = `b_${url.searchParams.get('u')}_${url.searchParams.get('id')}`; + const tag = '8982396'; + + // 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(); + + if (!email.trim()) { + toast({ + title: "Email required", + description: "Please enter your email address", + variant: "destructive", + }); + return; + } + + // Basic email validation + const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; + if (!emailRegex.test(email)) { + toast({ + title: "Invalid email", + description: "Please enter a valid email address", + variant: "destructive", + }); + return; + } + + setIsSubmitting(true); + + try { + // Submit to Mailchimp + const form = document.createElement('form'); + form.method = 'POST'; + form.action = url.href; + form.target = '_blank'; // Open in new tab + form.style.display = 'none'; + + // Add email field + const emailInput = document.createElement('input'); + emailInput.type = 'email'; + emailInput.name = 'EMAIL'; + emailInput.value = email.trim(); + form.appendChild(emailInput); + + // Add tag field with the new Shakespeare tag ID + const tagInput = document.createElement('input'); + tagInput.type = 'hidden'; + tagInput.name = 'tags'; + tagInput.value = tag; + form.appendChild(tagInput); + + // Add npub if available + if (user?.pubkey) { + const npubInput = document.createElement('input'); + npubInput.type = 'text'; + npubInput.name = 'NPUB'; + npubInput.value = nip19.npubEncode(user.pubkey); + npubInput.style.display = 'none'; + form.appendChild(npubInput); + } + + // Add honeypot field + const honeypotInput = document.createElement('input'); + honeypotInput.type = 'text'; + honeypotInput.name = honeypot; + honeypotInput.tabIndex = -1; + honeypotInput.style.position = 'absolute'; + honeypotInput.style.left = '-5000px'; + form.appendChild(honeypotInput); + + // Add form to document and submit + document.body.appendChild(form); + form.submit(); + + // Clean up after a short delay + setTimeout(() => { + document.body.removeChild(form); + }, 1000); + + // Save subscription status to localStorage + localStorage.setItem('shakespeare-email-subscribed', 'true'); + + setIsSubmitted(true); + toast({ + title: "Successfully subscribed!", + description: "You'll receive Shakespeare updates and resources occasionally.", + }); + } catch (error) { + console.error('Email signup error:', error); + toast({ + title: "Subscription failed", + description: "There was an error subscribing you to updates. Please try again.", + variant: "destructive", + }); + } finally { + setIsSubmitting(false); + } + }; + + if (isSubmitted) { + return ( + + +
+ +
+

+ Thanks for subscribing! +

+

+ You can opt out at any time using the unsubscribe link in our emails. +

+
+ +
+
+
+ ); + } + + return ( + + + + + {t('emailUpdates')} + + + {t('emailUpdatesDescription')} + + + +
+
+ + setEmail(e.target.value)} + disabled={isSubmitting} + required + /> +
+ +
+ + +

+ You can opt out at any time using the unsubscribe link in our emails. +

+
+
+
+
+ ); +} \ No newline at end of file diff --git a/src/components/SettingsLayout.tsx b/src/components/SettingsLayout.tsx index 200fff49..6cf9ea0c 100644 --- a/src/components/SettingsLayout.tsx +++ b/src/components/SettingsLayout.tsx @@ -3,7 +3,7 @@ import { useNavigate, useLocation, Outlet } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import { Button } from '@/components/ui/button'; import { ScrollArea } from '@/components/ui/scroll-area'; -import { Menu, Bot, GitBranch, Database, Wifi, Settings2, Info, Mail } from 'lucide-react'; +import { Menu, Bot, GitBranch, Database, Wifi, Settings2, Info } from 'lucide-react'; import { ProjectSidebar } from '@/components/ProjectSidebar'; import { useProjectsManager } from '@/hooks/useProjectsManager'; import { useIsMobile } from '@/hooks/useIsMobile'; @@ -56,13 +56,6 @@ const getSettingsItems = (t: (key: string) => string): SettingsItem[] => [ icon: Database, href: '/settings/data', }, - { - id: 'email', - title: t('emailUpdates'), - description: t('emailUpdatesDescription'), - icon: Mail, - href: '/settings/email', - }, { id: 'about', title: t('aboutShakespeare'), diff --git a/src/lib/i18n.ts b/src/lib/i18n.ts index c10614a4..e3c9b300 100644 --- a/src/lib/i18n.ts +++ b/src/lib/i18n.ts @@ -81,9 +81,6 @@ const resources = { dataSettingsDescription: 'Export files and manage local data', emailUpdates: 'Email Updates', emailUpdatesDescription: 'Subscribe to Shakespeare updates and resources', - emailUpdatesDescriptionLong: 'Stay updated with the latest Shakespeare features, tutorials, and resources.', - aboutShakespeareSettings: 'About Shakespeare', - aboutShakespeareSettingsDescription: 'Information about Shakespeare', // Project Sidebar newProject: 'New Project', @@ -393,9 +390,6 @@ const resources = { dataSettingsDescription: 'Exporte arquivos e gerencie dados locais', emailUpdates: 'Atualizações por Email', emailUpdatesDescription: 'Inscreva-se para receber atualizações e recursos do Shakespeare', - emailUpdatesDescriptionLong: 'Mantenha-se atualizado com os recursos mais recentes do Shakespeare, tutoriais e recursos. Enviamos apenas atualizações ocasionais e você pode cancelar a inscrição a qualquer momento.', - aboutShakespeareSettings: 'Sobre o Shakespeare', - aboutShakespeareSettingsDescription: 'Informações sobre o Shakespeare', // Project Sidebar newProject: 'Novo Projeto', @@ -705,9 +699,6 @@ const resources = { dataSettingsDescription: '导出文件和管理本地数据', emailUpdates: '邮件更新', emailUpdatesDescription: '订阅Shakespeare更新和资源', - emailUpdatesDescriptionLong: '及时了解最新的Shakespeare功能、教程和资源。我们只会偶尔发送更新,您可以随时取消订阅。', - aboutShakespeareSettings: '关于Shakespeare', - aboutShakespeareSettingsDescription: '关于Shakespeare的信息', // Project Sidebar newProject: '新项目', @@ -1017,9 +1008,6 @@ const resources = { dataSettingsDescription: 'Fitar da fayiloli da sarrafa bayanan gida', emailUpdates: 'Sabuntawar Imel', emailUpdatesDescription: 'Yi rajista don karbar sabuntawar Shakespeare da albarkatu', - emailUpdatesDescriptionLong: 'Kasance da sabuntawa game da sabbin fasalolin Shakespeare, koyarwa, da albarkatu. Muna aika sabuntawa lokaci-lokaci kawai kuma kuna iya dakatar da rajista koyaushe.', - aboutShakespeareSettings: 'Game da Shakespeare', - aboutShakespeareSettingsDescription: 'Bayani game da Shakespeare', // Project Sidebar newProject: 'Sabon Aikin', @@ -1329,9 +1317,6 @@ const resources = { dataSettingsDescription: 'Gbe awọn faili jade ati ṣakoso data agbegbe', emailUpdates: 'Awọn Imudojuiwọn Imeeli', emailUpdatesDescription: 'Forukọsilẹ fun awọn imudojuiwọn Shakespeare ati awọn ohun elo', - emailUpdatesDescriptionLong: 'Wa pẹlu imudojuiwọn pẹlu awọn ẹya Shakespeare tuntun, awọn ikẹkọ, ati awọn ohun elo. A nfi awọn imudojuiwọn lọọrọọ nikan ranṣẹ ati pe o le da forukọsilẹ duro nigbakugba.', - aboutShakespeareSettings: 'Nipa Shakespeare', - aboutShakespeareSettingsDescription: 'Alaye nipa Shakespeare', // Project Sidebar newProject: 'Iṣẹ akanṣe Tuntun', @@ -1636,9 +1621,6 @@ const resources = { dataSettingsDescription: 'Bupụta faịlụ na jikwaa data mpaghara', emailUpdates: 'Nmelite Email', emailUpdatesDescription: 'Debanye aha maka nmelite Shakespeare na akụrụngwa', - emailUpdatesDescriptionLong: 'Nọrọ na-emelite na atụmatụ Shakespeare ọhụrụ, nkuzi, na akụrụngwa. Anyị na-eziga naanị nmelite mgbe ụfọdụ ma ị nwere ike ịkwụsị ndebanye aha mgbe ọ bụla.', - aboutShakespeareSettings: 'Gbasara Shakespeare', - aboutShakespeareSettingsDescription: 'Ozi gbasara Shakespeare', // Project Sidebar newProject: 'Ọrụ Ọhụrụ', diff --git a/src/pages/AboutSettings.tsx b/src/pages/AboutSettings.tsx index 8c577b8f..8e5e86dd 100644 --- a/src/pages/AboutSettings.tsx +++ b/src/pages/AboutSettings.tsx @@ -1,11 +1,12 @@ import { useState, useEffect } from 'react'; import { useNavigate } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; -import { Info, ExternalLink, Loader2, AlertTriangle, ArrowLeft } from 'lucide-react'; +import { Info, ExternalLink, Loader2, AlertTriangle, ArrowLeft, Code } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion'; import { Alert, AlertDescription } from '@/components/ui/alert'; import { useIsMobile } from '@/hooks/useIsMobile'; +import { EmailSubscription } from '@/components/EmailSubscription'; export function AboutSettings() { const { t } = useTranslation(); @@ -77,52 +78,56 @@ export function AboutSettings() { )} -
- {/* Project Information */} - +
+ {/* Email Updates */} + - {/* License */} - - - -
- - {t('license')} -
-
- - {isLoading ? ( -
- - {t('loadingLicense')} +
+ {/* Project Information */} + + + {/* License */} + + + +
+ + {t('license')}
- ) : error ? ( - - - - {t('failedToLoadLicense')}: {error} - - - ) : license ? ( -
- ) : null} - - - + + + {isLoading ? ( +
+ + {t('loadingLicense')} +
+ ) : error ? ( + + + + {t('failedToLoadLicense')}: {error} + + + ) : license ? ( +
+ ) : null} + + + +
); diff --git a/src/pages/EmailSettings.tsx b/src/pages/EmailSettings.tsx deleted file mode 100644 index efff3f35..00000000 --- a/src/pages/EmailSettings.tsx +++ /dev/null @@ -1,292 +0,0 @@ -import { useState, useEffect } from 'react'; -import { ArrowLeft, Mail, CheckCircle } from 'lucide-react'; -import { useTranslation } from 'react-i18next'; -import { Button } from '@/components/ui/button'; -import { Input } from '@/components/ui/input'; -import { Label } from '@/components/ui/label'; -import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; -import { useIsMobile } from '@/hooks/useIsMobile'; -import { useNavigate } from 'react-router-dom'; -import { useCurrentUser } from '@/hooks/useCurrentUser'; -import { useToast } from '@/hooks/useToast'; -import { nip19 } from 'nostr-tools'; - -export function EmailSettings() { - const { t } = useTranslation(); - const isMobile = useIsMobile(); - const navigate = useNavigate(); - const { user } = useCurrentUser(); - const { toast } = useToast(); - - const [email, setEmail] = useState(''); - const [isSubmitting, setIsSubmitting] = useState(false); - const [isSubmitted, setIsSubmitted] = useState(false); - - const url = new URL('https://pub.us7.list-manage.com/subscribe/post?u=f1f718a93795f42a604d558d8&id=f7271442a0&f_id=00ffa3e4f0'); - const honeypot = `b_${url.searchParams.get('u')}_${url.searchParams.get('id')}`; - const tag = '8982396'; - - // 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(); - - if (!email.trim()) { - toast({ - title: "Email required", - description: "Please enter your email address", - variant: "destructive", - }); - return; - } - - // Basic email validation - const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; - if (!emailRegex.test(email)) { - toast({ - title: "Invalid email", - description: "Please enter a valid email address", - variant: "destructive", - }); - return; - } - - setIsSubmitting(true); - - try { - // Submit to Mailchimp - const form = document.createElement('form'); - form.method = 'POST'; - form.action = url.href; - form.target = '_blank'; // Open in new tab - form.style.display = 'none'; - - // Add email field - const emailInput = document.createElement('input'); - emailInput.type = 'email'; - emailInput.name = 'EMAIL'; - emailInput.value = email.trim(); - form.appendChild(emailInput); - - // Add tag field with the new Shakespeare tag ID - const tagInput = document.createElement('input'); - tagInput.type = 'hidden'; - tagInput.name = 'tags'; - tagInput.value = tag; - form.appendChild(tagInput); - - // Add npub if available - if (user?.pubkey) { - const npubInput = document.createElement('input'); - npubInput.type = 'text'; - npubInput.name = 'NPUB'; - npubInput.value = nip19.npubEncode(user.pubkey); - npubInput.style.display = 'none'; - form.appendChild(npubInput); - } - - // Add honeypot field - const honeypotInput = document.createElement('input'); - honeypotInput.type = 'text'; - honeypotInput.name = honeypot; - honeypotInput.tabIndex = -1; - honeypotInput.style.position = 'absolute'; - honeypotInput.style.left = '-5000px'; - form.appendChild(honeypotInput); - - // Add form to document and submit - document.body.appendChild(form); - form.submit(); - - // Clean up after a short delay - setTimeout(() => { - document.body.removeChild(form); - }, 1000); - - // Save subscription status to localStorage - localStorage.setItem('shakespeare-email-subscribed', 'true'); - - setIsSubmitted(true); - toast({ - title: "Successfully subscribed!", - description: "You'll receive Shakespeare updates and resources occasionally.", - }); - } catch (error) { - console.error('Email signup error:', error); - toast({ - title: "Subscription failed", - description: "There was an error subscribing you to updates. Please try again.", - variant: "destructive", - }); - } finally { - setIsSubmitting(false); - } - }; - - if (isSubmitted) { - return ( -
- {isMobile && ( -
- -
-

- - {t('emailUpdates')} -

-

- {t('emailUpdatesDescriptionLong')} -

-
-
- )} - - {!isMobile && ( -
-

- - {t('emailUpdates')} -

-

- {t('emailUpdatesDescriptionLong')} -

-
- )} - -
- - -
- -
-

- Thanks for subscribing! -

-

- You can opt out at any time using the unsubscribe link in our emails. -

-
-
- - -
-
-
-
-
-
- ); - } - - return ( -
- {isMobile && ( -
- -
-

- - {t('emailUpdates')} -

-

- {t('emailUpdatesDescriptionLong')} -

-
-
- )} - - {!isMobile && ( -
-

- - {t('emailUpdates')} -

-

- {t('emailUpdatesDescriptionLong')} -

-
- )} - -
- - - - Stay Updated with Shakespeare - - - -
-
- - setEmail(e.target.value)} - disabled={isSubmitting} - required - /> -
- -
- - -

- You can opt out at any time using the unsubscribe link in our emails. -

-
-
-
-
-
-
- ); -} - -export default EmailSettings; \ No newline at end of file diff --git a/src/pages/Settings.tsx b/src/pages/Settings.tsx index ecb29350..cf978600 100644 --- a/src/pages/Settings.tsx +++ b/src/pages/Settings.tsx @@ -1,6 +1,6 @@ import { useNavigate } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; -import { Bot, GitBranch, Database, Wifi, Settings2, Info, Mail } from 'lucide-react'; +import { Bot, GitBranch, Database, Wifi, Settings2, Info } from 'lucide-react'; import { useIsMobile } from '@/hooks/useIsMobile'; interface SettingsItem { @@ -48,13 +48,6 @@ const getSettingsItems = (t: (key: string) => string): SettingsItem[] => [ icon: Database, href: '/settings/data', }, - { - id: 'email', - title: t('emailUpdates'), - description: t('emailUpdatesDescription'), - icon: Mail, - href: '/settings/email', - }, { id: 'about', title: t('aboutShakespeare'),