diff --git a/app/[locale]/blog/_components/BlogCTASection.tsx b/app/[locale]/blog/_components/BlogCTASection.tsx index ecb44f0..ec9ad63 100644 --- a/app/[locale]/blog/_components/BlogCTASection.tsx +++ b/app/[locale]/blog/_components/BlogCTASection.tsx @@ -1,17 +1,17 @@ 'use client'; -import { useRef, useEffect } from 'react'; -import Link from 'next/link'; +import { useRef, useEffect, useState } from 'react'; +import { BlogSubFormModal } from '@/components/ui/BlogSubFormModal'; type Props = { - locale: string; title: string; text: string; cta: string; }; -export function BlogCTASection({ locale, title, text, cta }: Props) { +export function BlogCTASection({ title, text, cta }: Props) { const sectionRef = useRef(null); + const [modalOpen, setModalOpen] = useState(false); useEffect(() => { const section = sectionRef.current; @@ -36,35 +36,42 @@ export function BlogCTASection({ locale, title, text, cta }: Props) { }, []); return ( -
-
-
-

- {title} -

-

- {text} -

-
+ <> +
+
+
+

+ {title} +

+

+ {text} +

+
-
- - {cta} - - + {cta} + + +
-
+ + setModalOpen(false)} /> + ); } diff --git a/app/[locale]/blog/page.tsx b/app/[locale]/blog/page.tsx index afc0583..d223997 100644 --- a/app/[locale]/blog/page.tsx +++ b/app/[locale]/blog/page.tsx @@ -3,7 +3,6 @@ import { BlogHero } from "@/app/[locale]/blog/_components/BlogHero"; import { BlogCTASection } from "@/app/[locale]/blog/_components/BlogCTASection"; import { ArticleList } from "@/app/[locale]/blog/[slug]/_components/ArticleList"; import { getTranslations } from "next-intl/server"; -import { BlogSubFormController } from '@/components/ui/BlogSubFormController'; type props = { params: Promise<{ locale: string }>; @@ -16,12 +15,9 @@ export default async function BlogPage({ params }: props) { return (
- - { + const email = (formData.get('email') as string)?.trim(); + + if (!email) return { success: false, error: "L'adresse email est requise." }; + + const emailRe = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; + if (!emailRe.test(email)) { + return { success: false, error: 'Adresse email invalide.' }; + } + + try { + await addContact(email); + return { success: true }; + } catch (err) { + return { success: false, error: 'Une erreur est survenue. Réessaie plus tard.' }; + } +} diff --git a/components/ui/BlogSubFormModal.tsx b/components/ui/BlogSubFormModal.tsx index ce802ae..9f1c1e1 100644 --- a/components/ui/BlogSubFormModal.tsx +++ b/components/ui/BlogSubFormModal.tsx @@ -2,65 +2,47 @@ import { useEffect, useRef, useState, useActionState } from 'react'; import { createPortal } from 'react-dom'; -import { sendContactMail, type ContactFormState } from '@/app/actions/sendContactMail'; +import { subscribeNewsletter, type SubscribeState } from '@/app/actions/subscribeNewsletter'; type Props = { isOpen: boolean; onClose: () => void; }; -type FieldProps = { - label: string; - name: string; - type?: string; - required?: boolean; - textarea?: boolean; - inputRef?: React.RefObject; -}; - -function Field({ label, name, type = 'text', required, textarea, inputRef }: FieldProps) { +function EmailField({ inputRef }: { inputRef: React.RefObject }) { const base = 'w-full font-sans text-sm text-brand-brown bg-white/60 border border-brand-brown/12 rounded-lg px-4 py-3 placeholder:text-brand-brown/25 focus:outline-none focus:border-brand-brown/35 focus:bg-white/80 transition-colors duration-150'; return (
- {textarea ? ( -