From a4c53d419963f0a42488d0a8d85d4f8b7633b1dc Mon Sep 17 00:00:00 2001 From: squirrel <47972284+zksquirrel@users.noreply.github.com> Date: Fri, 3 Jan 2025 18:30:54 +0000 Subject: [PATCH] Update NewsletterForm.tsx --- src/components/Newsletter/NewsletterForm.tsx | 150 +++++++++---------- 1 file changed, 72 insertions(+), 78 deletions(-) diff --git a/src/components/Newsletter/NewsletterForm.tsx b/src/components/Newsletter/NewsletterForm.tsx index f02734f..5f37bee 100644 --- a/src/components/Newsletter/NewsletterForm.tsx +++ b/src/components/Newsletter/NewsletterForm.tsx @@ -1,112 +1,106 @@ -import { useState } from 'react'; +import React, { useState } from "react"; +import styles from "./NewsletterForm.module.css"; // Assuming custom styles are added here -export default function NewsletterForm() { - const [address, setAddress] = useState(''); - const [activeNewsletter, setActiveNewsletter] = useState(null); +const NewsletterForm: React.FC = () => { + const [activeForm, setActiveForm] = useState(null); + const [unifiedAddress, setUnifiedAddress] = useState(""); + const [message, setMessage] = useState(null); + const [error, setError] = useState(null); - const handleButtonClick = (newsletterType) => { - setActiveNewsletter( - activeNewsletter === newsletterType ? null : newsletterType - ); - setAddress(''); + const toggleForm = (formType: string) => { + setActiveForm((prev) => (prev === formType ? null : formType)); + setMessage(null); + setError(null); + setUnifiedAddress(""); // Reset the input field when toggling }; - const handleSubmit = async (e, type) => { - e.preventDefault(); - - if (!address) { - alert('Please enter a Zcash Unified Address'); + const handleSubmit = async (type: string) => { + if (!unifiedAddress.trim()) { + setError("Unified address cannot be empty."); return; } - const apiEndpoint = - type === 'networkstats' - ? '/api/saveNetworkStatsAddress' - : '/api/saveEcosystemNewsAddress'; - try { - const response = await fetch(apiEndpoint, { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ address }), + const response = await fetch(`/api/newsletter/${type}`, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ unifiedAddress }), }); + const result = await response.json(); if (response.ok) { - alert('Your address has been saved successfully!'); - setAddress(''); - setActiveNewsletter(null); + setMessage("Successfully signed up!"); + setUnifiedAddress(""); // Clear the input field } else { - alert('There was an error saving your address. Please try again.'); + setError(result.error || "Failed to sign up. Please try again."); } - } catch (error) { - console.error(error); - alert('An unexpected error occurred.'); + } catch (err) { + setError("An error occurred. Please try again."); } }; return ( -
-
+
+

Sign Up to the Shielded Newsletter

+

+ đź”’ Why Join? +
+ Stay informed and connected, directly in your Zcash shielded wallet. With our newsletter, you can: +
+
+ Ecosystem News: Get a concise weekly summary of notable updates, upcoming events, and community highlights—delivered straight to your shielded memo. +
+ Network Stats: Stay updated on key Zcash network metrics, including supply, transfers, approximate node counts, transactions, and shielded usage statistics—all in one weekly snapshot. +
+
+ ✨ Reimagine Your Wallet: Your wallet isn't just for transactions anymore. It's now a hub for secure, meaningful updates. +
+ 🛠️ Empower Your Community: We're also working on tools to let you create your own shielded newsletters, enabling more users to explore the potential of private, wallet-based communication. +
+
+ 📬 Sign Up Now: Enter a unified address and choose the updates that matter most to you. Let’s redefine how we stay connected while protecting our privacy. +

+ +
- {activeNewsletter && ( -
- handleSubmit( - e, - activeNewsletter === 'networkstats' ? 'networkstats' : 'ecosystemnews' - ) - } - style={{ margin: '20px auto', maxWidth: '400px' }} - > -
); -} +}; + +export default NewsletterForm;