From e725e798e995023cfd7ff7d1badcb192e20772ff Mon Sep 17 00:00:00 2001 From: Alaguraj0361 Date: Fri, 3 Apr 2026 19:11:28 +0530 Subject: [PATCH] add server actions for reservation and catering inquiry form submissions --- src/app/actions.ts | 110 ++++++++++++++++++++++++--------------------- 1 file changed, 60 insertions(+), 50 deletions(-) diff --git a/src/app/actions.ts b/src/app/actions.ts index ac397b9..e6319ce 100644 --- a/src/app/actions.ts +++ b/src/app/actions.ts @@ -1,30 +1,42 @@ -'use server' - -import nodemailer from 'nodemailer'; - -// Configure SMTP transport using environment variables -const transporter = nodemailer.createTransport({ - host: process.env.EMAIL_HOST || 'smtp.gmail.com', // Replace with actual SMTP host if different - port: Number(process.env.EMAIL_PORT) || 587, - secure: (process.env.EMAIL_SECURE === 'true'), - auth: { - user: process.env.EMAIL_USER, - pass: process.env.EMAIL_PASS, - }, -}); +import axios from "axios"; export async function submitReservation(formData: FormData) { const name = formData.get('name'); const phone = formData.get('phone'); + const email = formData.get('email'); // Added if available const date = formData.get('date'); const message = formData.get('message'); + const guests = formData.get('guests') || "2 Guests"; - // For reservations, we'll log it for now as per current logic - console.log('Reservation received:', { name, phone, date, message }); + const emailData = { + name: name, + phone: phone, + email: email || "No Email Provided", + subject: `Table Reservation - ${guests} on ${date}`, + message: ` + Reservation Details:
+ Name: ${name}
+ Phone: ${phone}
+ Guests: ${guests}
+ Date: ${date}

+ Special Requests:
+ ${message || "None"} + `, + to: "hello@antalyarestaurant.ca", + senderName: "Antalya Restaurant - Table Reservation", + }; - // Simulate delay - await new Promise(resolve => setTimeout(resolve, 1000)); - return { success: true, message: 'Reservation submitted successfully!' }; + try { + await axios.post( + "https://mailserver.metatronnest.com/send", + emailData, + { headers: { "Content-Type": "application/json" } } + ); + return { success: true, message: 'Reservation submitted successfully!' }; + } catch (error) { + console.error('Failed to submit reservation:', error); + return { success: false, message: 'Failed to submit reservation. Please try again later.' }; + } } export async function submitCateringInquiry(formData: FormData) { @@ -38,41 +50,39 @@ export async function submitCateringInquiry(formData: FormData) { message: formData.get('message'), }; - try { - // Send email to hello@antalyarestaurant.ca - await transporter.sendMail({ - from: process.env.EMAIL_USER || '"Antalya Website" ', - to: 'hello@antalyarestaurant.ca', - subject: `Catering Inquiry: ${rawFormData.eventType} - ${rawFormData.name}`, - text: ` - Name: ${rawFormData.name} - Email: ${rawFormData.email} - Phone: ${rawFormData.phone} - Event Type: ${rawFormData.eventType} - Event Date: ${rawFormData.date} - Number of Guests: ${rawFormData.guests} - Message: ${rawFormData.message} - `, - html: ` -
-

New Catering Inquiry

-

Name: ${rawFormData.name}

-

Email: ${rawFormData.email}

-

Phone: ${rawFormData.phone}

-

Event Type: ${rawFormData.eventType}

-

Event Date: ${rawFormData.date}

-

Number of Guests: ${rawFormData.guests}

-
-

Message:

-

${rawFormData.message || 'No special requests provided.'}

-
+ const emailData = { + name: rawFormData.name, + email: rawFormData.email, + phone: rawFormData.phone, + subject: `Catering Inquiry: ${rawFormData.eventType} - ${rawFormData.name}`, + message: ` +
+

New Catering Inquiry

+

Name: ${rawFormData.name}

+

Email: ${rawFormData.email}

+

Phone: ${rawFormData.phone}

+

Event Type: ${rawFormData.eventType}

+

Event Date: ${rawFormData.date}

+

Number of Guests: ${rawFormData.guests}

+
+

Message:

+

${rawFormData.message || 'No special requests provided.'}

- `, - }); +
+ `, + to: 'hello@antalyarestaurant.ca', + senderName: "Antalya Restaurant - Catering Inquiry", + }; + try { + await axios.post( + "https://mailserver.metatronnest.com/send", + emailData, + { headers: { "Content-Type": "application/json" } } + ); return { success: true, message: 'Your catering inquiry has been submitted successfully to hello@antalyarestaurant.ca!' }; } catch (error) { - console.error('Failed to send catering inquiry email:', error); + console.error('Failed to send catering inquiry:', error); return { success: false, message: 'There was an error sending your inquiry. Please try again or email us directly.' }; } }