'use client' import YogaImageComponent from "@/components/yoga.image.component"; import {YogaContactUs_Plain} from "@/types/generated-strapi-interfaces/api/yoga-contact-us"; import {RefObject, startTransition, useActionState, useEffect, useRef} from "react"; import {ContactFormState, sendContactUsMail} from "@/actions/contactus-actions"; import clsx from "clsx"; export interface Props { contactUs: YogaContactUs_Plain } const ContactUsComponent = ({ contactUs: { header, firstName, lastName, phone, title, message, email, buttonText } }: Props) => { const initialState = () => { return { firstname: {value: ''}, lastname: {value: ''}, comment: {value: ''}, email: {value: ''}, phone: {value: ''} } as ContactFormState; } const [state, formAction] = useActionState(sendContactUsMail, initialState()); const ref: RefObject = useRef(null) useEffect(() => { if ( state.formState == 'success'){ ref.current?.reset() } }, [state]); return (
{title}

{header}

{ e.preventDefault(); startTransition(() => formAction(new FormData(e.currentTarget))); }} >
{state.firstname.error &&
{state.firstname.error}
}
{state.lastname.error &&
{state.lastname.error}
}
{state.phone.error &&
{state.phone.error}
}
{state.email.error &&
{state.email.error}
}
{state.comment.error &&
{state.comment.error}
}
); } export default ContactUsComponent;