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:
@@ -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 });
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useState } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
import { useLanguage } from '@/lib/i18n';
|
import { useLanguage } from '@/lib/i18n';
|
||||||
|
|
||||||
const gold = '#E8A849';
|
const gold = '#E8A849';
|
||||||
@@ -15,7 +15,6 @@ const copy = {
|
|||||||
email: 'Email',
|
email: 'Email',
|
||||||
whatsapp: 'WhatsApp',
|
whatsapp: 'WhatsApp',
|
||||||
location: 'Location',
|
location: 'Location',
|
||||||
address: 'Otavalo, Imbabura, Ecuador',
|
|
||||||
send_message: 'Send us a message',
|
send_message: 'Send us a message',
|
||||||
form_name: 'Your Name',
|
form_name: 'Your Name',
|
||||||
form_email: 'Your Email',
|
form_email: 'Your Email',
|
||||||
@@ -32,7 +31,6 @@ const copy = {
|
|||||||
email: 'Correo',
|
email: 'Correo',
|
||||||
whatsapp: 'WhatsApp',
|
whatsapp: 'WhatsApp',
|
||||||
location: 'Ubicación',
|
location: 'Ubicación',
|
||||||
address: 'Otavalo, Imbabura, Ecuador',
|
|
||||||
send_message: 'Envíenos un mensaje',
|
send_message: 'Envíenos un mensaje',
|
||||||
form_name: 'Su Nombre',
|
form_name: 'Su Nombre',
|
||||||
form_email: 'Su Correo',
|
form_email: 'Su Correo',
|
||||||
@@ -49,6 +47,14 @@ export default function ContactPage() {
|
|||||||
const t = copy[language];
|
const t = copy[language];
|
||||||
const [form, setForm] = useState({ name: '', email: '', message: '' });
|
const [form, setForm] = useState({ name: '', email: '', message: '' });
|
||||||
const [status, setStatus] = useState<'idle' | 'sending' | 'success' | 'error'>('idle');
|
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) => {
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
e.preventDefault();
|
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={{ 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: '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: '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>
|
</div>
|
||||||
|
|
||||||
{/* Email */}
|
{/* 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={{ 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: '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: '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>
|
</div>
|
||||||
|
|
||||||
{/* WhatsApp */}
|
{/* 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={{ 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: '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: '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>
|
</div>
|
||||||
|
|
||||||
{/* Location */}
|
{/* 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={{ 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: '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: '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>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user