'use client'; import { useEffect, useState, useCallback } from 'react'; import { api } from '@/lib/api'; import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Badge } from '@/components/ui/badge'; import { toast } from 'sonner'; import { Save, ExternalLink, Copy, FileText, Shield, Map, Eye, EyeOff, CheckCircle2, XCircle, Clock, Smartphone, Phone, Mail, } from 'lucide-react'; const API_BASE = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3000/api/v1'; interface GlobalSettings { app_version_android?: string; app_version_ios?: string; support_title?: string; support_description?: string; support_days?: string; support_hours?: string; support_email?: string; support_phone?: string; maintenance_mode?: boolean; [key: string]: any; } const POLICY_ITEMS = [ { key: 'privacy', label: 'Política de Privacidad', icon: Shield, description: 'Cómo se recopilan, usan y protegen los datos personales.' }, { key: 'terms', label: 'Términos y Condiciones', icon: FileText, description: 'Condiciones de uso de la plataforma ProsApp.' }, ]; export default function SettingsPage() { const [loading, setLoading] = useState(true); // Global const [global, setGlobal] = useState({}); const [savingGlobal, setSavingGlobal] = useState(false); // Maps const [mapsConfigured, setMapsConfigured] = useState(false); const [mapsKey, setMapsKey] = useState(''); const [showMapsKey, setShowMapsKey] = useState(false); const [savingMaps, setSavingMaps] = useState(false); // Policies const [policies, setPolicies] = useState>({ privacy: '', terms: '' }); const [savingPolicy, setSavingPolicy] = useState(null); const load = useCallback(() => { setLoading(true); Promise.all([ api.get('/settings'), api.get<{ configured: boolean }>('/settings/maps-key'), api.get<{ privacy: string | null; terms: string | null }>('/settings/policies'), ]) .then(([globalData, mapsData, policiesData]) => { setGlobal(globalData || {}); setMapsConfigured(mapsData.configured); setPolicies({ privacy: policiesData.privacy || '', terms: policiesData.terms || '' }); }) .catch(() => toast.error('Error al cargar configuración')) .finally(() => setLoading(false)); }, []); useEffect(() => { load(); }, [load]); const saveGlobal = async () => { setSavingGlobal(true); try { await api.patch('/settings', global); toast.success('Configuración guardada'); } catch (e: any) { toast.error(e?.message || 'Error al guardar'); } finally { setSavingGlobal(false); } }; const saveMapsKey = async () => { if (!mapsKey.trim()) return toast.error('Ingresa una API Key'); setSavingMaps(true); try { await api.patch('/settings/maps', { api_key: mapsKey.trim() }); toast.success('Google Maps API Key guardada'); setMapsKey(''); setMapsConfigured(true); } catch (e: any) { toast.error(e?.message || 'Error al guardar'); } finally { setSavingMaps(false); } }; const savePolicy = async (key: string) => { setSavingPolicy(key); try { await api.patch(`/settings/policies/${key}`, { content: policies[key] }); toast.success('Política guardada'); } catch (e: any) { toast.error(e?.message || 'Error al guardar'); } finally { setSavingPolicy(null); } }; const copyLink = (key: string) => { navigator.clipboard.writeText(`${API_BASE}/settings/policy/${key}`); toast.success('Enlace copiado'); }; const setG = (field: keyof GlobalSettings, value: any) => setGlobal((g) => ({ ...g, [field]: value })); if (loading) return
Cargando...
; return (

Configuración

Ajustes globales, integraciones y documentos legales de ProsApp.

{/* ── Ajustes globales ── */}

Ajustes generales

Versión de la app
setG('app_version_android', e.target.value)} />
setG('app_version_ios', e.target.value)} />
Soporte
setG('support_title', e.target.value)} />
setG('support_description', e.target.value)} />
setG('support_days', e.target.value)} />
setG('support_hours', e.target.value)} />
setG('support_email', e.target.value)} />
setG('support_phone', e.target.value)} />
Modo mantenimiento Cuando está activo, la app muestra un mensaje de mantenimiento a los usuarios. {global.maintenance_mode ? 'Activo' : 'Inactivo'}
{/* ── Google Maps ── */}

Integraciones

Google Maps API Key Requerida para mostrar mapas y detectar ubicación. Habilita Maps JavaScript API y Geocoding API en Google Cloud Console.
{mapsConfigured ? <>Configurada : <>No configurada}
setMapsKey(e.target.value)} className="pr-10 font-mono" />

Restricción HTTP recomendada: https://app.prosapp.co/*

{/* ── Documentos legales ── */}

Documentos legales

{POLICY_ITEMS.map(({ key, label, icon: Icon, description }) => { const publicUrl = `${API_BASE}/settings/policy/${key}`; return ( {label} {description}