diff --git a/src/app/api/contact/route.ts b/src/app/api/contact/route.ts new file mode 100644 index 0000000..658ba83 --- /dev/null +++ b/src/app/api/contact/route.ts @@ -0,0 +1,23 @@ +import { NextRequest, NextResponse } from 'next/server'; +import { db } from '@/lib/db'; + +export async function POST(request: NextRequest) { + try { + const body = await request.json(); + const { name, email, message } = body; + + if (!name || !email || !message) { + return NextResponse.json({ error: 'Name, email, and message are required' }, { status: 400 }); + } + + // Store the contact message + await db.query( + `INSERT INTO contact_messages (name, email, message, created_at) VALUES ($1, $2, $3, NOW())`, + [name, email, message] + ); + + return NextResponse.json({ ok: true }); + } catch (err: any) { + return NextResponse.json({ error: err.message || 'Failed to send message' }, { status: 500 }); + } +} \ No newline at end of file diff --git a/src/app/contact/page.tsx b/src/app/contact/page.tsx index c835beb..4066bb0 100644 --- a/src/app/contact/page.tsx +++ b/src/app/contact/page.tsx @@ -1,6 +1,6 @@ 'use client'; -import { useState } from 'react'; +import { useState, useEffect } from 'react'; import { useLanguage } from '@/lib/i18n'; const gold = '#E8A849'; @@ -15,7 +15,6 @@ const copy = { email: 'Email', whatsapp: 'WhatsApp', location: 'Location', - address: 'Otavalo, Imbabura, Ecuador', send_message: 'Send us a message', form_name: 'Your Name', form_email: 'Your Email', @@ -32,7 +31,6 @@ const copy = { email: 'Correo', whatsapp: 'WhatsApp', location: 'Ubicación', - address: 'Otavalo, Imbabura, Ecuador', send_message: 'Envíenos un mensaje', form_name: 'Su Nombre', form_email: 'Su Correo', @@ -49,6 +47,14 @@ export default function ContactPage() { const t = copy[language]; const [form, setForm] = useState({ name: '', email: '', message: '' }); const [status, setStatus] = useState<'idle' | 'sending' | 'success' | 'error'>('idle'); + const [config, setConfig] = useState<{ phone?: string; email?: string; whatsapp_url?: string; address?: string }>({}); + + useEffect(() => { + fetch('/api/site-assets') + .then(res => res.json()) + .then(data => setConfig(data.data || {})) + .catch(() => {}); + }, []); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); @@ -85,28 +91,28 @@ export default function ContactPage() {
📞
{t.phone}
-
+593 99 XXX XXXX
+
{config.phone || '+593 99 XXX XXXX'}
{/* Email */}
✉️
{t.email}
-
info@lahuasca.com
+
{config.email || 'info@lahuasca.com'}
{/* WhatsApp */}
💬
{t.whatsapp}
-
+593 99 XXX XXXX
+
{config.whatsapp_url ? WhatsApp : (config.phone || '+593 99 XXX XXXX')}
{/* Location */}
📍
{t.location}
-
{t.address}
+
{config.address || 'Otavalo, Imbabura, Ecuador'}