'use client' import { ChangeEvent, useRef, useState } from "react"; import { CheckboxInput, Input, Submit } from "./form"; import { FloatingLabel } from "../floating-label"; export default function ContactForm() { const [anon, setAnon] = useState(false); const formRef = useRef(null); const [status, setStatus] = useState<'success' | 'loading' | 'failed' | 'idle'>('idle'); const [errorMsg, setErrorMsg] = useState(""); const statusMsg = { success: 'Sended!', loading: 'Sending...', failed: 'Failed :(', idle: 'Send!' } const send = async (e: React.FormEvent) => { e.preventDefault(); setStatus('idle'); setErrorMsg(''); if (status == 'loading' || !formRef.current) return; const formData = new FormData(formRef.current); const data = { anon, name: formData.get('name')?.toString(), email: formData.get('email')?.toString(), message: formData.get('message')!.toString() } if ((data.name && data.email) && (data.name.length < 1 || data.email.length < 1) && !data.anon) { setErrorMsg("Name and email are required. If you prefer not to provide them, check the box to send anonymously."); return; } if (data.message.length < 1) { setErrorMsg("What do you want to tell me???"); return; } setStatus('loading'); //process await new Promise(res => setTimeout(res, 2000)); setStatus('success'); } return (
{!anon && <> }