'use client'; import { useEffect, useState } from 'react'; import { PencilIcon, TrashIcon, PlusIcon } from '@heroicons/react/24/outline'; import CreatePlanModal from '@/components/plans/CreatePlanModal'; export default function PlansPage() { const [plans, setPlans] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(''); const [isModalOpen, setIsModalOpen] = useState(false); useEffect(() => { fetchPlans(); }, []); const fetchPlans = async () => { try { setLoading(true); const token = localStorage.getItem('token'); const response = await fetch('/api/admin/plans', { headers: { 'Authorization': `Bearer ${token}`, }, }); if (!response.ok) { throw new Error('Erro ao carregar planos'); } const data = await response.json(); setPlans(data.plans || []); setError(''); } catch (err: any) { setError(err.message); } finally { setLoading(false); } }; const handleDeletePlan = async (id: string) => { if (!confirm('Tem certeza que deseja deletar este plano? Esta ação não pode ser desfeita.')) { return; } try { const token = localStorage.getItem('token'); const response = await fetch(`/api/admin/plans/${id}`, { method: 'DELETE', headers: { 'Authorization': `Bearer ${token}`, }, }); if (!response.ok) { throw new Error('Erro ao deletar plano'); } fetchPlans(); } catch (err: any) { setError(err.message); } }; if (loading) { return (

Carregando planos...

); } return (
{/* Header */}

Planos

Gerencie os planos de assinatura disponíveis para as agências

{/* Error Message */} {error && (

{error}

)} {/* Plans Grid */} {plans.length > 0 ? (
{plans.map((plan) => (
{/* Header */}

{plan.name}

{!plan.is_active && ( Inativo )}
{plan.is_active && ( Ativo )}
{plan.description && (

{plan.description}

)}
{/* Content */}
{/* Pricing */}
{plan.monthly_price && (
Mensal R$ {parseFloat(plan.monthly_price).toFixed(2)}
)} {plan.annual_price && (
Anual R$ {parseFloat(plan.annual_price).toFixed(2)}
)}
{/* Stats */}

Usuários

{plan.min_users} - {plan.max_users === -1 ? '∞' : plan.max_users}

Armazenamento

{plan.storage_gb} GB

{/* Features */} {plan.features && plan.features.length > 0 && (

Recursos

    {plan.features.slice(0, 4).map((feature: string, idx: number) => (
  • {feature}
  • ))} {plan.features.length > 4 && (
  • +{plan.features.length - 4} mais
  • )}
)} {/* Differentiators */} {plan.differentiators && plan.differentiators.length > 0 && (

Diferenciais

    {plan.differentiators.slice(0, 2).map((diff: string, idx: number) => (
  • {diff}
  • ))} {plan.differentiators.length > 2 && (
  • +{plan.differentiators.length - 2} mais
  • )}
)}
{/* Footer */}
Editar
))}
) : (

Nenhum plano criado

Clique no botão acima para criar o primeiro plano

)} {/* Create Plan Modal */} setIsModalOpen(false)} onSuccess={() => { fetchPlans(); }} />
); }