import { BuildingOffice2Icon, CheckCircleIcon, EnvelopeIcon, ExclamationTriangleIcon, PhoneIcon } from '@heroicons/react/24/outline' import { motion } from "motion/react"; import { useState } from "react"; import { useForm } from "react-hook-form"; interface Props { phoneLabel: string phoneValue: string emailLabel: string emailValue: string addressLabel: string addressValue: string serviceAreaLabel: string serviceArea: string firstNameLabel?: string lastNameLabel?: string emailFieldLabel?: string phoneFieldLabel?: string messageLabel?: string firstNamePlaceholder?: string lastNamePlaceholder?: string emailPlaceholder?: string phonePlaceholder?: string messagePlaceholder?: string submitLabel?: string } interface ContactFields { firstName: string lastName: string email: string phone: string message: string } export default function Contact({ phoneLabel, phoneValue, emailLabel, emailValue, addressLabel, addressValue, serviceAreaLabel, serviceArea, firstNameLabel = 'Prénom', lastNameLabel = 'Nom', emailFieldLabel = 'Courriel', phoneFieldLabel = 'Téléphone', messageLabel = 'Message', firstNamePlaceholder = 'Jean', lastNamePlaceholder = 'Tremblay', emailPlaceholder = 'nom@exemple.com', phonePlaceholder = '(514) 555-1234', messagePlaceholder = 'Décrivez votre projet...', submitLabel = 'Envoyer', }: Props) { const inputClass = 'block w-full rounded-md bg-white px-3.5 py-2 text-base text-brand-dark outline-1 -outline-offset-1 outline-brand-200 placeholder:text-brand-400 focus:outline-2 focus:-outline-offset-2 focus:outline-brand-600 dark:bg-white/5 dark:text-white dark:outline-white/10 dark:placeholder:text-brand-400 dark:focus:outline-brand-500' const inputErrorClass = 'block w-full rounded-md bg-white px-3.5 py-2 text-base text-brand-dark outline-1 -outline-offset-1 outline-red-400 placeholder:text-brand-400 focus:outline-2 focus:-outline-offset-2 focus:outline-red-500 dark:bg-white/5 dark:text-white dark:outline-red-500/50 dark:placeholder:text-brand-400' const labelClass = 'block text-sm/6 font-semibold text-brand-dark dark:text-white' const [submitStatus, setSubmitStatus] = useState<"idle" | "success" | "error">("idle") const { register, handleSubmit, formState: { errors, isSubmitting }, } = useForm({ mode: "onTouched" }) async function onSubmit(data: ContactFields) { try { const res = await fetch('/api/contact', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data), }) setSubmitStatus(res.ok ? "success" : "error") } catch { setSubmitStatus("error") } } const fadeUp = (delay: number) => ({ initial: { opacity: 0, y: 18 }, whileInView: { opacity: 1, y: 0 }, viewport: { amount: 0.35, once: false }, transition: { duration: 0.55, ease: [0.22, 1, 0.36, 1] as const, delay }, }) const slideIn = (direction: "left" | "right", delay: number) => ({ initial: { opacity: 0, x: direction === "left" ? -44 : 44 }, whileInView: { opacity: 1, x: 0 }, viewport: { amount: 0.25, once: false }, transition: { duration: 0.65, ease: [0.22, 1, 0.36, 1] as const, delay }, }) return (
{addressLabel}
{addressValue}
{serviceAreaLabel} {serviceArea}
{phoneLabel}
{phoneValue}
{emailLabel}
{emailValue}
{submitStatus === "success" ? (

Message envoyé !

Merci pour votre message. Nous vous répondrons dans les plus brefs délais.

) : (
{errors.firstName &&

{errors.firstName.message}

}
{errors.lastName &&

{errors.lastName.message}

}
{errors.email &&

{errors.email.message}

}
{errors.phone &&

{errors.phone.message}

}