diff --git a/server.js b/server.js index f0c3737..325aa3c 100644 --- a/server.js +++ b/server.js @@ -85,7 +85,7 @@ function contactRateLimit(req, res, next) { app.post('/api/contact', contactRateLimit, async (req, res) => { try { - const { name, email, message, _honey } = req.body ?? {} + const { name, email, message, subscribe, _honey } = req.body ?? {} // Honeypot — silently discard if filled by a bot if (_honey) { @@ -121,34 +121,37 @@ app.post('/api/contact', contactRateLimit, async (req, res) => { }) const resend = new Resend(process.env.RESEND_API_KEY) - const { firstName, lastName } = splitName(trimmedName) - const contactResend = new Resend(process.env.RESEND_CONTACTS_API_KEY ?? process.env.RESEND_API_KEY) - try { - const { error: contactError } = await contactResend.contacts.create({ - email: trimmedEmail, - firstName, - lastName, - unsubscribed: false, - ...(process.env.RESEND_SEGMENT_ID - ? { segments: [{ id: process.env.RESEND_SEGMENT_ID }] } - : {}), - }) + if (subscribe === true) { + const { firstName, lastName } = splitName(trimmedName) + const contactResend = new Resend(process.env.RESEND_CONTACTS_API_KEY ?? process.env.RESEND_API_KEY) - if (contactError) { - const { error: updateError } = await contactResend.contacts.update({ + try { + const { error: contactError } = await contactResend.contacts.create({ email: trimmedEmail, firstName, lastName, unsubscribed: false, + ...(process.env.RESEND_SEGMENT_ID + ? { segments: [{ id: process.env.RESEND_SEGMENT_ID }] } + : {}), }) - if (updateError) { - console.error('[contact] contact sync error:', updateError) + if (contactError) { + const { error: updateError } = await contactResend.contacts.update({ + email: trimmedEmail, + firstName, + lastName, + unsubscribed: false, + }) + + if (updateError) { + console.error('[contact] contact sync error:', updateError) + } } + } catch (contactSyncErr) { + console.error('[contact] contact sync exception:', contactSyncErr) } - } catch (contactSyncErr) { - console.error('[contact] contact sync exception:', contactSyncErr) } const { error } = await resend.emails.send({ diff --git a/src/App.css b/src/App.css index 6800955..ef4191f 100644 --- a/src/App.css +++ b/src/App.css @@ -566,6 +566,33 @@ resize: vertical; } +.contact-consent { + display: flex; + flex-direction: row; + align-items: flex-start; + gap: 0.75rem; + font-family: 'Barlow Condensed', sans-serif; + font-size: 1rem; + font-weight: 400; + letter-spacing: normal; + line-height: 1.5; + text-transform: none; + color: #d8c79e; +} + +.contact-consent input { + width: 1rem; + height: 1rem; + margin-top: 0.2rem; + padding: 0; + flex: 0 0 auto; + accent-color: #c8860a; +} + +.contact-consent span { + display: block; +} + .contact-form .btn-primary { justify-content: center; width: 100%; diff --git a/src/App.tsx b/src/App.tsx index 8808717..079b9e2 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -105,6 +105,7 @@ function AmazonMusicIcon() { function ContactForm() { const navigate = useNavigate() const [fields, setFields] = useState({ name: '', email: '', message: '' }) + const [subscribe, setSubscribe] = useState(false) const [honey, setHoney] = useState('') const [status, setStatus] = useState<'idle' | 'submitting' | 'error'>('idle') const [errorMsg, setErrorMsg] = useState('') @@ -121,7 +122,7 @@ function ContactForm() { const res = await fetch('/api/contact', { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ ...fields, _honey: honey }), + body: JSON.stringify({ ...fields, subscribe, _honey: honey }), }) if (!res.ok) { const data = await res.json().catch(() => ({})) @@ -159,6 +160,14 @@ function ContactForm() { Message