fix: contact page now fetches brand info from config

- Created contact API endpoint to store messages
- Added contact_messages table
- Contact page now displays phone, email, WhatsApp, and address from site config
This commit is contained in:
2026-06-30 00:20:00 -05:00
parent ef2bfa5f05
commit 3bdaee333b
2 changed files with 36 additions and 7 deletions
+23
View File
@@ -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 });
}
}
+13 -7
View File
@@ -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() {
<div style={{ background: 'rgba(245,240,232,0.06)', borderRadius: '12px', padding: '1.5rem', border: '1px solid rgba(245,240,232,0.12)' }}>
<div style={{ fontSize: '24px', marginBottom: '0.5rem' }}>📞</div>
<div style={{ fontSize: '12px', textTransform: 'uppercase', letterSpacing: '0.1em', color: gold, marginBottom: '0.25rem' }}>{t.phone}</div>
<div style={{ fontSize: '16px' }}>+593 99 XXX XXXX</div>
<div style={{ fontSize: '16px' }}>{config.phone || '+593 99 XXX XXXX'}</div>
</div>
{/* Email */}
<div style={{ background: 'rgba(245,240,232,0.06)', borderRadius: '12px', padding: '1.5rem', border: '1px solid rgba(245,240,232,0.12)' }}>
<div style={{ fontSize: '24px', marginBottom: '0.5rem' }}></div>
<div style={{ fontSize: '12px', textTransform: 'uppercase', letterSpacing: '0.1em', color: gold, marginBottom: '0.25rem' }}>{t.email}</div>
<div style={{ fontSize: '16px' }}>info@lahuasca.com</div>
<div style={{ fontSize: '16px' }}>{config.email || 'info@lahuasca.com'}</div>
</div>
{/* WhatsApp */}
<div style={{ background: 'rgba(245,240,232,0.06)', borderRadius: '12px', padding: '1.5rem', border: '1px solid rgba(245,240,232,0.12)' }}>
<div style={{ fontSize: '24px', marginBottom: '0.5rem' }}>💬</div>
<div style={{ fontSize: '12px', textTransform: 'uppercase', letterSpacing: '0.1em', color: gold, marginBottom: '0.25rem' }}>{t.whatsapp}</div>
<div style={{ fontSize: '16px' }}>+593 99 XXX XXXX</div>
<div style={{ fontSize: '16px' }}>{config.whatsapp_url ? <a href={config.whatsapp_url} target="_blank" rel="noopener noreferrer" style={{ color: cream, textDecoration: 'underline' }}>WhatsApp</a> : (config.phone || '+593 99 XXX XXXX')}</div>
</div>
{/* Location */}
<div style={{ background: 'rgba(245,240,232,0.06)', borderRadius: '12px', padding: '1.5rem', border: '1px solid rgba(245,240,232,0.12)' }}>
<div style={{ fontSize: '24px', marginBottom: '0.5rem' }}>📍</div>
<div style={{ fontSize: '12px', textTransform: 'uppercase', letterSpacing: '0.1em', color: gold, marginBottom: '0.25rem' }}>{t.location}</div>
<div style={{ fontSize: '16px' }}>{t.address}</div>
<div style={{ fontSize: '16px' }}>{config.address || 'Otavalo, Imbabura, Ecuador'}</div>
</div>
</div>