add server actions for reservation and catering inquiry form submissions
This commit is contained in:
parent
d1060fe508
commit
e725e798e9
@ -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: `
|
||||
<strong>Reservation Details:</strong><br/>
|
||||
Name: ${name}<br/>
|
||||
Phone: ${phone}<br/>
|
||||
Guests: ${guests}<br/>
|
||||
Date: ${date}<br/><br/>
|
||||
<strong>Special Requests:</strong><br/>
|
||||
${message || "None"}
|
||||
`,
|
||||
to: "hello@antalyarestaurant.ca",
|
||||
senderName: "Antalya Restaurant - Table Reservation",
|
||||
};
|
||||
|
||||
// Simulate delay
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
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,22 +50,12 @@ 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" <noreply@antalyarestaurant.ca>',
|
||||
to: 'hello@antalyarestaurant.ca',
|
||||
const emailData = {
|
||||
name: rawFormData.name,
|
||||
email: rawFormData.email,
|
||||
phone: rawFormData.phone,
|
||||
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: `
|
||||
message: `
|
||||
<div style="font-family: Arial, sans-serif; line-height: 1.6; color: #441109;">
|
||||
<h2 style="color: #c49c5c; border-bottom: 2px solid #c49c5c; padding-bottom: 10px;">New Catering Inquiry</h2>
|
||||
<p><strong>Name:</strong> ${rawFormData.name}</p>
|
||||
@ -68,11 +70,19 @@ export async function submitCateringInquiry(formData: FormData) {
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
});
|
||||
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.' };
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user