import { useEffect, useState } from 'react'; import { motion } from 'framer-motion'; import { CheckCircle, Edit2, RefreshCw, Star, XCircle } from 'lucide-react'; import { fetchPlans } from '../api/sysadmin'; import type { Plan } from '../api/sysadmin'; import { EditPlanModal } from '../components/ui/EditPlanModal'; const formatMoney = (value: number) => new Intl.NumberFormat('es-AR', { style: 'currency', currency: 'ARS' }).format(value || 0); const getFeatureTags = (plan: Plan) => [ { label: 'Mail', enabled: plan.mailNotifications }, { label: 'SMS', enabled: plan.smsNotifications }, { label: 'WAP', enabled: plan.wapNotifications }, { label: 'Pagos', enabled: plan.payments }, { label: 'Bot', enabled: plan.bot }, { label: 'Fecha límite', enabled: plan.dateLimit }, ]; const getLimitTags = (plan: Plan) => [ { label: 'Org', value: plan.limitOrganizations }, { label: 'Emp', value: plan.limitEmployees }, { label: 'Serv', value: plan.limitServices }, { label: 'Turnos', value: plan.limitAppointments }, { label: 'Clientes', value: plan.limitClients }, { label: 'Rep', value: plan.limitRepeats }, ]; const formatLimit = (value: number) => value === -1 ? '∞' : value; export const PlansPage = () => { const [plans, setPlans] = useState([]); const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const [editingPlan, setEditingPlan] = useState(null); const [planIdFilter, setPlanIdFilter] = useState(''); const filteredPlans = plans.filter((plan) => { const normalizedFilter = planIdFilter.trim().toLowerCase(); if (!normalizedFilter) return true; return [plan.id, plan._id].some((planId) => planId?.toLowerCase().includes(normalizedFilter)); }); const loadPlans = async () => { setLoading(true); setError(''); try { const data = await fetchPlans(); setPlans(data); } catch (err: any) { setError(err.response?.data?.message || err.message || 'Error cargando planes'); } setLoading(false); }; useEffect(() => { loadPlans(); }, []); return (

Gestión de Planes

Visualizá y editá precios, límites y funciones contratables.

setPlanIdFilter(event.target.value)} />
{error && (
{error}
)}
{loading ? ( ) : filteredPlans.length === 0 ? ( ) : ( filteredPlans.map(plan => ( )) )}
Plan Precio Límites Funciones Estado Acciones
Cargando planes...
No se encontraron planes
{plan.name} {plan.featured && }
{plan.code}
{plan.description}
{formatMoney(plan.price)} / mes
{formatMoney(plan.annualPrice)} / año
{getLimitTags(plan).map((limit) => ( {limit.label} {formatLimit(limit.value)} ))}
{getFeatureTags(plan).map((feature) => ( {feature.label} ))}
{plan.active ? : } {plan.active ? 'Activo' : 'Inactivo'}