From 49f25baee17e4573cacbcda7fe2a458db2e18b66 Mon Sep 17 00:00:00 2001 From: bender Date: Mon, 9 Mar 2026 08:26:33 +0000 Subject: [PATCH] Switch to version 1: modified src/components/sections/contact/ContactSplitForm.tsx --- .../sections/contact/ContactSplitForm.tsx | 251 +++++++++++++++--- 1 file changed, 208 insertions(+), 43 deletions(-) diff --git a/src/components/sections/contact/ContactSplitForm.tsx b/src/components/sections/contact/ContactSplitForm.tsx index 3537626..15ed065 100644 --- a/src/components/sections/contact/ContactSplitForm.tsx +++ b/src/components/sections/contact/ContactSplitForm.tsx @@ -1,49 +1,214 @@ -import React, { useState } from "react"; +"use client"; + +import { useState } from "react"; +import TextAnimation from "@/components/text/TextAnimation"; +import Button from "@/components/button/Button"; +import Input from "@/components/form/Input"; +import Textarea from "@/components/form/Textarea"; +import MediaContent from "@/components/shared/MediaContent"; +import { cls, shouldUseInvertedText } from "@/lib/utils"; +import { useTheme } from "@/providers/themeProvider/ThemeProvider"; +import { useButtonAnimation } from "@/components/hooks/useButtonAnimation"; +import { getButtonProps } from "@/lib/buttonUtils"; +import type { AnimationType } from "@/components/text/types"; +import type { ButtonAnimationType } from "@/types/button"; +import {sendContactEmail} from "@/utils/sendContactEmail"; + +export interface InputField { + name: string; + type: string; + placeholder: string; + required?: boolean; + className?: string; +} + +export interface TextareaField { + name: string; + placeholder: string; + rows?: number; + required?: boolean; + className?: string; +} interface ContactSplitFormProps { - tag: string; - title: string; - description: string; - background?: { variant: string }; - useInvertedBackground?: boolean; - inputPlaceholder?: string; - buttonText?: string; - termsText?: string; + title: string; + description: string; + inputs: InputField[]; + textarea?: TextareaField; + useInvertedBackground: boolean; + imageSrc?: string; + videoSrc?: string; + imageAlt?: string; + videoAriaLabel?: string; + mediaPosition?: "left" | "right"; + mediaAnimation: ButtonAnimationType; + buttonText?: string; + onSubmit?: (data: Record) => void; + ariaLabel?: string; + className?: string; + containerClassName?: string; + contentClassName?: string; + formCardClassName?: string; + titleClassName?: string; + descriptionClassName?: string; + buttonClassName?: string; + buttonTextClassName?: string; + mediaWrapperClassName?: string; + mediaClassName?: string; } -export default function ContactSplitForm({ - tag, - title, - description, - background = { variant: "sparkles-gradient" }, - useInvertedBackground = false, - inputPlaceholder = "Enter your email", buttonText = "Sign Up", termsText = "By clicking Sign Up you're confirming that you agree with our Terms and Conditions."}: ContactSplitFormProps) { - const [email, setEmail] = useState(""); +const ContactSplitForm = ({ + title, + description, + inputs, + textarea, + useInvertedBackground, + imageSrc, + videoSrc, + imageAlt = "", + videoAriaLabel = "Contact section video", + mediaPosition = "right", + mediaAnimation, + buttonText = "Submit", + onSubmit, + ariaLabel = "Contact section", + className = "", + containerClassName = "", + contentClassName = "", + formCardClassName = "", + titleClassName = "", + descriptionClassName = "", + buttonClassName = "", + buttonTextClassName = "", + mediaWrapperClassName = "", + mediaClassName = "", +}: ContactSplitFormProps) => { + const theme = useTheme(); + const shouldUseLightText = shouldUseInvertedText(useInvertedBackground, theme.cardStyle); + const { containerRef: mediaContainerRef } = useButtonAnimation({ animationType: mediaAnimation }); - const handleSubmit = (e: React.FormEvent) => { - e.preventDefault(); - setEmail(""); - }; + // Validate minimum inputs requirement + if (inputs.length < 2) { + throw new Error("ContactSplitForm requires at least 2 inputs"); + } - return ( -
-
{tag}
-

{title}

-

{description}

-
- setEmail(e.target.value)} - required - className="contact-input" - /> - -
-

{termsText}

-
- ); -} + // Initialize form data dynamically + const initialFormData: Record = {}; + inputs.forEach(input => { + initialFormData[input.name] = ""; + }); + if (textarea) { + initialFormData[textarea.name] = ""; + } + + const [formData, setFormData] = useState(initialFormData); + + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + try { + await sendContactEmail({ formData }); + console.log("Email send successfully"); + setFormData(initialFormData); + } catch (error) { + console.error("Failed to send email:", error); + } + }; + + const getButtonConfigProps = () => { + if (theme.defaultButtonVariant === "hover-bubble") { + return { bgClassName: "w-full" }; + } + if (theme.defaultButtonVariant === "icon-arrow") { + return { className: "justify-between" }; + } + return {}; + }; + + const formContent = ( +
+
+
+ + + +
+ +
+ {inputs.map((input) => ( + setFormData({ ...formData, [input.name]: value })} + required={input.required} + ariaLabel={input.placeholder} + className={input.className} + /> + ))} + + {textarea && ( +