diff --git a/app/components/ContactForm.tsx b/app/components/ContactForm.tsx index fee32c2..078770e 100644 --- a/app/components/ContactForm.tsx +++ b/app/components/ContactForm.tsx @@ -1,18 +1,27 @@ 'use client'; -import { useState } from 'react'; +import { useState, useEffect, Suspense } from 'react'; +import { useSearchParams } from 'next/navigation'; -export default function ContactForm() { +function ContactFormInner() { + const searchParams = useSearchParams(); const [formData, setFormData] = useState({ name: '', phone: '', email: '', - service: 'RPA 자동화', + service: '외주 개발 문의', message: '', }); const [status, setStatus] = useState<'idle' | 'loading' | 'success' | 'error'>('idle'); const [errorMessage, setErrorMessage] = useState(''); + useEffect(() => { + const serviceParam = searchParams.get('service'); + if (serviceParam) { + setFormData((prev) => ({ ...prev, service: serviceParam })); + } + }, [searchParams]); + const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setStatus('loading'); @@ -21,29 +30,13 @@ export default function ContactForm() { try { const response = await fetch('/api/contact', { method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, + headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(formData), }); - const data = await response.json(); - - if (!response.ok) { - throw new Error(data.error || '문의 전송에 실패했습니다.'); - } - + if (!response.ok) throw new Error(data.error || '문의 전송에 실패했습니다.'); setStatus('success'); - // 폼 초기화 - setFormData({ - name: '', - phone: '', - email: '', - service: 'RPA 자동화', - message: '', - }); - - // 3초 후 성공 메시지 숨기기 + setFormData({ name: '', phone: '', email: '', service: '외주 개발 문의', message: '' }); setTimeout(() => setStatus('idle'), 5000); } catch (error) { setStatus('error'); @@ -54,133 +47,129 @@ export default function ContactForm() { const handleChange = ( e: React.ChangeEvent ) => { - setFormData((prev) => ({ - ...prev, - [e.target.name]: e.target.value, - })); + setFormData((prev) => ({ ...prev, [e.target.name]: e.target.value })); }; return ( -
-
-
-
- - -
-
- - -
-
- + +
-
-
- - - - - - - -
- -
- - -
- - {status === 'success' && ( -
- ✅ 문의가 성공적으로 전송되었습니다! 24시간 이내 답변드리겠습니다. -
- )} - - {status === 'error' && ( -
- ❌ {errorMessage} -
- )} - - - - -
-
-

또는 아래 연락처로 직접 문의주세요

- + placeholder="010-0000-0000" + className="w-full px-3.5 py-2.5 text-sm border border-[#dbe8ff] rounded-xl focus:ring-2 focus:ring-[#1a56db] focus:border-[#1a56db] outline-none bg-white disabled:bg-slate-50" + />
-
+ +
+ + +
+ +
+ + +
+ +
+ +