From ca5ff42d8f75a4438469f89cc64d6449599f9dce Mon Sep 17 00:00:00 2001 From: bender Date: Wed, 4 Mar 2026 19:07:12 +0000 Subject: [PATCH] Switch to version 1: modified src/components/sections/contact/ContactSplitForm.tsx --- .../sections/contact/ContactSplitForm.tsx | 300 ++++++++++++------ 1 file changed, 202 insertions(+), 98 deletions(-) diff --git a/src/components/sections/contact/ContactSplitForm.tsx b/src/components/sections/contact/ContactSplitForm.tsx index 32c9140..15ed065 100644 --- a/src/components/sections/contact/ContactSplitForm.tsx +++ b/src/components/sections/contact/ContactSplitForm.tsx @@ -1,110 +1,214 @@ "use client"; -import React, { useState } from 'react'; -import { Mail, Phone } from 'lucide-react'; +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"; -interface ContactFormData { - name: string; - email: string; - subject: string; - message: string; +export interface InputField { + name: string; + type: string; + placeholder: string; + required?: boolean; + className?: string; } -export const ContactSplitForm: React.FC = () => { - const [formData, setFormData] = useState({ - name: '', - email: '', - subject: '', - message: '', - }); - const [isSubmitted, setIsSubmitted] = useState(false); +export interface TextareaField { + name: string; + placeholder: string; + rows?: number; + required?: boolean; + className?: string; +} - const handleChange = (e: React.ChangeEvent) => { - const { name, value } = e.target; - setFormData(prev => ({ ...prev, [name]: value })); - }; +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; +} - const handleFormSubmit = (e: React.FormEvent) => { - e.preventDefault(); - setIsSubmitted(true); - setFormData({ name: '', email: '', subject: '', message: '' }); - setTimeout(() => setIsSubmitted(false), 3000); - }; +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 }); - return ( -
-
-
-
-

Contact Us

-

Have questions? We'd love to hear from you.

-
+ // Validate minimum inputs requirement + if (inputs.length < 2) { + throw new Error("ContactSplitForm requires at least 2 inputs"); + } -
-
- -
-

Email

-

hello@company.com

-

We'll respond within 24 hours

-
-
-
- -
-

Phone

-

+1 (555) 123-4567

-

Mon-Fri, 9am-6pm EST

-
-
-
+ // 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 && ( +