diff --git a/src/app/api/submit/route.ts b/src/app/api/submit/route.ts index 57ed31e..99b8b32 100644 --- a/src/app/api/submit/route.ts +++ b/src/app/api/submit/route.ts @@ -1,3 +1,19 @@ +// import { NextResponse } from 'next/server'; + +// export async function POST(req: Request) { +// try { +// const { name, email } = await req.json(); + +// if (!name || !email) { +// return NextResponse.json({ message: 'Name and Email are required' }, { status: 400 }); +// } + +// return NextResponse.json({ message: `Thank you, ${name}!` }); +// } catch { +// return NextResponse.json({ message: 'Server error' }, { status: 500 }); +// } +// } + import { NextResponse } from 'next/server'; export async function POST(req: Request) { @@ -8,8 +24,8 @@ export async function POST(req: Request) { return NextResponse.json({ message: 'Name and Email are required' }, { status: 400 }); } - return NextResponse.json({ message: `Thank you, ${name}!` }); + return NextResponse.json({ message: `Hello ${name}, your form has been submitted successfully!` }); } catch { - return NextResponse.json({ message: 'Server error' }, { status: 500 }); + return NextResponse.json({ message: 'Internal server error' }, { status: 500 }); } } diff --git a/src/app/form/page.tsx b/src/app/form/page.tsx index 03c5df6..109cba1 100644 --- a/src/app/form/page.tsx +++ b/src/app/form/page.tsx @@ -1,25 +1,118 @@ +// 'use client'; + +// import { useState } from 'react'; + +// export default function Form() { +// const [name, setName] = useState(''); +// const [email, setEmail] = useState(''); +// const [message, setMessage] = useState(''); +// const [loading, setLoading] = useState(false); +// const [error, setError] = useState(''); + +// const handleSubmit = async (e: React.FormEvent) => { +// e.preventDefault(); +// setLoading(true); +// setMessage(''); +// setError(''); + +// try { +// const res = await fetch('/api/submit', { +// method: 'POST', +// headers: { 'Content-Type': 'application/json' }, +// body: JSON.stringify({ name, email }), +// }); + +// if (!res.ok) throw new Error('Failed to submit'); +// const data = await res.json(); +// setMessage(data.message); +// } catch { +// setError('Submission failed. Please try again.'); +// } finally { +// setLoading(false); +// } +// }; + +// const handleReset = () => { +// setName(''); +// setEmail(''); +// setMessage(''); +// setError(''); +// }; + +// return ( +//
{message}
} +// {error &&{error}
} +//{message}
} - {error &&{error}
} +{error}
+{message}