diff --git a/src/components/sections/contact/ContactSplitForm.tsx b/src/components/sections/contact/ContactSplitForm.tsx index 4416cad..15ed065 100644 --- a/src/components/sections/contact/ContactSplitForm.tsx +++ b/src/components/sections/contact/ContactSplitForm.tsx @@ -1,59 +1,214 @@ -import React, { useState } from "react"; -import { cn } from "@/lib/utils"; +"use client"; -export interface ContactSplitFormProps { - tag?: string; - title: string; - description: string; - useInvertedBackground?: boolean; - inputPlaceholder?: string; - buttonText?: string; - className?: string; - containerClassName?: string; +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 const ContactSplitForm: React.FC = ({ - tag, - title, - description, - useInvertedBackground = false, - inputPlaceholder = "Enter your email", buttonText = "Sign Up", className, - containerClassName -}) => { - const [email, setEmail] = useState(""); +export interface TextareaField { + name: string; + placeholder: string; + rows?: number; + required?: boolean; + className?: string; +} - const handleSubmit = (e: React.FormEvent) => { - e.preventDefault(); - setEmail(""); - }; +interface ContactSplitFormProps { + 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; +} - return ( -
-
- {tag &&

{tag}

} -

{title}

-

{description}

+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 }); -
- setEmail(e.target.value)} - className="w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-primary" - required - /> - -
-
-
- ); + // Validate minimum inputs requirement + if (inputs.length < 2) { + throw new Error("ContactSplitForm requires at least 2 inputs"); + } + + // 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 && ( +