From b2f9a7de7dcb80710ae8c428b093d74ed233406f Mon Sep 17 00:00:00 2001 From: JeffEmmett <20747463-JeffEmmett@users.noreply.replit.com> Date: Wed, 21 May 2025 11:52:34 +0000 Subject: [PATCH] Add newsletter signup to the community section and allow users to subscribe Implements a newsletter subscription form with email validation using React Query mutation in CommunitySection and removes NewsletterSection component. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 88cd88e4-2dbe-4df6-8c8a-7e38f13ef1ec Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/af8dabca-e746-4e53-9c29-d8d4d9cf30f5/d51bd366-771e-4a50-bff0-f3d09af0d72a.jpg --- .../community/community-section.tsx | 108 +++++++++++++++++- .../newsletter/newsletter-section.tsx | 100 +++++++++++++++- client/src/pages/home-page.tsx | 2 - 3 files changed, 206 insertions(+), 4 deletions(-) diff --git a/client/src/components/community/community-section.tsx b/client/src/components/community/community-section.tsx index 018a4c3..e0dfc84 100644 --- a/client/src/components/community/community-section.tsx +++ b/client/src/components/community/community-section.tsx @@ -3,10 +3,64 @@ import { Testimonial } from "./testimonial"; import { useAuth } from "@/hooks/use-auth"; import { Link } from "wouter"; import { Card, CardContent } from "@/components/ui/card"; +import { useMutation } from "@tanstack/react-query"; +import { apiRequest } from "@/lib/queryClient"; +import { useToast } from "@/hooks/use-toast"; +import { Loader2 } from "lucide-react"; export function CommunitySection() { const { user } = useAuth(); + const { toast } = useToast(); const [iframeLoaded, setIframeLoaded] = useState(false); + const [email, setEmail] = useState(""); + const [agreedToTerms, setAgreedToTerms] = useState(false); + + const newsletterMutation = useMutation({ + mutationFn: async (newsletterData: { email: string, agreedToTerms: boolean }) => { + const res = await apiRequest("POST", "/api/newsletter", newsletterData); + return await res.json(); + }, + onSuccess: () => { + toast({ + title: "Subscription successful", + description: "Thank you for subscribing to our newsletter!", + }); + // Reset form + setEmail(""); + setAgreedToTerms(false); + }, + onError: (error: Error) => { + toast({ + title: "Subscription failed", + description: error.message, + variant: "destructive", + }); + }, + }); + + const handleNewsletterSubmit = (e: React.FormEvent) => { + e.preventDefault(); + + if (!email) { + toast({ + title: "Email required", + description: "Please enter your email address", + variant: "destructive", + }); + return; + } + + if (!agreedToTerms) { + toast({ + title: "Consent required", + description: "Please agree to receive emails from Pilates with Fadia", + variant: "destructive", + }); + return; + } + + newsletterMutation.mutate({ email, agreedToTerms }); + }; const testimonials = [ { @@ -50,9 +104,61 @@ export function CommunitySection() {
+
I curate a growing community of like-minded individuals committed to health, wellness, and positive growth.
+ + {/* Newsletter Section */} ++ Stay updated with wellness tips, special class offerings, and community events +
+ +
Stay updated with wellness tips, special class offerings, and community events
diff --git a/client/src/pages/home-page.tsx b/client/src/pages/home-page.tsx
index 24e31ea..69c0f47 100644
--- a/client/src/pages/home-page.tsx
+++ b/client/src/pages/home-page.tsx
@@ -3,7 +3,6 @@ import { HeroSection } from "@/components/home/hero-section";
import { AboutSection } from "@/components/about/about-section";
import { ClassesSection } from "@/components/classes/classes-section";
import { CommunitySection } from "@/components/community/community-section";
-import { NewsletterSection } from "@/components/newsletter/newsletter-section";
import { ContactSection } from "@/components/contact/contact-section";
import { CTASection } from "@/components/home/cta-section";
import { useEffect } from "react";
@@ -20,7 +19,6 @@ export default function HomePage() {