diff --git a/src/app/api/reservation/route.ts b/src/app/api/reservation/route.ts new file mode 100644 index 0000000..7e25f0c --- /dev/null +++ b/src/app/api/reservation/route.ts @@ -0,0 +1,123 @@ +import { NextRequest, NextResponse } from 'next/server'; + +interface ReservationRequest { + name: string; + email: string; + phone: string; + guests: string; + date: string; +} + +export async function POST(request: NextRequest) { + try { + const body: ReservationRequest = await request.json(); + const { name, email, phone, guests, date } = body; + + if (!name || !email || !phone || !guests || !date) { + return NextResponse.json( + { error: 'All fields are required' }, + { status: 400 } + ); + } + + const emailContent = ` +

Reservation Confirmation

+

Dear ${name},

+

Thank you for your reservation at Chestnut!

+

Reservation Details:

+ +

We look forward to welcoming you to our intimate dining experience.

+

If you have any questions, please contact us at reservations@chestnutcork.ie or +353 (0)21 555 0123

+

Best regards,
The Chestnut Team

+ `; + + const smsContent = `Hello ${name}, your reservation at Chestnut has been confirmed for ${date} for ${guests} guests. We'll send a confirmation email to ${email}. Call +353 (0)21 555 0123 for questions.`; + + console.log('Email Confirmation:', { + to: email, + subject: 'Chestnut Reservation Confirmation', + html: emailContent, + }); + + console.log('SMS Confirmation:', { + to: phone, + message: smsContent, + }); + + await sendEmail(email, 'Chestnut Reservation Confirmation', emailContent); + await sendSMS(phone, smsContent); + + return NextResponse.json( + { + success: true, + message: 'Reservation confirmed. Confirmation messages sent to email and phone.', + reservation: { name, email, phone, guests, date }, + }, + { status: 200 } + ); + } catch (error) { + console.error('Reservation error:', error); + return NextResponse.json( + { error: 'Failed to process reservation' }, + { status: 500 } + ); + } +} + +async function sendEmail( + to: string, + subject: string, + html: string +): Promise { + try { + const response = await fetch('https://api.resend.com/emails', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${process.env.RESEND_API_KEY}`, + }, + body: JSON.stringify({ + from: process.env.RESEND_FROM_EMAIL || 'noreply@chestnut.ie', + to, + subject, + html, + }), + }); + + if (!response.ok) { + const error = await response.json(); + console.error('Email service error:', error); + } + } catch (error) { + console.error('Email sending failed:', error); + } +} + +async function sendSMS(phone: string, message: string): Promise { + try { + const response = await fetch('https://api.twilio.com/2010-04-01/Accounts/' + process.env.TWILIO_ACCOUNT_SID + '/Messages.json', { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + 'Authorization': 'Basic ' + Buffer.from(`${process.env.TWILIO_ACCOUNT_SID}:${process.env.TWILIO_AUTH_TOKEN}`).toString('base64'), + }, + body: new URLSearchParams({ + From: process.env.TWILIO_PHONE_NUMBER || '', + To: phone, + Body: message, + }).toString(), + }); + + if (!response.ok) { + const error = await response.json(); + console.error('SMS service error:', error); + } + } catch (error) { + console.error('SMS sending failed:', error); + } +} diff --git a/src/app/page.tsx b/src/app/page.tsx index eda492f..1a53c41 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -10,9 +10,48 @@ import MetricCardTwo from "@/components/sections/metrics/MetricCardTwo"; import TestimonialCardOne from "@/components/sections/testimonial/TestimonialCardOne"; import ContactFaq from "@/components/sections/contact/ContactFaq"; import FooterLogoReveal from "@/components/sections/footer/FooterLogoReveal"; -import { Award, Calendar, ChefHat, Heart, Leaf, Sparkles } from "lucide-react"; +import { Award, Calendar, ChefHat, Heart, Leaf, Sparkles, MessageCircle, Phone, Mail } from "lucide-react"; +import { useState } from "react"; +import Input from "@/components/form/Input"; export default function LandingPage() { + const [reservationForm, setReservationForm] = useState({ + name: "", email: "", phone: "", guests: "", date: ""}); + + const handleReservationSubmit = async () => { + if ( + !reservationForm.name || + !reservationForm.email || + !reservationForm.phone || + !reservationForm.guests || + !reservationForm.date + ) { + alert("Please fill in all fields"); + return; + } + + try { + const response = await fetch("/api/reservation", { + method: "POST", headers: { "Content-Type": "application/json" }, + body: JSON.stringify(reservationForm), + }); + + if (response.ok) { + const data = await response.json(); + console.log("Reservation submitted:", data); + alert( + `Confirmation sent to ${reservationForm.email} and ${reservationForm.phone}` + ); + setReservationForm({ name: "", email: "", phone: "", guests: "", date: "" }); + } else { + alert("Failed to submit reservation"); + } + } catch (error) { + console.error("Error submitting reservation:", error); + alert("Error submitting reservation"); + } + }; + return (
+
+
+

Make Your Reservation

+

Reserve your intimate dining experience at Chestnut. Our 18-guest intimate setting ensures personalized service and culinary excellence.

+ +
+ + setReservationForm({ ...reservationForm, name: value }) + } + placeholder="Your Name" + required + /> + + setReservationForm({ ...reservationForm, email: value }) + } + type="email" + placeholder="Your Email" + required + /> + + setReservationForm({ ...reservationForm, phone: value }) + } + type="tel" + placeholder="Your Phone Number" + required + /> + + setReservationForm({ ...reservationForm, guests: value }) + } + placeholder="Number of Guests" + required + /> + + setReservationForm({ ...reservationForm, date: value }) + } + type="date" + placeholder="Preferred Date" + required + /> + +
+
+
+