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 axios from "axios";
|
||||||
|
|
||||||
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,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export async function submitReservation(formData: FormData) {
|
export async function submitReservation(formData: FormData) {
|
||||||
const name = formData.get('name');
|
const name = formData.get('name');
|
||||||
const phone = formData.get('phone');
|
const phone = formData.get('phone');
|
||||||
|
const email = formData.get('email'); // Added if available
|
||||||
const date = formData.get('date');
|
const date = formData.get('date');
|
||||||
const message = formData.get('message');
|
const message = formData.get('message');
|
||||||
|
const guests = formData.get('guests') || "2 Guests";
|
||||||
|
|
||||||
// For reservations, we'll log it for now as per current logic
|
const emailData = {
|
||||||
console.log('Reservation received:', { name, phone, date, message });
|
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
|
try {
|
||||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
await axios.post(
|
||||||
return { success: true, message: 'Reservation submitted successfully!' };
|
"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) {
|
export async function submitCateringInquiry(formData: FormData) {
|
||||||
@ -38,41 +50,39 @@ export async function submitCateringInquiry(formData: FormData) {
|
|||||||
message: formData.get('message'),
|
message: formData.get('message'),
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
const emailData = {
|
||||||
// Send email to hello@antalyarestaurant.ca
|
name: rawFormData.name,
|
||||||
await transporter.sendMail({
|
email: rawFormData.email,
|
||||||
from: process.env.EMAIL_USER || '"Antalya Website" <noreply@antalyarestaurant.ca>',
|
phone: rawFormData.phone,
|
||||||
to: 'hello@antalyarestaurant.ca',
|
subject: `Catering Inquiry: ${rawFormData.eventType} - ${rawFormData.name}`,
|
||||||
subject: `Catering Inquiry: ${rawFormData.eventType} - ${rawFormData.name}`,
|
message: `
|
||||||
text: `
|
<div style="font-family: Arial, sans-serif; line-height: 1.6; color: #441109;">
|
||||||
Name: ${rawFormData.name}
|
<h2 style="color: #c49c5c; border-bottom: 2px solid #c49c5c; padding-bottom: 10px;">New Catering Inquiry</h2>
|
||||||
Email: ${rawFormData.email}
|
<p><strong>Name:</strong> ${rawFormData.name}</p>
|
||||||
Phone: ${rawFormData.phone}
|
<p><strong>Email:</strong> ${rawFormData.email}</p>
|
||||||
Event Type: ${rawFormData.eventType}
|
<p><strong>Phone:</strong> ${rawFormData.phone}</p>
|
||||||
Event Date: ${rawFormData.date}
|
<p><strong>Event Type:</strong> ${rawFormData.eventType}</p>
|
||||||
Number of Guests: ${rawFormData.guests}
|
<p><strong>Event Date:</strong> ${rawFormData.date}</p>
|
||||||
Message: ${rawFormData.message}
|
<p><strong>Number of Guests:</strong> ${rawFormData.guests}</p>
|
||||||
`,
|
<div style="margin-top: 20px; padding: 15px; background: #fdfaf5; border-radius: 8px;">
|
||||||
html: `
|
<p><strong>Message:</strong></p>
|
||||||
<div style="font-family: Arial, sans-serif; line-height: 1.6; color: #441109;">
|
<p>${rawFormData.message || 'No special requests provided.'}</p>
|
||||||
<h2 style="color: #c49c5c; border-bottom: 2px solid #c49c5c; padding-bottom: 10px;">New Catering Inquiry</h2>
|
|
||||||
<p><strong>Name:</strong> ${rawFormData.name}</p>
|
|
||||||
<p><strong>Email:</strong> ${rawFormData.email}</p>
|
|
||||||
<p><strong>Phone:</strong> ${rawFormData.phone}</p>
|
|
||||||
<p><strong>Event Type:</strong> ${rawFormData.eventType}</p>
|
|
||||||
<p><strong>Event Date:</strong> ${rawFormData.date}</p>
|
|
||||||
<p><strong>Number of Guests:</strong> ${rawFormData.guests}</p>
|
|
||||||
<div style="margin-top: 20px; padding: 15px; background: #fdfaf5; border-radius: 8px;">
|
|
||||||
<p><strong>Message:</strong></p>
|
|
||||||
<p>${rawFormData.message || 'No special requests provided.'}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</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!' };
|
return { success: true, message: 'Your catering inquiry has been submitted successfully to hello@antalyarestaurant.ca!' };
|
||||||
} catch (error) {
|
} 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.' };
|
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