chore(release): snapshot 1.4.2
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
"use client";
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import DashboardPreview from "./DashboardPreview";
|
||||
@@ -14,211 +14,199 @@ interface DynamicBrandingProps {
|
||||
|
||||
export default function DynamicBranding({
|
||||
currentStep,
|
||||
companyName = '',
|
||||
subdomain = '',
|
||||
primaryColor = '#0ea5e9',
|
||||
secondaryColor = '#0284c7',
|
||||
logoUrl = ''
|
||||
companyName = "",
|
||||
subdomain = "",
|
||||
primaryColor = "#0ea5e9",
|
||||
secondaryColor = "#0284c7",
|
||||
logoUrl = ""
|
||||
}: DynamicBrandingProps) {
|
||||
const [activeTestimonial, setActiveTestimonial] = useState(0);
|
||||
|
||||
const testimonials = [
|
||||
{
|
||||
text: "Com o Aggios, nossa produtividade aumentou 40%. Gestão de projetos nunca foi tão simples!",
|
||||
author: "Maria Silva",
|
||||
company: "DigitalWorks",
|
||||
avatar: "MS"
|
||||
text: "A implementação do Aggios transformou completamente a gestão da nossa agência. Conseguimos reduzir em 65% o tempo gasto com tarefas administrativas e aumentar nossa capacidade de atendimento.",
|
||||
author: "Carlos Eduardo Martins",
|
||||
position: "CEO",
|
||||
company: "Martins & Associados",
|
||||
rating: 5
|
||||
},
|
||||
{
|
||||
text: "Reduzi 60% do tempo gasto com controle financeiro. Tudo centralizado em um só lugar.",
|
||||
author: "João Santos",
|
||||
company: "TechHub",
|
||||
avatar: "JS"
|
||||
text: "Como diretora de operações, preciso de dados precisos em tempo real. O Aggios entrega exatamente isso. A plataforma é intuitiva e os relatórios são excepcionais para tomada de decisão estratégica.",
|
||||
author: "Patricia Almeida Santos",
|
||||
position: "Diretora de Operações",
|
||||
company: "Digital Solutions Group",
|
||||
rating: 5
|
||||
},
|
||||
{
|
||||
text: "A melhor decisão para nossa agência. Dashboard intuitivo e relatórios incríveis!",
|
||||
author: "Ana Costa",
|
||||
company: "CreativeFlow",
|
||||
avatar: "AC"
|
||||
text: "Implementamos o Aggios há 6 meses e o ROI foi imediato. Melhor controle financeiro, visibilidade total dos projetos e uma equipe muito mais produtiva. Recomendo sem ressalvas.",
|
||||
author: "Roberto Henrique Costa",
|
||||
position: "Diretor Financeiro",
|
||||
company: "Costa & Partners",
|
||||
rating: 5
|
||||
},
|
||||
{
|
||||
text: "A integração com nossas ferramentas foi perfeita e o suporte técnico é simplesmente excepcional. O Aggios se tornou parte fundamental da nossa operação diária.",
|
||||
author: "Fernanda Silva Rodrigues",
|
||||
position: "Head de TI",
|
||||
company: "Tech Innovators",
|
||||
rating: 5
|
||||
}
|
||||
];
|
||||
|
||||
const stepContent = [
|
||||
{
|
||||
icon: "ri-user-heart-line",
|
||||
title: "Bem-vindo ao Aggios!",
|
||||
description: "Vamos criar sua conta em poucos passos",
|
||||
benefits: [
|
||||
"✓ Acesso completo ao painel",
|
||||
"✓ Gestão ilimitada de projetos",
|
||||
"✓ Suporte prioritário"
|
||||
]
|
||||
},
|
||||
{
|
||||
icon: "ri-building-line",
|
||||
title: "Configure sua Empresa",
|
||||
description: "Personalize de acordo com seu negócio",
|
||||
benefits: [
|
||||
"✓ Dashboard personalizado",
|
||||
"✓ Gestão de equipe e clientes",
|
||||
"✓ Controle financeiro integrado"
|
||||
]
|
||||
},
|
||||
{
|
||||
icon: "ri-map-pin-line",
|
||||
title: "Quase lá!",
|
||||
description: "Informações de localização e contato",
|
||||
benefits: [
|
||||
"✓ Multi-contatos configuráveis",
|
||||
"✓ Integração com WhatsApp",
|
||||
"✓ Notificações em tempo real"
|
||||
]
|
||||
},
|
||||
{
|
||||
icon: "ri-palette-line",
|
||||
title: "Personalize as Cores",
|
||||
description: "Deixe com a cara da sua empresa",
|
||||
benefits: [
|
||||
"✓ Preview em tempo real",
|
||||
"✓ Paleta de cores customizada",
|
||||
"✓ Identidade visual única"
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
const content = stepContent[currentStep - 1] || stepContent[0];
|
||||
|
||||
// Auto-rotate testimonials
|
||||
useEffect(() => {
|
||||
const interval = setInterval(() => {
|
||||
setActiveTestimonial((prev) => (prev + 1) % testimonials.length);
|
||||
}, 5000);
|
||||
}, 6000);
|
||||
return () => clearInterval(interval);
|
||||
}, [testimonials.length]);
|
||||
|
||||
// Se for etapa 4, mostrar preview do dashboard
|
||||
if (currentStep === 4) {
|
||||
return (
|
||||
<div className="relative z-10 flex flex-col justify-center items-center w-full p-12">
|
||||
{/* Logo */}
|
||||
<div className="mb-8">
|
||||
<div className="inline-block px-6 py-3 rounded-2xl bg-white/10 backdrop-blur-sm border border-white/20">
|
||||
<h1 className="text-5xl font-bold tracking-tight bg-linear-to-r from-white to-white/80 bg-clip-text text-transparent">
|
||||
<div className="relative z-10 flex flex-col h-full w-full overflow-hidden bg-gradient-to-br from-slate-900 via-slate-800 to-slate-900">
|
||||
{/* Decorative elements */}
|
||||
<div className="absolute inset-0 opacity-10">
|
||||
<div className="absolute top-0 left-0 w-96 h-96 bg-blue-500 rounded-full blur-3xl" />
|
||||
<div className="absolute bottom-0 right-0 w-96 h-96 bg-purple-500 rounded-full blur-3xl" />
|
||||
</div>
|
||||
|
||||
<div className="relative z-10 flex flex-col justify-center items-center h-full p-12 text-white">
|
||||
<div className="mb-6">
|
||||
<h1 className="text-4xl font-bold tracking-tight text-white text-center mb-2">
|
||||
aggios
|
||||
</h1>
|
||||
<p className="text-sm text-white/70 font-medium tracking-wide uppercase text-center">
|
||||
Gestão Inteligente para Agências
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="max-w-lg text-center mb-8">
|
||||
<h2 className="text-3xl font-bold mb-2 text-white">Preview do seu Painel</h2>
|
||||
<p className="text-white/70 text-base">Veja como ficará seu dashboard personalizado</p>
|
||||
</div>
|
||||
|
||||
<div className="w-full max-w-3xl mb-6">
|
||||
<DashboardPreview
|
||||
companyName={companyName}
|
||||
subdomain={subdomain}
|
||||
primaryColor={primaryColor}
|
||||
secondaryColor={secondaryColor}
|
||||
logoUrl={logoUrl}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="text-center">
|
||||
<p className="text-white/60 text-sm">
|
||||
As cores e configurações são atualizadas em tempo real
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Conteúdo */}
|
||||
<div className="max-w-lg text-center">
|
||||
<h2 className="text-3xl font-bold mb-2 text-white">Preview do seu Painel</h2>
|
||||
<p className="text-white/80 text-lg">Veja como ficará seu dashboard personalizado</p>
|
||||
</div>
|
||||
|
||||
{/* Preview */}
|
||||
<div className="w-full max-w-3xl">
|
||||
<DashboardPreview
|
||||
companyName={companyName}
|
||||
subdomain={subdomain}
|
||||
primaryColor={primaryColor}
|
||||
secondaryColor={secondaryColor}
|
||||
logoUrl={logoUrl}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Info */}
|
||||
<div className="mt-6 text-center">
|
||||
<p className="text-white/70 text-sm">
|
||||
As cores e configurações são atualizadas em tempo real
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Decorative circles */}
|
||||
<div className="absolute -bottom-32 -left-32 w-96 h-96 rounded-full bg-white/5" />
|
||||
<div className="absolute -top-16 -right-16 w-64 h-64 rounded-full bg-white/5" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="relative z-10 flex flex-col justify-between w-full p-12 text-white">
|
||||
{/* Logo e Conteúdo da Etapa */}
|
||||
<div className="flex flex-col justify-center flex-1">
|
||||
{/* Logo */}
|
||||
<div className="relative z-10 flex flex-col h-full w-full overflow-hidden bg-gradient-to-br from-slate-900 via-slate-800 to-slate-900">
|
||||
{/* Decorative elements */}
|
||||
<div className="absolute inset-0 opacity-10">
|
||||
<div className="absolute top-20 right-20 w-96 h-96 bg-blue-500 rounded-full blur-3xl" />
|
||||
<div className="absolute bottom-20 left-20 w-80 h-80 bg-indigo-500 rounded-full blur-3xl" />
|
||||
</div>
|
||||
|
||||
<div className="relative z-10 flex flex-col justify-between h-full p-12 text-white">
|
||||
<div className="mb-8">
|
||||
<div className="inline-block px-6 py-3 rounded-2xl bg-white/10 backdrop-blur-sm border border-white/20">
|
||||
<h1 className="text-5xl font-bold tracking-tight bg-linear-to-r from-white to-white/80 bg-clip-text text-transparent">
|
||||
<div className="inline-block">
|
||||
<h1 className="text-4xl font-bold tracking-tight text-white mb-2">
|
||||
aggios
|
||||
</h1>
|
||||
<p className="text-sm text-white/70 font-medium tracking-wide uppercase">
|
||||
Gestão Inteligente para Agências
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Ícone e Título da Etapa */}
|
||||
<div className="mb-6">
|
||||
<div className="w-16 h-16 rounded-2xl bg-white/20 flex items-center justify-center mb-4">
|
||||
<i className={`${content.icon} text-3xl`} />
|
||||
</div>
|
||||
<h2 className="text-3xl font-bold mb-2">{content.title}</h2>
|
||||
<p className="text-white/80 text-lg">{content.description}</p>
|
||||
</div>
|
||||
<div className="flex-1" />
|
||||
|
||||
{/* Benefícios */}
|
||||
<div className="space-y-3 mb-8">
|
||||
{content.benefits.map((benefit, index) => (
|
||||
<div
|
||||
key={index}
|
||||
className="flex items-center gap-3 text-white/90 animate-fade-in"
|
||||
style={{ animationDelay: `${index * 100}ms` }}
|
||||
>
|
||||
<span className="text-lg">{benefit}</span>
|
||||
<div className="space-y-6">
|
||||
<div className="mb-6">
|
||||
<h3 className="text-sm font-semibold text-white/60 uppercase tracking-wider mb-1">
|
||||
Depoimentos
|
||||
</h3>
|
||||
<p className="text-2xl font-bold text-white">
|
||||
O que nossos clientes dizem
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="relative">
|
||||
<div className="bg-white/5 backdrop-blur-md rounded-xl p-8 border border-white/10 shadow-2xl">
|
||||
<div className="flex gap-1 mb-4">
|
||||
{[...Array(testimonials[activeTestimonial].rating)].map((_, i) => (
|
||||
<i key={i} className="ri-star-fill text-yellow-400 text-lg" />
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="mb-4">
|
||||
<i className="ri-double-quotes-l text-4xl text-white/20" />
|
||||
</div>
|
||||
|
||||
<p className="text-white/95 text-lg leading-relaxed mb-6 min-h-[140px]">
|
||||
{testimonials[activeTestimonial].text}
|
||||
</p>
|
||||
|
||||
<div className="flex items-center gap-4 pt-6 border-t border-white/10">
|
||||
<div className="relative w-14 h-14 rounded-full overflow-hidden ring-2 ring-white/20 bg-gradient-to-br from-blue-500 to-purple-600 flex items-center justify-center">
|
||||
<span className="text-white font-bold text-xl">
|
||||
{testimonials[activeTestimonial].author.split(' ').map(n => n[0]).join('')}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex-1">
|
||||
<p className="font-semibold text-white text-lg">
|
||||
{testimonials[activeTestimonial].author}
|
||||
</p>
|
||||
<p className="text-sm text-white/70">
|
||||
{testimonials[activeTestimonial].position}
|
||||
</p>
|
||||
<p className="text-sm text-white/50 font-medium">
|
||||
{testimonials[activeTestimonial].company}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
|
||||
<div className="flex gap-2 justify-center mt-6">
|
||||
{testimonials.map((_, index) => (
|
||||
<button
|
||||
key={index}
|
||||
onClick={() => setActiveTestimonial(index)}
|
||||
className={`h-2 rounded-full transition-all duration-300 ${index === activeTestimonial
|
||||
? "w-12 bg-white shadow-lg shadow-white/20"
|
||||
: "w-2 bg-white/30 hover:bg-white/50"
|
||||
}`}
|
||||
aria-label={`Ir para depoimento ${index + 1}`}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-center gap-6 mt-8 pt-6 border-t border-white/10">
|
||||
<div className="text-center">
|
||||
<p className="text-2xl font-bold text-white">10.000+</p>
|
||||
<p className="text-xs text-white/60 uppercase tracking-wide">Projetos</p>
|
||||
</div>
|
||||
<div className="w-px h-8 bg-white/20" />
|
||||
<div className="text-center">
|
||||
<p className="text-2xl font-bold text-white">98%</p>
|
||||
<p className="text-xs text-white/60 uppercase tracking-wide">Satisfação</p>
|
||||
</div>
|
||||
<div className="w-px h-8 bg-white/20" />
|
||||
<div className="text-center">
|
||||
<p className="text-2xl font-bold text-white">5.000+</p>
|
||||
<p className="text-xs text-white/60 uppercase tracking-wide">Usuários</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Carrossel de Depoimentos */}
|
||||
<div className="relative">
|
||||
<div className="bg-white/10 backdrop-blur-sm rounded-2xl p-6 border border-white/20">
|
||||
<div className="mb-4">
|
||||
<i className="ri-double-quotes-l text-3xl text-white/40" />
|
||||
</div>
|
||||
<p className="text-white/95 mb-4 min-h-[60px]">
|
||||
{testimonials[activeTestimonial].text}
|
||||
</p>
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="w-10 h-10 rounded-full bg-white/20 flex items-center justify-center font-semibold">
|
||||
{testimonials[activeTestimonial].avatar}
|
||||
</div>
|
||||
<div>
|
||||
<p className="font-semibold text-white">
|
||||
{testimonials[activeTestimonial].author}
|
||||
</p>
|
||||
<p className="text-sm text-white/70">
|
||||
{testimonials[activeTestimonial].company}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Indicadores */}
|
||||
<div className="flex gap-2 justify-center mt-4">
|
||||
{testimonials.map((_, index) => (
|
||||
<button
|
||||
key={index}
|
||||
onClick={() => setActiveTestimonial(index)}
|
||||
className={`h-1.5 rounded-full transition-all ${index === activeTestimonial
|
||||
? "w-8 bg-white"
|
||||
: "w-1.5 bg-white/40 hover:bg-white/60"
|
||||
}`}
|
||||
aria-label={`Ir para depoimento ${index + 1}`}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Decorative circles */}
|
||||
<div className="absolute -bottom-32 -left-32 w-96 h-96 rounded-full bg-white/5" />
|
||||
<div className="absolute -top-16 -right-16 w-64 h-64 rounded-full bg-white/5" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
123
front-end-dash.aggios.app/components/layout/ConfirmDialog.tsx
Normal file
123
front-end-dash.aggios.app/components/layout/ConfirmDialog.tsx
Normal file
@@ -0,0 +1,123 @@
|
||||
import { Fragment } from 'react';
|
||||
import { Dialog, Transition } from '@headlessui/react';
|
||||
import { ExclamationTriangleIcon, XMarkIcon } from '@heroicons/react/24/outline';
|
||||
|
||||
interface ConfirmDialogProps {
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
onConfirm: () => void;
|
||||
title: string;
|
||||
message: string;
|
||||
confirmText?: string;
|
||||
cancelText?: string;
|
||||
variant?: 'danger' | 'warning' | 'info';
|
||||
}
|
||||
|
||||
export default function ConfirmDialog({
|
||||
isOpen,
|
||||
onClose,
|
||||
onConfirm,
|
||||
title,
|
||||
message,
|
||||
confirmText = 'Confirmar',
|
||||
cancelText = 'Cancelar',
|
||||
variant = 'danger'
|
||||
}: ConfirmDialogProps) {
|
||||
const handleConfirm = () => {
|
||||
onConfirm();
|
||||
onClose();
|
||||
};
|
||||
|
||||
const variantStyles = {
|
||||
danger: {
|
||||
icon: 'bg-red-100 dark:bg-red-900/20',
|
||||
iconColor: 'text-red-600 dark:text-red-400',
|
||||
button: 'bg-red-600 hover:bg-red-700 dark:bg-red-700 dark:hover:bg-red-800'
|
||||
},
|
||||
warning: {
|
||||
icon: 'bg-yellow-100 dark:bg-yellow-900/20',
|
||||
iconColor: 'text-yellow-600 dark:text-yellow-400',
|
||||
button: 'bg-yellow-600 hover:bg-yellow-700 dark:bg-yellow-700 dark:hover:bg-yellow-800'
|
||||
},
|
||||
info: {
|
||||
icon: 'bg-blue-100 dark:bg-blue-900/20',
|
||||
iconColor: 'text-blue-600 dark:text-blue-400',
|
||||
button: 'bg-blue-600 hover:bg-blue-700 dark:bg-blue-700 dark:hover:bg-blue-800'
|
||||
}
|
||||
};
|
||||
|
||||
const style = variantStyles[variant];
|
||||
|
||||
return (
|
||||
<Transition.Root show={isOpen} as={Fragment}>
|
||||
<Dialog as="div" className="relative z-50" onClose={onClose}>
|
||||
<Transition.Child
|
||||
as={Fragment}
|
||||
enter="ease-out duration-300"
|
||||
enterFrom="opacity-0"
|
||||
enterTo="opacity-100"
|
||||
leave="ease-in duration-200"
|
||||
leaveFrom="opacity-100"
|
||||
leaveTo="opacity-0"
|
||||
>
|
||||
<div className="fixed inset-0 bg-zinc-900/40 backdrop-blur-sm transition-opacity" />
|
||||
</Transition.Child>
|
||||
|
||||
<div className="fixed inset-0 z-10 overflow-y-auto">
|
||||
<div className="flex min-h-full items-end justify-center p-4 text-center sm:items-center sm:p-0">
|
||||
<Transition.Child
|
||||
as={Fragment}
|
||||
enter="ease-out duration-300"
|
||||
enterFrom="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
|
||||
enterTo="opacity-100 translate-y-0 sm:scale-100"
|
||||
leave="ease-in duration-200"
|
||||
leaveFrom="opacity-100 translate-y-0 sm:scale-100"
|
||||
leaveTo="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
|
||||
>
|
||||
<Dialog.Panel className="relative transform overflow-hidden rounded-2xl bg-white dark:bg-zinc-900 text-left shadow-xl transition-all sm:my-8 sm:w-full sm:max-w-lg border border-zinc-200 dark:border-zinc-800">
|
||||
<div className="p-6">
|
||||
<div className="flex items-start gap-4">
|
||||
<div className={`flex h-12 w-12 flex-shrink-0 items-center justify-center rounded-xl ${style.icon}`}>
|
||||
<ExclamationTriangleIcon className={`h-6 w-6 ${style.iconColor}`} />
|
||||
</div>
|
||||
<div className="flex-1">
|
||||
<Dialog.Title className="text-lg font-semibold text-zinc-900 dark:text-white">
|
||||
{title}
|
||||
</Dialog.Title>
|
||||
<p className="mt-2 text-sm text-zinc-600 dark:text-zinc-400">
|
||||
{message}
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
onClick={onClose}
|
||||
className="rounded-lg p-1.5 text-zinc-400 hover:text-zinc-600 dark:hover:text-zinc-300 hover:bg-zinc-100 dark:hover:bg-zinc-800 transition-colors"
|
||||
>
|
||||
<XMarkIcon className="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="mt-6 flex gap-3">
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
className="flex-1 px-4 py-2.5 border border-zinc-200 dark:border-zinc-700 text-zinc-700 dark:text-zinc-300 font-medium rounded-lg hover:bg-zinc-50 dark:hover:bg-zinc-800 transition-colors"
|
||||
>
|
||||
{cancelText}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleConfirm}
|
||||
className={`flex-1 px-4 py-2.5 text-white font-medium rounded-lg transition-colors ${style.button}`}
|
||||
>
|
||||
{confirmText}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog.Panel>
|
||||
</Transition.Child>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog>
|
||||
</Transition.Root>
|
||||
);
|
||||
}
|
||||
33
front-end-dash.aggios.app/components/layout/EmptyState.tsx
Normal file
33
front-end-dash.aggios.app/components/layout/EmptyState.tsx
Normal file
@@ -0,0 +1,33 @@
|
||||
import { ReactNode } from 'react';
|
||||
|
||||
interface EmptyStateProps {
|
||||
icon: ReactNode;
|
||||
title: string;
|
||||
description: string;
|
||||
actionLabel?: string;
|
||||
onAction?: () => void;
|
||||
}
|
||||
|
||||
export default function EmptyState({ icon, title, description, actionLabel, onAction }: EmptyStateProps) {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center h-64 bg-white dark:bg-zinc-900 rounded-xl border border-zinc-200 dark:border-zinc-800 text-center p-8">
|
||||
<div className="w-16 h-16 bg-zinc-50 dark:bg-zinc-800 rounded-full flex items-center justify-center mb-4">
|
||||
{icon}
|
||||
</div>
|
||||
<h3 className="text-lg font-medium text-zinc-900 dark:text-white mb-1">
|
||||
{title}
|
||||
</h3>
|
||||
<p className="text-zinc-500 dark:text-zinc-400 max-w-sm mx-auto">
|
||||
{description}
|
||||
</p>
|
||||
{actionLabel && onAction && (
|
||||
<button
|
||||
onClick={onAction}
|
||||
className="mt-4 text-sm text-[var(--brand-color)] hover:underline font-medium"
|
||||
>
|
||||
{actionLabel}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
export default function LoadingState() {
|
||||
return (
|
||||
<div className="flex items-center justify-center h-64 bg-white dark:bg-zinc-900 rounded-xl border border-zinc-200 dark:border-zinc-800">
|
||||
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-[var(--brand-color)]"></div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
31
front-end-dash.aggios.app/components/layout/PageHeader.tsx
Normal file
31
front-end-dash.aggios.app/components/layout/PageHeader.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
interface PageHeaderProps {
|
||||
title: string;
|
||||
description: string;
|
||||
actionLabel: string;
|
||||
onAction: () => void;
|
||||
}
|
||||
|
||||
export default function PageHeader({ title, description, actionLabel, onAction }: PageHeaderProps) {
|
||||
return (
|
||||
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-zinc-900 dark:text-white tracking-tight">
|
||||
{title}
|
||||
</h1>
|
||||
<p className="text-sm text-zinc-500 dark:text-zinc-400 mt-1">
|
||||
{description}
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
onClick={onAction}
|
||||
className="inline-flex items-center justify-center gap-2 px-4 py-2.5 text-sm font-medium text-white rounded-lg hover:opacity-90 transition-opacity"
|
||||
style={{ background: 'var(--gradient)' }}
|
||||
>
|
||||
<svg className="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 4v16m8-8H4" />
|
||||
</svg>
|
||||
{actionLabel}
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
108
front-end-dash.aggios.app/components/layout/Pagination.tsx
Normal file
108
front-end-dash.aggios.app/components/layout/Pagination.tsx
Normal file
@@ -0,0 +1,108 @@
|
||||
import { ChevronLeftIcon, ChevronRightIcon } from '@heroicons/react/24/outline';
|
||||
|
||||
interface PaginationProps {
|
||||
currentPage: number;
|
||||
totalPages: number;
|
||||
totalItems: number;
|
||||
itemsPerPage: number;
|
||||
onPageChange: (page: number) => void;
|
||||
}
|
||||
|
||||
export default function Pagination({
|
||||
currentPage,
|
||||
totalPages,
|
||||
totalItems,
|
||||
itemsPerPage,
|
||||
onPageChange
|
||||
}: PaginationProps) {
|
||||
const startItem = (currentPage - 1) * itemsPerPage + 1;
|
||||
const endItem = Math.min(currentPage * itemsPerPage, totalItems);
|
||||
|
||||
const pages = [];
|
||||
const maxVisiblePages = 5;
|
||||
|
||||
let startPage = Math.max(1, currentPage - Math.floor(maxVisiblePages / 2));
|
||||
let endPage = Math.min(totalPages, startPage + maxVisiblePages - 1);
|
||||
|
||||
if (endPage - startPage < maxVisiblePages - 1) {
|
||||
startPage = Math.max(1, endPage - maxVisiblePages + 1);
|
||||
}
|
||||
|
||||
for (let i = startPage; i <= endPage; i++) {
|
||||
pages.push(i);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="px-6 py-4 border-t border-zinc-200 dark:border-zinc-800 bg-zinc-50/50 dark:bg-zinc-800/50 flex flex-col sm:flex-row items-center justify-between gap-4">
|
||||
<p className="text-xs text-zinc-500 dark:text-zinc-400">
|
||||
Mostrando <span className="font-medium">{startItem}</span> a{' '}
|
||||
<span className="font-medium">{endItem}</span> de{' '}
|
||||
<span className="font-medium">{totalItems}</span> resultados
|
||||
</p>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<button
|
||||
onClick={() => onPageChange(currentPage - 1)}
|
||||
disabled={currentPage === 1}
|
||||
className="inline-flex items-center gap-1 px-3 py-1.5 text-xs font-medium rounded-md transition-colors disabled:opacity-50 disabled:cursor-not-allowed bg-white dark:bg-zinc-800 border border-zinc-200 dark:border-zinc-700 text-zinc-700 dark:text-zinc-300 hover:bg-zinc-50 dark:hover:bg-zinc-700"
|
||||
>
|
||||
<ChevronLeftIcon className="w-4 h-4" />
|
||||
Anterior
|
||||
</button>
|
||||
|
||||
<div className="hidden sm:flex items-center gap-1">
|
||||
{startPage > 1 && (
|
||||
<>
|
||||
<button
|
||||
onClick={() => onPageChange(1)}
|
||||
className="px-3 py-1.5 text-xs font-medium rounded-md bg-white dark:bg-zinc-800 border border-zinc-200 dark:border-zinc-700 text-zinc-700 dark:text-zinc-300 hover:bg-zinc-50 dark:hover:bg-zinc-700 transition-colors"
|
||||
>
|
||||
1
|
||||
</button>
|
||||
{startPage > 2 && (
|
||||
<span className="px-2 text-zinc-400">...</span>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
{pages.map(page => (
|
||||
<button
|
||||
key={page}
|
||||
onClick={() => onPageChange(page)}
|
||||
className={`px-3 py-1.5 text-xs font-medium rounded-md transition-colors ${page === currentPage
|
||||
? 'text-white shadow-sm'
|
||||
: 'bg-white dark:bg-zinc-800 border border-zinc-200 dark:border-zinc-700 text-zinc-700 dark:text-zinc-300 hover:bg-zinc-50 dark:hover:bg-zinc-700'
|
||||
}`}
|
||||
style={page === currentPage ? { background: 'var(--gradient)' } : {}}
|
||||
>
|
||||
{page}
|
||||
</button>
|
||||
))}
|
||||
|
||||
{endPage < totalPages && (
|
||||
<>
|
||||
{endPage < totalPages - 1 && (
|
||||
<span className="px-2 text-zinc-400">...</span>
|
||||
)}
|
||||
<button
|
||||
onClick={() => onPageChange(totalPages)}
|
||||
className="px-3 py-1.5 text-xs font-medium rounded-md bg-white dark:bg-zinc-800 border border-zinc-200 dark:border-zinc-700 text-zinc-700 dark:text-zinc-300 hover:bg-zinc-50 dark:hover:bg-zinc-700 transition-colors"
|
||||
>
|
||||
{totalPages}
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<button
|
||||
onClick={() => onPageChange(currentPage + 1)}
|
||||
disabled={currentPage === totalPages}
|
||||
className="inline-flex items-center gap-1 px-3 py-1.5 text-xs font-medium rounded-md transition-colors disabled:opacity-50 disabled:cursor-not-allowed bg-white dark:bg-zinc-800 border border-zinc-200 dark:border-zinc-700 text-zinc-700 dark:text-zinc-300 hover:bg-zinc-50 dark:hover:bg-zinc-700"
|
||||
>
|
||||
Próxima
|
||||
<ChevronRightIcon className="w-4 h-4" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
294
front-end-dash.aggios.app/components/layout/README.md
Normal file
294
front-end-dash.aggios.app/components/layout/README.md
Normal file
@@ -0,0 +1,294 @@
|
||||
# Componentes de Layout Padrão
|
||||
|
||||
Este diretório contém componentes reutilizáveis para manter um design system consistente em todas as páginas de listagem do dashboard.
|
||||
|
||||
## Componentes Disponíveis
|
||||
|
||||
### 1. **PageHeader**
|
||||
Header padrão com título, descrição e botão de ação.
|
||||
|
||||
```tsx
|
||||
import PageHeader from '@/components/layout/PageHeader';
|
||||
|
||||
<PageHeader
|
||||
title="Agências"
|
||||
description="Gerencie seus parceiros e acompanhe o desempenho."
|
||||
actionLabel="Nova Agência"
|
||||
onAction={() => setModalOpen(true)}
|
||||
/>
|
||||
```
|
||||
|
||||
### 2. **SearchBar**
|
||||
Barra de busca padrão com ícone de lupa.
|
||||
|
||||
```tsx
|
||||
import SearchBar from '@/components/layout/SearchBar';
|
||||
|
||||
<SearchBar
|
||||
value={searchTerm}
|
||||
onChange={setSearchTerm}
|
||||
placeholder="Buscar por nome, email..."
|
||||
/>
|
||||
```
|
||||
|
||||
### 3. **StatusFilter**
|
||||
Dropdown de filtro de status com Headless UI.
|
||||
|
||||
```tsx
|
||||
import StatusFilter from '@/components/layout/StatusFilter';
|
||||
|
||||
const STATUS_OPTIONS = [
|
||||
{ id: 'all', name: 'Todos os Status' },
|
||||
{ id: 'active', name: 'Ativos' },
|
||||
{ id: 'inactive', name: 'Inativos' },
|
||||
];
|
||||
|
||||
<StatusFilter
|
||||
options={STATUS_OPTIONS}
|
||||
selected={selectedStatus}
|
||||
onChange={setSelectedStatus}
|
||||
/>
|
||||
```
|
||||
|
||||
### 4. **EmptyState**
|
||||
Estado vazio padrão com ícone, título e descrição.
|
||||
|
||||
```tsx
|
||||
import EmptyState from '@/components/layout/EmptyState';
|
||||
import { BuildingOfficeIcon } from '@heroicons/react/24/outline';
|
||||
|
||||
<EmptyState
|
||||
icon={<BuildingOfficeIcon className="w-8 h-8 text-zinc-400" />}
|
||||
title="Nenhuma agência encontrada"
|
||||
description="Não encontramos resultados para os filtros selecionados."
|
||||
actionLabel="Limpar todos os filtros"
|
||||
onAction={clearFilters}
|
||||
/>
|
||||
```
|
||||
|
||||
### 5. **LoadingState**
|
||||
Estado de carregamento com spinner.
|
||||
|
||||
```tsx
|
||||
import LoadingState from '@/components/layout/LoadingState';
|
||||
|
||||
{loading && <LoadingState />}
|
||||
```
|
||||
|
||||
### 6. **StatusBadge**
|
||||
Badge de status ativo/inativo com toggle opcional.
|
||||
|
||||
```tsx
|
||||
import StatusBadge from '@/components/layout/StatusBadge';
|
||||
|
||||
<StatusBadge
|
||||
active={item.is_active}
|
||||
onClick={() => toggleStatus(item.id, item.is_active)}
|
||||
activeLabel="Ativo"
|
||||
inactiveLabel="Inativo"
|
||||
/>
|
||||
```
|
||||
|
||||
### 7. **Pagination** ⭐ NEW
|
||||
Paginação funcional com navegação e indicador de páginas.
|
||||
|
||||
```tsx
|
||||
import Pagination from '@/components/layout/Pagination';
|
||||
|
||||
const [currentPage, setCurrentPage] = useState(1);
|
||||
const itemsPerPage = 10;
|
||||
const totalItems = filteredItems.length;
|
||||
const totalPages = Math.ceil(totalItems / itemsPerPage);
|
||||
|
||||
const paginatedItems = filteredItems.slice(
|
||||
(currentPage - 1) * itemsPerPage,
|
||||
currentPage * itemsPerPage
|
||||
);
|
||||
|
||||
<Pagination
|
||||
currentPage={currentPage}
|
||||
totalPages={totalPages}
|
||||
totalItems={totalItems}
|
||||
itemsPerPage={itemsPerPage}
|
||||
onPageChange={setCurrentPage}
|
||||
/>
|
||||
```
|
||||
|
||||
### 8. **ConfirmDialog** ⭐ NEW
|
||||
Modal de confirmação profissional (substitui `confirm()`).
|
||||
|
||||
```tsx
|
||||
import { useState } from 'react';
|
||||
import ConfirmDialog from '@/components/layout/ConfirmDialog';
|
||||
|
||||
const [confirmOpen, setConfirmOpen] = useState(false);
|
||||
const [itemToDelete, setItemToDelete] = useState<string | null>(null);
|
||||
|
||||
const handleDeleteClick = (id: string) => {
|
||||
setItemToDelete(id);
|
||||
setConfirmOpen(true);
|
||||
};
|
||||
|
||||
const handleConfirmDelete = () => {
|
||||
if (itemToDelete) {
|
||||
// Executar exclusão
|
||||
deleteItem(itemToDelete);
|
||||
}
|
||||
};
|
||||
|
||||
<ConfirmDialog
|
||||
isOpen={confirmOpen}
|
||||
onClose={() => setConfirmOpen(false)}
|
||||
onConfirm={handleConfirmDelete}
|
||||
title="Excluir Item"
|
||||
message="Tem certeza que deseja excluir este item? Esta ação não pode ser desfeita."
|
||||
confirmText="Excluir"
|
||||
cancelText="Cancelar"
|
||||
variant="danger"
|
||||
/>
|
||||
```
|
||||
|
||||
### 9. **ToastContext & useToast** ⭐ NEW
|
||||
Sistema de notificações toast (substitui `alert()`).
|
||||
|
||||
**Setup no layout:**
|
||||
```tsx
|
||||
import { ToastProvider } from '@/components/layout/ToastContext';
|
||||
|
||||
<ToastProvider>
|
||||
{children}
|
||||
</ToastProvider>
|
||||
```
|
||||
|
||||
**Uso nas páginas:**
|
||||
```tsx
|
||||
import { useToast } from '@/components/layout/ToastContext';
|
||||
|
||||
const toast = useToast();
|
||||
|
||||
// Sucesso
|
||||
toast.success('Item criado!', 'O item foi criado com sucesso.');
|
||||
|
||||
// Erro
|
||||
toast.error('Erro ao excluir', 'Não foi possível excluir o item.');
|
||||
|
||||
// Info
|
||||
toast.info('Informação', 'Ação concluída.');
|
||||
```
|
||||
|
||||
## Exemplo de Uso Completo
|
||||
|
||||
```tsx
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect } from 'react';
|
||||
import PageHeader from '@/components/layout/PageHeader';
|
||||
import SearchBar from '@/components/layout/SearchBar';
|
||||
import StatusFilter from '@/components/layout/StatusFilter';
|
||||
import LoadingState from '@/components/layout/LoadingState';
|
||||
import EmptyState from '@/components/layout/EmptyState';
|
||||
import StatusBadge from '@/components/layout/StatusBadge';
|
||||
import TableFooter from '@/components/layout/TableFooter';
|
||||
import { BuildingOfficeIcon } from '@heroicons/react/24/outline';
|
||||
|
||||
const STATUS_OPTIONS = [
|
||||
{ id: 'all', name: 'Todos os Status' },
|
||||
{ id: 'active', name: 'Ativos' },
|
||||
{ id: 'inactive', name: 'Inativos' },
|
||||
];
|
||||
|
||||
export default function MyListPage() {
|
||||
const [items, setItems] = useState([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [searchTerm, setSearchTerm] = useState('');
|
||||
const [selectedStatus, setSelectedStatus] = useState(STATUS_OPTIONS[0]);
|
||||
|
||||
const filteredItems = items.filter(item => {
|
||||
const matchesSearch = item.name.toLowerCase().includes(searchTerm.toLowerCase());
|
||||
const matchesStatus =
|
||||
selectedStatus.id === 'all' ? true :
|
||||
selectedStatus.id === 'active' ? item.is_active :
|
||||
!item.is_active;
|
||||
return matchesSearch && matchesStatus;
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="p-6 max-w-[1600px] mx-auto space-y-6">
|
||||
<PageHeader
|
||||
title="Minha Lista"
|
||||
description="Descrição da página"
|
||||
actionLabel="Novo Item"
|
||||
onAction={() => {}}
|
||||
/>
|
||||
|
||||
<div className="flex flex-col lg:flex-row gap-4 items-center justify-between">
|
||||
<SearchBar
|
||||
value={searchTerm}
|
||||
onChange={setSearchTerm}
|
||||
placeholder="Buscar..."
|
||||
/>
|
||||
<StatusFilter
|
||||
options={STATUS_OPTIONS}
|
||||
selected={selectedStatus}
|
||||
onChange={setSelectedStatus}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{loading ? (
|
||||
<LoadingState />
|
||||
) : filteredItems.length === 0 ? (
|
||||
<EmptyState
|
||||
icon={<BuildingOfficeIcon className="w-8 h-8 text-zinc-400" />}
|
||||
title="Nenhum item encontrado"
|
||||
description="Tente ajustar os filtros."
|
||||
/>
|
||||
) : (
|
||||
<div className="bg-white dark:bg-zinc-900 rounded-xl border border-zinc-200 dark:border-zinc-800 overflow-hidden">
|
||||
<table className="w-full">
|
||||
{/* Sua tabela aqui */}
|
||||
</table>
|
||||
<TableFooter count={filteredItems.length} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
## Design System
|
||||
|
||||
### Cores
|
||||
```css
|
||||
--gradient: linear-gradient(135deg, #ff3a05, #ff0080)
|
||||
--brand-color: #ff0080
|
||||
```
|
||||
|
||||
### Classes Tailwind Padrão
|
||||
|
||||
**Container principal:**
|
||||
```
|
||||
p-6 max-w-[1600px] mx-auto space-y-6
|
||||
```
|
||||
|
||||
**Tabela:**
|
||||
```
|
||||
bg-white dark:bg-zinc-900 rounded-xl border border-zinc-200 dark:border-zinc-800
|
||||
```
|
||||
|
||||
**Header da tabela:**
|
||||
```
|
||||
bg-zinc-50/50 dark:bg-zinc-800/50 border-b border-zinc-200 dark:border-zinc-800
|
||||
```
|
||||
|
||||
**Linha hover:**
|
||||
```
|
||||
hover:bg-zinc-50 dark:hover:bg-zinc-800/50 transition-colors
|
||||
```
|
||||
|
||||
## Benefícios
|
||||
|
||||
✅ **Consistência visual** - Todas as páginas seguem o mesmo padrão
|
||||
✅ **Manutenção fácil** - Altere um componente, atualiza em todas as páginas
|
||||
✅ **Desenvolvimento rápido** - Reutilize componentes prontos
|
||||
✅ **Design system** - Cores e estilos centralizados
|
||||
✅ **Acessibilidade** - Componentes já otimizados
|
||||
24
front-end-dash.aggios.app/components/layout/SearchBar.tsx
Normal file
24
front-end-dash.aggios.app/components/layout/SearchBar.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
import { MagnifyingGlassIcon } from '@heroicons/react/24/outline';
|
||||
|
||||
interface SearchBarProps {
|
||||
value: string;
|
||||
onChange: (value: string) => void;
|
||||
placeholder?: string;
|
||||
}
|
||||
|
||||
export default function SearchBar({ value, onChange, placeholder = "Buscar..." }: SearchBarProps) {
|
||||
return (
|
||||
<div className="relative w-full lg:w-96">
|
||||
<div className="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
|
||||
<MagnifyingGlassIcon className="h-5 w-5 text-zinc-400" aria-hidden="true" />
|
||||
</div>
|
||||
<input
|
||||
type="text"
|
||||
className="block w-full pl-10 pr-3 py-2 border border-zinc-200 dark:border-zinc-700 rounded-lg leading-5 bg-white dark:bg-zinc-900 text-zinc-900 dark:text-zinc-100 placeholder-zinc-400 focus:outline-none focus:ring-1 focus:ring-[var(--brand-color)] focus:border-[var(--brand-color)] sm:text-sm transition duration-150 ease-in-out"
|
||||
placeholder={placeholder}
|
||||
value={value}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
28
front-end-dash.aggios.app/components/layout/StatusBadge.tsx
Normal file
28
front-end-dash.aggios.app/components/layout/StatusBadge.tsx
Normal file
@@ -0,0 +1,28 @@
|
||||
interface StatusBadgeProps {
|
||||
active: boolean;
|
||||
onClick?: () => void;
|
||||
activeLabel?: string;
|
||||
inactiveLabel?: string;
|
||||
}
|
||||
|
||||
export default function StatusBadge({
|
||||
active,
|
||||
onClick,
|
||||
activeLabel = 'Ativo',
|
||||
inactiveLabel = 'Inativo'
|
||||
}: StatusBadgeProps) {
|
||||
const Component = onClick ? 'button' : 'span';
|
||||
|
||||
return (
|
||||
<Component
|
||||
onClick={onClick}
|
||||
className={`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium border transition-all ${active
|
||||
? 'bg-emerald-50 text-emerald-700 border-emerald-200 dark:bg-emerald-900/20 dark:text-emerald-400 dark:border-emerald-900/30'
|
||||
: 'bg-zinc-100 text-zinc-600 border-zinc-200 dark:bg-zinc-800 dark:text-zinc-400 dark:border-zinc-700'
|
||||
} ${onClick ? 'cursor-pointer hover:opacity-80' : ''}`}
|
||||
>
|
||||
<span className={`w-1.5 h-1.5 rounded-full ${active ? 'bg-emerald-500' : 'bg-zinc-400'}`} />
|
||||
{active ? activeLabel : inactiveLabel}
|
||||
</Component>
|
||||
);
|
||||
}
|
||||
61
front-end-dash.aggios.app/components/layout/StatusFilter.tsx
Normal file
61
front-end-dash.aggios.app/components/layout/StatusFilter.tsx
Normal file
@@ -0,0 +1,61 @@
|
||||
import { Fragment } from 'react';
|
||||
import { Listbox, Transition } from '@headlessui/react';
|
||||
import { CheckIcon, ChevronUpDownIcon } from '@heroicons/react/24/outline';
|
||||
|
||||
interface StatusOption {
|
||||
id: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface StatusFilterProps {
|
||||
options: StatusOption[];
|
||||
selected: StatusOption;
|
||||
onChange: (option: StatusOption) => void;
|
||||
}
|
||||
|
||||
export default function StatusFilter({ options, selected, onChange }: StatusFilterProps) {
|
||||
return (
|
||||
<Listbox value={selected} onChange={onChange}>
|
||||
<div className="relative w-full sm:w-[180px]">
|
||||
<Listbox.Button className="relative w-full cursor-pointer rounded-lg bg-white dark:bg-zinc-900 py-2 pl-3 pr-10 text-left text-sm border border-zinc-200 dark:border-zinc-700 focus:outline-none focus:border-[var(--brand-color)] focus:ring-1 focus:ring-[var(--brand-color)] text-zinc-700 dark:text-zinc-300">
|
||||
<span className="block truncate">{selected.name}</span>
|
||||
<span className="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-2">
|
||||
<ChevronUpDownIcon className="h-4 w-4 text-zinc-400" aria-hidden="true" />
|
||||
</span>
|
||||
</Listbox.Button>
|
||||
<Transition
|
||||
as={Fragment}
|
||||
leave="transition ease-in duration-100"
|
||||
leaveFrom="opacity-100"
|
||||
leaveTo="opacity-0"
|
||||
>
|
||||
<Listbox.Options className="absolute z-10 mt-1 max-h-60 w-full overflow-auto rounded-md bg-white dark:bg-zinc-800 py-1 text-base ring-1 ring-black ring-opacity-5 focus:outline-none sm:text-sm border border-zinc-200 dark:border-zinc-700">
|
||||
{options.map((option, idx) => (
|
||||
<Listbox.Option
|
||||
key={idx}
|
||||
className={({ active }) =>
|
||||
`relative cursor-default select-none py-2 pl-10 pr-4 ${active ? 'bg-zinc-100 dark:bg-zinc-700 text-zinc-900 dark:text-white' : 'text-zinc-900 dark:text-zinc-100'
|
||||
}`
|
||||
}
|
||||
value={option}
|
||||
>
|
||||
{({ selected }) => (
|
||||
<>
|
||||
<span className={`block truncate ${selected ? 'font-medium' : 'font-normal'}`}>
|
||||
{option.name}
|
||||
</span>
|
||||
{selected ? (
|
||||
<span className="absolute inset-y-0 left-0 flex items-center pl-3 text-[var(--brand-color)]">
|
||||
<CheckIcon className="h-4 w-4" aria-hidden="true" />
|
||||
</span>
|
||||
) : null}
|
||||
</>
|
||||
)}
|
||||
</Listbox.Option>
|
||||
))}
|
||||
</Listbox.Options>
|
||||
</Transition>
|
||||
</div>
|
||||
</Listbox>
|
||||
);
|
||||
}
|
||||
57
front-end-dash.aggios.app/components/layout/ToastContext.tsx
Normal file
57
front-end-dash.aggios.app/components/layout/ToastContext.tsx
Normal file
@@ -0,0 +1,57 @@
|
||||
'use client';
|
||||
|
||||
import { createContext, useContext, useState, useCallback } from 'react';
|
||||
import ToastNotification, { Toast } from './ToastNotification';
|
||||
|
||||
interface ToastContextType {
|
||||
showToast: (type: Toast['type'], title: string, message?: string) => void;
|
||||
success: (title: string, message?: string) => void;
|
||||
error: (title: string, message?: string) => void;
|
||||
info: (title: string, message?: string) => void;
|
||||
}
|
||||
|
||||
const ToastContext = createContext<ToastContextType | undefined>(undefined);
|
||||
|
||||
export function ToastProvider({ children }: { children: React.ReactNode }) {
|
||||
const [toasts, setToasts] = useState<Toast[]>([]);
|
||||
|
||||
const showToast = useCallback((type: Toast['type'], title: string, message?: string) => {
|
||||
const id = Date.now().toString();
|
||||
setToasts(prev => [...prev, { id, type, title, message }]);
|
||||
}, []);
|
||||
|
||||
const success = useCallback((title: string, message?: string) => {
|
||||
showToast('success', title, message);
|
||||
}, [showToast]);
|
||||
|
||||
const error = useCallback((title: string, message?: string) => {
|
||||
showToast('error', title, message);
|
||||
}, [showToast]);
|
||||
|
||||
const info = useCallback((title: string, message?: string) => {
|
||||
showToast('info', title, message);
|
||||
}, [showToast]);
|
||||
|
||||
const removeToast = useCallback((id: string) => {
|
||||
setToasts(prev => prev.filter(toast => toast.id !== id));
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<ToastContext.Provider value={{ showToast, success, error, info }}>
|
||||
{children}
|
||||
<div className="fixed top-4 right-4 z-[9999] flex flex-col gap-3 w-96">
|
||||
{toasts.map(toast => (
|
||||
<ToastNotification key={toast.id} toast={toast} onClose={removeToast} />
|
||||
))}
|
||||
</div>
|
||||
</ToastContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export function useToast() {
|
||||
const context = useContext(ToastContext);
|
||||
if (!context) {
|
||||
throw new Error('useToast must be used within ToastProvider');
|
||||
}
|
||||
return context;
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
import { Fragment, useEffect } from 'react';
|
||||
import { Transition } from '@headlessui/react';
|
||||
import {
|
||||
CheckCircleIcon,
|
||||
XCircleIcon,
|
||||
InformationCircleIcon,
|
||||
XMarkIcon
|
||||
} from '@heroicons/react/24/outline';
|
||||
|
||||
export interface Toast {
|
||||
id: string;
|
||||
type: 'success' | 'error' | 'info';
|
||||
title: string;
|
||||
message?: string;
|
||||
}
|
||||
|
||||
interface ToastNotificationProps {
|
||||
toast: Toast;
|
||||
onClose: (id: string) => void;
|
||||
}
|
||||
|
||||
export default function ToastNotification({ toast, onClose }: ToastNotificationProps) {
|
||||
useEffect(() => {
|
||||
const timer = setTimeout(() => {
|
||||
onClose(toast.id);
|
||||
}, 5000);
|
||||
|
||||
return () => clearTimeout(timer);
|
||||
}, [toast.id, onClose]);
|
||||
|
||||
const styles = {
|
||||
success: {
|
||||
bg: 'bg-emerald-50 dark:bg-emerald-900/20',
|
||||
border: 'border-emerald-200 dark:border-emerald-900/30',
|
||||
icon: 'text-emerald-600 dark:text-emerald-400',
|
||||
title: 'text-emerald-900 dark:text-emerald-300',
|
||||
IconComponent: CheckCircleIcon
|
||||
},
|
||||
error: {
|
||||
bg: 'bg-red-50 dark:bg-red-900/20',
|
||||
border: 'border-red-200 dark:border-red-900/30',
|
||||
icon: 'text-red-600 dark:text-red-400',
|
||||
title: 'text-red-900 dark:text-red-300',
|
||||
IconComponent: XCircleIcon
|
||||
},
|
||||
info: {
|
||||
bg: 'bg-blue-50 dark:bg-blue-900/20',
|
||||
border: 'border-blue-200 dark:border-blue-900/30',
|
||||
icon: 'text-blue-600 dark:text-blue-400',
|
||||
title: 'text-blue-900 dark:text-blue-300',
|
||||
IconComponent: InformationCircleIcon
|
||||
}
|
||||
};
|
||||
|
||||
const style = styles[toast.type];
|
||||
const Icon = style.IconComponent;
|
||||
|
||||
return (
|
||||
<Transition
|
||||
show={true}
|
||||
as={Fragment}
|
||||
enter="transform ease-out duration-300 transition"
|
||||
enterFrom="translate-y-2 opacity-0 sm:translate-y-0 sm:translate-x-2"
|
||||
enterTo="translate-y-0 opacity-100 sm:translate-x-0"
|
||||
leave="transition ease-in duration-100"
|
||||
leaveFrom="opacity-100"
|
||||
leaveTo="opacity-0"
|
||||
>
|
||||
<div className={`pointer-events-auto w-full rounded-lg border shadow-lg ${style.bg} ${style.border}`}>
|
||||
<div className="p-4">
|
||||
<div className="flex items-start gap-3">
|
||||
<div className="flex-shrink-0">
|
||||
<Icon className={`h-6 w-6 ${style.icon}`} />
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<p className={`text-sm font-semibold ${style.title}`}>
|
||||
{toast.title}
|
||||
</p>
|
||||
{toast.message && (
|
||||
<p className="mt-1 text-sm text-zinc-600 dark:text-zinc-400">
|
||||
{toast.message}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex-shrink-0">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onClose(toast.id)}
|
||||
className="inline-flex rounded-md text-zinc-400 hover:text-zinc-500 dark:hover:text-zinc-300 focus:outline-none"
|
||||
>
|
||||
<XMarkIcon className="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Transition>
|
||||
);
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
'use client';
|
||||
|
||||
import { Fragment, useState } from 'react';
|
||||
import { Dialog, Transition } from '@headlessui/react';
|
||||
import { Dialog, Transition, Tab } from '@headlessui/react';
|
||||
import {
|
||||
XMarkIcon,
|
||||
SparklesIcon,
|
||||
PlusIcon,
|
||||
MinusIcon,
|
||||
} from '@heroicons/react/24/outline';
|
||||
|
||||
interface CreatePlanModalProps {
|
||||
@@ -21,16 +23,13 @@ interface CreatePlanForm {
|
||||
max_users: number;
|
||||
monthly_price: string;
|
||||
annual_price: string;
|
||||
discount_months: number;
|
||||
features: string;
|
||||
differentiators: string;
|
||||
storage_gb: number;
|
||||
is_active: boolean;
|
||||
}
|
||||
|
||||
function classNames(...classes: string[]) {
|
||||
return classes.filter(Boolean).join(' ');
|
||||
}
|
||||
|
||||
export default function CreatePlanModal({ isOpen, onClose, onSuccess }: CreatePlanModalProps) {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
@@ -42,9 +41,10 @@ export default function CreatePlanModal({ isOpen, onClose, onSuccess }: CreatePl
|
||||
max_users: 30,
|
||||
monthly_price: '',
|
||||
annual_price: '',
|
||||
discount_months: 2,
|
||||
features: '',
|
||||
differentiators: '',
|
||||
storage_gb: 1,
|
||||
storage_gb: 10,
|
||||
is_active: true,
|
||||
});
|
||||
|
||||
@@ -57,10 +57,28 @@ export default function CreatePlanModal({ isOpen, onClose, onSuccess }: CreatePl
|
||||
[name]: (e.target as HTMLInputElement).checked,
|
||||
}));
|
||||
} else if (type === 'number') {
|
||||
setFormData(prev => ({
|
||||
...prev,
|
||||
[name]: parseFloat(value) || 0,
|
||||
}));
|
||||
const numValue = parseFloat(value) || 0;
|
||||
setFormData(prev => {
|
||||
const newData = {
|
||||
...prev,
|
||||
[name]: numValue,
|
||||
};
|
||||
|
||||
// Calcular preço anual automaticamente quando mensal ou discount_months muda
|
||||
if ((name === 'monthly_price' || name === 'discount_months')) {
|
||||
const monthlyPrice = name === 'monthly_price' ? numValue : parseFloat(prev.monthly_price) || 0;
|
||||
const discountMonths = name === 'discount_months' ? numValue : prev.discount_months;
|
||||
|
||||
if (monthlyPrice > 0 && discountMonths >= 0) {
|
||||
// Calcula: (12 meses - meses de desconto) * preço mensal
|
||||
const monthsToPay = Math.max(0, 12 - discountMonths);
|
||||
const annualWithDiscount = (monthlyPrice * monthsToPay).toFixed(2);
|
||||
newData.annual_price = annualWithDiscount;
|
||||
}
|
||||
}
|
||||
|
||||
return newData;
|
||||
});
|
||||
} else {
|
||||
setFormData(prev => ({
|
||||
...prev,
|
||||
@@ -69,13 +87,54 @@ export default function CreatePlanModal({ isOpen, onClose, onSuccess }: CreatePl
|
||||
}
|
||||
};
|
||||
|
||||
const incrementValue = (field: 'min_users' | 'max_users' | 'storage_gb' | 'discount_months', step: number = 1) => {
|
||||
setFormData(prev => {
|
||||
const newValue = prev[field] + step;
|
||||
const newData = {
|
||||
...prev,
|
||||
[field]: newValue,
|
||||
};
|
||||
|
||||
// Recalcular preço anual se mudou discount_months
|
||||
if (field === 'discount_months') {
|
||||
const monthlyPrice = parseFloat(prev.monthly_price) || 0;
|
||||
if (monthlyPrice > 0 && newValue >= 0) {
|
||||
const monthsToPay = Math.max(0, 12 - newValue);
|
||||
newData.annual_price = (monthlyPrice * monthsToPay).toFixed(2);
|
||||
}
|
||||
}
|
||||
|
||||
return newData;
|
||||
});
|
||||
};
|
||||
|
||||
const decrementValue = (field: 'min_users' | 'max_users' | 'storage_gb' | 'discount_months', step: number = 1, min: number = 0) => {
|
||||
setFormData(prev => {
|
||||
const newValue = Math.max(min, prev[field] - step);
|
||||
const newData = {
|
||||
...prev,
|
||||
[field]: newValue,
|
||||
};
|
||||
|
||||
// Recalcular preço anual se mudou discount_months
|
||||
if (field === 'discount_months') {
|
||||
const monthlyPrice = parseFloat(prev.monthly_price) || 0;
|
||||
if (monthlyPrice > 0 && newValue >= 0) {
|
||||
const monthsToPay = Math.max(0, 12 - newValue);
|
||||
newData.annual_price = (monthlyPrice * monthsToPay).toFixed(2);
|
||||
}
|
||||
}
|
||||
|
||||
return newData;
|
||||
});
|
||||
};
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
setLoading(true);
|
||||
setError('');
|
||||
|
||||
try {
|
||||
// Validações básicas
|
||||
if (!formData.name || !formData.slug) {
|
||||
setError('Nome e Slug são obrigatórios');
|
||||
setLoading(false);
|
||||
@@ -84,7 +143,6 @@ export default function CreatePlanModal({ isOpen, onClose, onSuccess }: CreatePl
|
||||
|
||||
const token = localStorage.getItem('token');
|
||||
|
||||
// Parse features e differentiators
|
||||
const features = formData.features
|
||||
.split(',')
|
||||
.map(f => f.trim())
|
||||
@@ -109,6 +167,8 @@ export default function CreatePlanModal({ isOpen, onClose, onSuccess }: CreatePl
|
||||
is_active: formData.is_active,
|
||||
};
|
||||
|
||||
console.log('Enviando payload:', payload);
|
||||
|
||||
const response = await fetch('/api/admin/plans', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@@ -119,15 +179,18 @@ export default function CreatePlanModal({ isOpen, onClose, onSuccess }: CreatePl
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json();
|
||||
throw new Error(error.message || 'Erro ao criar plano');
|
||||
const errorData = await response.json();
|
||||
console.error('Erro da API:', errorData);
|
||||
throw new Error(errorData.message || 'Erro ao criar plano');
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
console.log('Plano criado:', data);
|
||||
onSuccess(data.plan);
|
||||
onClose();
|
||||
handleClose();
|
||||
} catch (err: any) {
|
||||
setError(err.message);
|
||||
console.error('Erro ao criar plano:', err);
|
||||
setError(err.message || 'Erro desconhecido ao criar plano');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -144,9 +207,10 @@ export default function CreatePlanModal({ isOpen, onClose, onSuccess }: CreatePl
|
||||
max_users: 30,
|
||||
monthly_price: '',
|
||||
annual_price: '',
|
||||
discount_months: 2,
|
||||
features: '',
|
||||
differentiators: '',
|
||||
storage_gb: 1,
|
||||
storage_gb: 10,
|
||||
is_active: true,
|
||||
});
|
||||
onClose();
|
||||
@@ -179,229 +243,366 @@ export default function CreatePlanModal({ isOpen, onClose, onSuccess }: CreatePl
|
||||
leaveFrom="opacity-100 translate-y-0 sm:scale-100"
|
||||
leaveTo="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
|
||||
>
|
||||
<Dialog.Panel className="relative transform overflow-hidden rounded-2xl bg-white dark:bg-zinc-900 text-left shadow-xl transition-all sm:my-8 sm:w-full sm:max-w-2xl border border-zinc-200 dark:border-zinc-800">
|
||||
<div className="absolute right-0 top-0 hidden pr-4 pt-4 sm:block">
|
||||
<Dialog.Panel className="relative transform overflow-hidden rounded-2xl bg-white dark:bg-zinc-900 text-left shadow-xl transition-all sm:my-8 sm:w-full sm:max-w-3xl border border-zinc-200 dark:border-zinc-800">
|
||||
<div className="absolute right-0 top-0 pr-6 pt-6">
|
||||
<button
|
||||
type="button"
|
||||
className="rounded-md bg-white dark:bg-zinc-900 text-zinc-400 hover:text-zinc-500 focus:outline-none"
|
||||
className="rounded-lg p-1.5 text-zinc-400 hover:text-zinc-600 dark:hover:text-zinc-300 hover:bg-zinc-100 dark:hover:bg-zinc-800 transition-colors"
|
||||
onClick={handleClose}
|
||||
disabled={loading}
|
||||
>
|
||||
<span className="sr-only">Fechar</span>
|
||||
<XMarkIcon className="h-6 w-6" aria-hidden="true" />
|
||||
<XMarkIcon className="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="p-6 sm:p-8">
|
||||
{/* Header */}
|
||||
<div className="sm:flex sm:items-start mb-6">
|
||||
<div className="mx-auto flex h-12 w-12 flex-shrink-0 items-center justify-center rounded-full bg-blue-100 dark:bg-blue-900 sm:mx-0 sm:h-10 sm:w-10">
|
||||
<SparklesIcon className="h-6 w-6 text-blue-600 dark:text-blue-400" aria-hidden="true" />
|
||||
<div className="flex items-start gap-4 mb-6">
|
||||
<div
|
||||
className="flex h-12 w-12 flex-shrink-0 items-center justify-center rounded-xl shadow-lg"
|
||||
style={{ background: 'var(--gradient)' }}
|
||||
>
|
||||
<SparklesIcon className="h-6 w-6 text-white" />
|
||||
</div>
|
||||
<div className="mt-3 text-center sm:ml-4 sm:mt-0 sm:text-left">
|
||||
<Dialog.Title as="h3" className="text-xl font-semibold leading-6 text-zinc-900 dark:text-white">
|
||||
<div>
|
||||
<Dialog.Title className="text-xl font-bold text-zinc-900 dark:text-white">
|
||||
Criar Novo Plano
|
||||
</Dialog.Title>
|
||||
<div className="mt-2">
|
||||
<p className="text-sm text-zinc-500 dark:text-zinc-400">
|
||||
Configure um novo plano de assinatura para as agências.
|
||||
</p>
|
||||
</div>
|
||||
<p className="mt-1 text-sm text-zinc-500 dark:text-zinc-400">
|
||||
Configure um novo plano de assinatura para as agências.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Error Message */}
|
||||
{error && (
|
||||
<div className="mb-4 rounded-lg bg-red-50 dark:bg-red-900/20 p-4 border border-red-200 dark:border-red-800">
|
||||
<div className="mb-6 rounded-lg bg-red-50 dark:bg-red-900/20 p-4 border border-red-200 dark:border-red-800">
|
||||
<p className="text-sm font-medium text-red-800 dark:text-red-400">{error}</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
{/* Row 1: Nome e Slug */}
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-zinc-900 dark:text-zinc-100 mb-1">
|
||||
Nome do Plano *
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
name="name"
|
||||
value={formData.name}
|
||||
onChange={handleChange}
|
||||
placeholder="Ex: Ignição"
|
||||
className="w-full px-3 py-2 border border-zinc-300 dark:border-zinc-600 rounded-lg bg-white dark:bg-zinc-800 text-zinc-900 dark:text-white placeholder-zinc-400 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-zinc-900 dark:text-zinc-100 mb-1">
|
||||
Slug *
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
name="slug"
|
||||
value={formData.slug}
|
||||
onChange={handleChange}
|
||||
placeholder="Ex: ignition"
|
||||
className="w-full px-3 py-2 border border-zinc-300 dark:border-zinc-600 rounded-lg bg-white dark:bg-zinc-800 text-zinc-900 dark:text-white placeholder-zinc-400 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<form onSubmit={handleSubmit}>
|
||||
<Tab.Group>
|
||||
<Tab.List className="flex gap-2 p-1 bg-zinc-100 dark:bg-zinc-800 rounded-lg mb-6">
|
||||
{['Dados Básicos', 'Usuários', 'Preços', 'Avançado'].map((tab) => (
|
||||
<Tab
|
||||
key={tab}
|
||||
className={({ selected }) =>
|
||||
`flex-1 px-4 py-2.5 text-sm font-medium rounded-lg transition-all focus:outline-none ${selected
|
||||
? 'bg-white dark:bg-zinc-900 text-zinc-900 dark:text-white shadow-sm'
|
||||
: 'text-zinc-600 dark:text-zinc-400 hover:text-zinc-900 dark:hover:text-white'
|
||||
}`
|
||||
}
|
||||
>
|
||||
{tab}
|
||||
</Tab>
|
||||
))}
|
||||
</Tab.List>
|
||||
|
||||
{/* Descrição */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-zinc-900 dark:text-zinc-100 mb-1">
|
||||
Descrição
|
||||
</label>
|
||||
<textarea
|
||||
name="description"
|
||||
value={formData.description}
|
||||
onChange={handleChange}
|
||||
placeholder="Descrição breve do plano"
|
||||
rows={2}
|
||||
className="w-full px-3 py-2 border border-zinc-300 dark:border-zinc-600 rounded-lg bg-white dark:bg-zinc-800 text-zinc-900 dark:text-white placeholder-zinc-400 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent resize-none"
|
||||
/>
|
||||
</div>
|
||||
<Tab.Panels className="space-y-4">
|
||||
{/* Tab 1: Dados Básicos */}
|
||||
<Tab.Panel className="space-y-4">
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-2">
|
||||
Nome do Plano *
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
name="name"
|
||||
value={formData.name}
|
||||
onChange={handleChange}
|
||||
placeholder="Ex: Ignição"
|
||||
className="w-full px-3 py-2.5 border border-zinc-200 dark:border-zinc-700 rounded-lg bg-white dark:bg-zinc-900 text-zinc-900 dark:text-white placeholder-zinc-400 focus:outline-none focus:ring-2 focus:ring-[var(--brand-color)] focus:border-transparent transition-all"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-2">
|
||||
Slug *
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
name="slug"
|
||||
value={formData.slug}
|
||||
onChange={handleChange}
|
||||
placeholder="Ex: ignition"
|
||||
className="w-full px-3 py-2.5 border border-zinc-200 dark:border-zinc-700 rounded-lg bg-white dark:bg-zinc-900 text-zinc-900 dark:text-white placeholder-zinc-400 focus:outline-none focus:ring-2 focus:ring-[var(--brand-color)] focus:border-transparent transition-all"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Row 2: Usuários */}
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-zinc-900 dark:text-zinc-100 mb-1">
|
||||
Mín. Usuários
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
name="min_users"
|
||||
value={formData.min_users}
|
||||
onChange={handleChange}
|
||||
min="1"
|
||||
className="w-full px-3 py-2 border border-zinc-300 dark:border-zinc-600 rounded-lg bg-white dark:bg-zinc-800 text-zinc-900 dark:text-white placeholder-zinc-400 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-zinc-900 dark:text-zinc-100 mb-1">
|
||||
Máx. Usuários (-1 = ilimitado)
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
name="max_users"
|
||||
value={formData.max_users}
|
||||
onChange={handleChange}
|
||||
className="w-full px-3 py-2 border border-zinc-300 dark:border-zinc-600 rounded-lg bg-white dark:bg-zinc-800 text-zinc-900 dark:text-white placeholder-zinc-400 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-2">
|
||||
Descrição
|
||||
</label>
|
||||
<textarea
|
||||
name="description"
|
||||
value={formData.description}
|
||||
onChange={handleChange}
|
||||
placeholder="Descrição breve do plano"
|
||||
rows={3}
|
||||
className="w-full px-3 py-2.5 border border-zinc-200 dark:border-zinc-700 rounded-lg bg-white dark:bg-zinc-900 text-zinc-900 dark:text-white placeholder-zinc-400 focus:outline-none focus:ring-2 focus:ring-[var(--brand-color)] focus:border-transparent resize-none transition-all"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Row 3: Preços */}
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-zinc-900 dark:text-zinc-100 mb-1">
|
||||
Preço Mensal (BRL)
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
name="monthly_price"
|
||||
value={formData.monthly_price}
|
||||
onChange={handleChange}
|
||||
placeholder="199.99"
|
||||
step="0.01"
|
||||
className="w-full px-3 py-2 border border-zinc-300 dark:border-zinc-600 rounded-lg bg-white dark:bg-zinc-800 text-zinc-900 dark:text-white placeholder-zinc-400 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-zinc-900 dark:text-zinc-100 mb-1">
|
||||
Preço Anual (BRL)
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
name="annual_price"
|
||||
value={formData.annual_price}
|
||||
onChange={handleChange}
|
||||
placeholder="1919.90"
|
||||
step="0.01"
|
||||
className="w-full px-3 py-2 border border-zinc-300 dark:border-zinc-600 rounded-lg bg-white dark:bg-zinc-800 text-zinc-900 dark:text-white placeholder-zinc-400 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center pt-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
name="is_active"
|
||||
checked={formData.is_active}
|
||||
onChange={handleChange}
|
||||
className="h-4 w-4 rounded border-zinc-300 dark:border-zinc-600 focus:ring-2 focus:ring-[var(--brand-color)]"
|
||||
style={{ accentColor: 'var(--brand-color)' }}
|
||||
/>
|
||||
<label className="ml-3 text-sm font-medium text-zinc-700 dark:text-zinc-300">
|
||||
Plano Ativo
|
||||
</label>
|
||||
</div>
|
||||
</Tab.Panel>
|
||||
|
||||
{/* Row 4: Storage */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-zinc-900 dark:text-zinc-100 mb-1">
|
||||
Armazenamento (GB)
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
name="storage_gb"
|
||||
value={formData.storage_gb}
|
||||
onChange={handleChange}
|
||||
min="1"
|
||||
className="w-full px-3 py-2 border border-zinc-300 dark:border-zinc-600 rounded-lg bg-white dark:bg-zinc-800 text-zinc-900 dark:text-white placeholder-zinc-400 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
||||
/>
|
||||
</div>
|
||||
{/* Tab 2: Usuários */}
|
||||
<Tab.Panel className="space-y-4">
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-2">
|
||||
Mínimo de Usuários
|
||||
</label>
|
||||
<div className="flex items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => decrementValue('min_users', 1, 1)}
|
||||
className="p-2 rounded-lg border border-zinc-200 dark:border-zinc-700 hover:bg-zinc-50 dark:hover:bg-zinc-800 transition-colors"
|
||||
>
|
||||
<MinusIcon className="w-4 h-4 text-zinc-600 dark:text-zinc-400" />
|
||||
</button>
|
||||
<input
|
||||
type="number"
|
||||
name="min_users"
|
||||
value={formData.min_users}
|
||||
onChange={handleChange}
|
||||
min="1"
|
||||
className="flex-1 px-3 py-2.5 border border-zinc-200 dark:border-zinc-700 rounded-lg bg-white dark:bg-zinc-900 text-zinc-900 dark:text-white text-center font-medium focus:outline-none focus:ring-2 focus:ring-[var(--brand-color)] focus:border-transparent transition-all"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => incrementValue('min_users', 1)}
|
||||
className="p-2 rounded-lg border border-zinc-200 dark:border-zinc-700 hover:bg-zinc-50 dark:hover:bg-zinc-800 transition-colors"
|
||||
>
|
||||
<PlusIcon className="w-4 h-4 text-zinc-600 dark:text-zinc-400" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-2">
|
||||
Máximo de Usuários
|
||||
</label>
|
||||
<div className="flex items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => decrementValue('max_users', 5, -1)}
|
||||
className="p-2 rounded-lg border border-zinc-200 dark:border-zinc-700 hover:bg-zinc-50 dark:hover:bg-zinc-800 transition-colors"
|
||||
>
|
||||
<MinusIcon className="w-4 h-4 text-zinc-600 dark:text-zinc-400" />
|
||||
</button>
|
||||
<input
|
||||
type="number"
|
||||
name="max_users"
|
||||
value={formData.max_users}
|
||||
onChange={handleChange}
|
||||
className="flex-1 px-3 py-2.5 border border-zinc-200 dark:border-zinc-700 rounded-lg bg-white dark:bg-zinc-900 text-zinc-900 dark:text-white text-center font-medium focus:outline-none focus:ring-2 focus:ring-[var(--brand-color)] focus:border-transparent transition-all"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => incrementValue('max_users', 5)}
|
||||
className="p-2 rounded-lg border border-zinc-200 dark:border-zinc-700 hover:bg-zinc-50 dark:hover:bg-zinc-800 transition-colors"
|
||||
>
|
||||
<PlusIcon className="w-4 h-4 text-zinc-600 dark:text-zinc-400" />
|
||||
</button>
|
||||
</div>
|
||||
<p className="mt-2 text-xs text-zinc-500 dark:text-zinc-400">
|
||||
Use -1 para ilimitado
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</Tab.Panel>
|
||||
|
||||
{/* Row 5: Features */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-zinc-900 dark:text-zinc-100 mb-1">
|
||||
Recursos <span className="text-xs text-zinc-500">(separados por vírgula)</span>
|
||||
</label>
|
||||
<textarea
|
||||
name="features"
|
||||
value={formData.features}
|
||||
onChange={handleChange}
|
||||
placeholder="CRM, ERP, Projetos, Helpdesk, Pagamentos, Contratos, Documentos"
|
||||
rows={2}
|
||||
className="w-full px-3 py-2 border border-zinc-300 dark:border-zinc-600 rounded-lg bg-white dark:bg-zinc-800 text-zinc-900 dark:text-white placeholder-zinc-400 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent resize-none"
|
||||
/>
|
||||
</div>
|
||||
{/* Tab 3: Preços */}
|
||||
<Tab.Panel className="space-y-4">
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-2">
|
||||
Preço Mensal (R$) *
|
||||
</label>
|
||||
<div className="relative">
|
||||
<span className="absolute left-3 top-1/2 -translate-y-1/2 text-zinc-500">R$</span>
|
||||
<input
|
||||
type="number"
|
||||
name="monthly_price"
|
||||
value={formData.monthly_price}
|
||||
onChange={handleChange}
|
||||
placeholder="199.99"
|
||||
step="0.01"
|
||||
className="w-full pl-10 pr-3 py-2.5 border border-zinc-200 dark:border-zinc-700 rounded-lg bg-white dark:bg-zinc-900 text-zinc-900 dark:text-white placeholder-zinc-400 focus:outline-none focus:ring-2 focus:ring-[var(--brand-color)] focus:border-transparent transition-all"
|
||||
/>
|
||||
</div>
|
||||
<p className="mt-2 text-xs text-zinc-500 dark:text-zinc-400">
|
||||
Digite o preço mensal
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-2">
|
||||
Meses Grátis (Desconto)
|
||||
</label>
|
||||
<div className="flex items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => decrementValue('discount_months', 1, 0)}
|
||||
className="p-2 rounded-lg border border-zinc-200 dark:border-zinc-700 hover:bg-zinc-50 dark:hover:bg-zinc-800 transition-colors"
|
||||
>
|
||||
<MinusIcon className="w-4 h-4 text-zinc-600 dark:text-zinc-400" />
|
||||
</button>
|
||||
<input
|
||||
type="number"
|
||||
name="discount_months"
|
||||
value={formData.discount_months}
|
||||
onChange={handleChange}
|
||||
min="0"
|
||||
max="11"
|
||||
className="flex-1 px-3 py-2.5 border border-zinc-200 dark:border-zinc-700 rounded-lg bg-white dark:bg-zinc-900 text-zinc-900 dark:text-white text-center font-medium focus:outline-none focus:ring-2 focus:ring-[var(--brand-color)] focus:border-transparent transition-all"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => incrementValue('discount_months', 1)}
|
||||
className="p-2 rounded-lg border border-zinc-200 dark:border-zinc-700 hover:bg-zinc-50 dark:hover:bg-zinc-800 transition-colors"
|
||||
>
|
||||
<PlusIcon className="w-4 h-4 text-zinc-600 dark:text-zinc-400" />
|
||||
</button>
|
||||
</div>
|
||||
<p className="mt-2 text-xs text-zinc-500 dark:text-zinc-400">
|
||||
Ex: 2 = cliente paga 10 meses
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Row 6: Diferenciais */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-zinc-900 dark:text-zinc-100 mb-1">
|
||||
Diferenciais <span className="text-xs text-zinc-500">(separados por vírgula)</span>
|
||||
</label>
|
||||
<textarea
|
||||
name="differentiators"
|
||||
value={formData.differentiators}
|
||||
onChange={handleChange}
|
||||
placeholder="Suporte prioritário, Gerente de conta dedicado, API integrações"
|
||||
rows={2}
|
||||
className="w-full px-3 py-2 border border-zinc-300 dark:border-zinc-600 rounded-lg bg-white dark:bg-zinc-800 text-zinc-900 dark:text-white placeholder-zinc-400 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent resize-none"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-2">
|
||||
Preço Anual (R$) <span className="text-emerald-600 dark:text-emerald-400">✓ Auto</span>
|
||||
</label>
|
||||
<div className="relative">
|
||||
<span className="absolute left-3 top-1/2 -translate-y-1/2 text-zinc-500">R$</span>
|
||||
<input
|
||||
type="number"
|
||||
name="annual_price"
|
||||
value={formData.annual_price}
|
||||
onChange={handleChange}
|
||||
placeholder="Calculado automaticamente"
|
||||
step="0.01"
|
||||
className="w-full pl-10 pr-3 py-2.5 border border-zinc-200 dark:border-zinc-700 rounded-lg bg-white dark:bg-zinc-900 text-zinc-900 dark:text-white placeholder-zinc-400 focus:outline-none focus:ring-2 focus:ring-[var(--brand-color)] focus:border-transparent transition-all"
|
||||
/>
|
||||
</div>
|
||||
{formData.monthly_price && formData.annual_price && formData.discount_months > 0 && (
|
||||
<p className="mt-2 text-xs font-medium text-emerald-600 dark:text-emerald-400">
|
||||
💰 Cliente paga {12 - formData.discount_months} meses e ganha {formData.discount_months} mês(es) grátis!
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Status Checkbox */}
|
||||
<div className="flex items-center pt-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
name="is_active"
|
||||
checked={formData.is_active}
|
||||
onChange={handleChange}
|
||||
className="h-4 w-4 text-blue-600 rounded border-zinc-300 focus:ring-blue-500"
|
||||
/>
|
||||
<label className="ml-3 text-sm font-medium text-zinc-900 dark:text-zinc-100">
|
||||
Plano Ativo
|
||||
</label>
|
||||
</div>
|
||||
<div className="p-4 bg-gradient-to-r from-emerald-50 to-blue-50 dark:from-emerald-900/20 dark:to-blue-900/20 rounded-lg border border-emerald-200 dark:border-emerald-800">
|
||||
<p className="text-sm font-medium text-emerald-900 dark:text-emerald-100 mb-1">
|
||||
🎯 Cálculo Automático de Desconto
|
||||
</p>
|
||||
<p className="text-xs text-emerald-700 dark:text-emerald-300">
|
||||
Configure quantos meses de desconto deseja oferecer. O preço anual será calculado automaticamente: <strong>Preço Mensal × (12 - Meses Grátis)</strong>. Ideal para promoções sazonais!
|
||||
</p>
|
||||
</div>
|
||||
</Tab.Panel>
|
||||
|
||||
{/* Tab 4: Avançado */}
|
||||
<Tab.Panel className="space-y-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-2">
|
||||
Armazenamento (GB)
|
||||
</label>
|
||||
<div className="flex items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => decrementValue('storage_gb', 1, 1)}
|
||||
className="p-2 rounded-lg border border-zinc-200 dark:border-zinc-700 hover:bg-zinc-50 dark:hover:bg-zinc-800 transition-colors"
|
||||
>
|
||||
<MinusIcon className="w-4 h-4 text-zinc-600 dark:text-zinc-400" />
|
||||
</button>
|
||||
<input
|
||||
type="number"
|
||||
name="storage_gb"
|
||||
value={formData.storage_gb}
|
||||
onChange={handleChange}
|
||||
min="1"
|
||||
className="flex-1 px-3 py-2.5 border border-zinc-200 dark:border-zinc-700 rounded-lg bg-white dark:bg-zinc-900 text-zinc-900 dark:text-white text-center font-medium focus:outline-none focus:ring-2 focus:ring-[var(--brand-color)] focus:border-transparent transition-all"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => incrementValue('storage_gb', 1)}
|
||||
className="p-2 rounded-lg border border-zinc-200 dark:border-zinc-700 hover:bg-zinc-50 dark:hover:bg-zinc-800 transition-colors"
|
||||
>
|
||||
<PlusIcon className="w-4 h-4 text-zinc-600 dark:text-zinc-400" />
|
||||
</button>
|
||||
</div>
|
||||
<p className="mt-2 text-xs text-zinc-500 dark:text-zinc-400">
|
||||
Incrementos de 1 GB
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-2">
|
||||
Recursos <span className="text-xs text-zinc-500">(separados por vírgula)</span>
|
||||
</label>
|
||||
<textarea
|
||||
name="features"
|
||||
value={formData.features}
|
||||
onChange={handleChange}
|
||||
placeholder="CRM, ERP, Projetos, Helpdesk, Pagamentos"
|
||||
rows={3}
|
||||
className="w-full px-3 py-2.5 border border-zinc-200 dark:border-zinc-700 rounded-lg bg-white dark:bg-zinc-900 text-zinc-900 dark:text-white placeholder-zinc-400 focus:outline-none focus:ring-2 focus:ring-[var(--brand-color)] focus:border-transparent resize-none transition-all"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-2">
|
||||
Diferenciais <span className="text-xs text-zinc-500">(separados por vírgula)</span>
|
||||
</label>
|
||||
<textarea
|
||||
name="differentiators"
|
||||
value={formData.differentiators}
|
||||
onChange={handleChange}
|
||||
placeholder="Suporte prioritário, Gerente dedicado, API avançada"
|
||||
rows={3}
|
||||
className="w-full px-3 py-2.5 border border-zinc-200 dark:border-zinc-700 rounded-lg bg-white dark:bg-zinc-900 text-zinc-900 dark:text-white placeholder-zinc-400 focus:outline-none focus:ring-2 focus:ring-[var(--brand-color)] focus:border-transparent resize-none transition-all"
|
||||
/>
|
||||
</div>
|
||||
</Tab.Panel>
|
||||
</Tab.Panels>
|
||||
</Tab.Group>
|
||||
|
||||
{/* Buttons */}
|
||||
<div className="mt-6 pt-4 border-t border-zinc-200 dark:border-zinc-700 flex gap-3">
|
||||
<button
|
||||
type="submit"
|
||||
disabled={loading}
|
||||
className="flex-1 px-4 py-2.5 bg-blue-600 hover:bg-blue-700 disabled:bg-blue-400 disabled:cursor-not-allowed text-white font-medium rounded-lg transition-colors"
|
||||
>
|
||||
{loading ? 'Criando...' : 'Criar Plano'}
|
||||
</button>
|
||||
<div className="mt-8 pt-6 border-t border-zinc-200 dark:border-zinc-700 flex gap-3">
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleClose}
|
||||
disabled={loading}
|
||||
className="flex-1 px-4 py-2.5 border border-zinc-300 dark:border-zinc-600 text-zinc-700 dark:text-zinc-300 font-medium rounded-lg hover:bg-zinc-50 dark:hover:bg-zinc-800 disabled:opacity-50 disabled:cursor-not-allowed transition-colors"
|
||||
className="flex-1 px-4 py-2.5 border border-zinc-200 dark:border-zinc-700 text-zinc-700 dark:text-zinc-300 font-medium rounded-lg hover:bg-zinc-50 dark:hover:bg-zinc-800 disabled:opacity-50 disabled:cursor-not-allowed transition-colors"
|
||||
>
|
||||
Cancelar
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={loading}
|
||||
className="flex-1 px-4 py-2.5 text-white font-medium rounded-lg disabled:opacity-50 disabled:cursor-not-allowed transition-all shadow-lg hover:shadow-xl"
|
||||
style={{ background: loading ? '#999' : 'var(--gradient)' }}
|
||||
>
|
||||
{loading ? 'Criando...' : 'Criar Plano'}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
797
front-end-dash.aggios.app/components/plans/EditPlanModal.tsx
Normal file
797
front-end-dash.aggios.app/components/plans/EditPlanModal.tsx
Normal file
@@ -0,0 +1,797 @@
|
||||
"use client";
|
||||
|
||||
import { Fragment, useEffect, useState } from 'react';
|
||||
import { Dialog, Transition } from '@headlessui/react';
|
||||
import Tabs, { TabItem } from '@/components/ui/Tabs';
|
||||
import { useToast } from '@/components/layout/ToastContext';
|
||||
import {
|
||||
XMarkIcon,
|
||||
SparklesIcon,
|
||||
UserGroupIcon,
|
||||
ChartBarIcon,
|
||||
FolderIcon,
|
||||
LifebuoyIcon,
|
||||
CreditCardIcon,
|
||||
DocumentTextIcon,
|
||||
ArchiveBoxIcon,
|
||||
ShareIcon,
|
||||
DocumentIcon,
|
||||
CurrencyDollarIcon,
|
||||
SparklesIcon as SparklesIconOutline,
|
||||
CubeIcon,
|
||||
PlusIcon,
|
||||
MinusIcon
|
||||
} from '@heroicons/react/24/outline';
|
||||
|
||||
const SOLUTION_ICONS: Record<string, React.ComponentType<{ className?: string }>> = {
|
||||
'crm': UserGroupIcon,
|
||||
'erp': ChartBarIcon,
|
||||
'projetos': FolderIcon,
|
||||
'helpdesk': LifebuoyIcon,
|
||||
'pagamentos': CreditCardIcon,
|
||||
'contratos': DocumentTextIcon,
|
||||
'documentos': ArchiveBoxIcon,
|
||||
'social': ShareIcon,
|
||||
};
|
||||
|
||||
interface Solution {
|
||||
id: string;
|
||||
name: string;
|
||||
slug: string;
|
||||
description?: string;
|
||||
is_active: boolean;
|
||||
}
|
||||
|
||||
interface EditPlanModalProps {
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
planId: string | null;
|
||||
onSuccess: () => void;
|
||||
}
|
||||
|
||||
export default function EditPlanModal({ isOpen, onClose, planId, onSuccess }: EditPlanModalProps) {
|
||||
const toast = useToast();
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [loadingSolutions, setLoadingSolutions] = useState(true);
|
||||
const [allSolutions, setAllSolutions] = useState<Solution[]>([]);
|
||||
const [selectedSolutions, setSelectedSolutions] = useState<string[]>([]);
|
||||
|
||||
const [formData, setFormData] = useState({
|
||||
name: '',
|
||||
slug: '',
|
||||
description: '',
|
||||
monthly_price: '',
|
||||
annual_price: '',
|
||||
min_users: 1,
|
||||
max_users: 30,
|
||||
storage_gb: 1,
|
||||
discount_months: 2,
|
||||
features: '' as string | string[],
|
||||
differentiators: '' as string | string[],
|
||||
is_active: true,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (isOpen && planId) {
|
||||
fetchPlanData();
|
||||
fetchAllSolutions();
|
||||
fetchPlanSolutions();
|
||||
}
|
||||
}, [isOpen, planId]);
|
||||
|
||||
const fetchPlanData = async () => {
|
||||
if (!planId) return;
|
||||
|
||||
try {
|
||||
setLoading(true);
|
||||
const response = await fetch(`/api/admin/plans/${planId}`, {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${localStorage.getItem('token')}`,
|
||||
},
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
const plan = data.plan;
|
||||
|
||||
console.log('Plano carregado:', plan);
|
||||
console.log('Solu\u00e7\u00f5es do plano:', plan.solutions);
|
||||
|
||||
setFormData({
|
||||
name: plan.name || '',
|
||||
slug: plan.slug || '',
|
||||
description: plan.description || '',
|
||||
monthly_price: plan.monthly_price || '',
|
||||
annual_price: plan.annual_price || '',
|
||||
min_users: plan.min_users || 1,
|
||||
max_users: plan.max_users || 30,
|
||||
storage_gb: plan.storage_gb || 1,
|
||||
discount_months: plan.discount_months || 2,
|
||||
features: Array.isArray(plan.features) ? plan.features.join(', ') : (plan.features || ''),
|
||||
differentiators: Array.isArray(plan.differentiators) ? plan.differentiators.join(', ') : (plan.differentiators || ''),
|
||||
is_active: plan.is_active ?? true,
|
||||
});
|
||||
|
||||
const solutionIds = plan.solutions?.map((s: Solution) => s.id) || [];
|
||||
console.log('IDs das solu\u00e7\u00f5es extra\u00eddos:', solutionIds);
|
||||
// Não seta aqui, vamos buscar via API separada
|
||||
// setSelectedSolutions(solutionIds);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching plan:', error);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const fetchPlanSolutions = async () => {
|
||||
if (!planId) return;
|
||||
|
||||
try {
|
||||
console.log('Buscando soluções do plano...');
|
||||
const response = await fetch(`/api/admin/plans/${planId}/solutions`, {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${localStorage.getItem('token')}`,
|
||||
},
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
console.log('Soluções do plano (via API separada):', data);
|
||||
const solutionIds = data.solutions?.map((s: Solution) => s.id) || [];
|
||||
console.log('IDs extraídos:', solutionIds);
|
||||
setSelectedSolutions(solutionIds);
|
||||
} else {
|
||||
console.error('Erro ao buscar soluções:', response.status);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching plan solutions:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const fetchAllSolutions = async () => {
|
||||
try {
|
||||
setLoadingSolutions(true);
|
||||
const response = await fetch('/api/admin/solutions', {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${localStorage.getItem('token')}`,
|
||||
},
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
console.log('Todas as solu\u00e7\u00f5es dispon\u00edveis:', data.solutions);
|
||||
setAllSolutions(data.solutions || []);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching solutions:', error);
|
||||
} finally {
|
||||
setLoadingSolutions(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (!planId) return;
|
||||
|
||||
setSaving(true);
|
||||
|
||||
try {
|
||||
const planPayload = {
|
||||
name: formData.name,
|
||||
slug: formData.slug,
|
||||
description: formData.description,
|
||||
monthly_price: parseFloat(String(formData.monthly_price)) || 0,
|
||||
annual_price: parseFloat(String(formData.annual_price)) || 0,
|
||||
min_users: parseInt(String(formData.min_users)) || 1,
|
||||
max_users: parseInt(String(formData.max_users)) || 30,
|
||||
storage_gb: parseInt(String(formData.storage_gb)) || 1,
|
||||
is_active: formData.is_active,
|
||||
features: typeof formData.features === 'string'
|
||||
? formData.features.split(',').map(f => f.trim()).filter(f => f)
|
||||
: formData.features,
|
||||
differentiators: typeof formData.differentiators === 'string'
|
||||
? formData.differentiators.split(',').map(d => d.trim()).filter(d => d)
|
||||
: formData.differentiators,
|
||||
};
|
||||
|
||||
console.log('Atualizando plano:', planPayload);
|
||||
|
||||
// Atualizar dados do plano
|
||||
const response = await fetch(`/api/admin/plans/${planId}`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${localStorage.getItem('token')}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(planPayload),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json();
|
||||
console.error('Erro ao atualizar plano:', errorData);
|
||||
toast.error('Erro ao atualizar plano', errorData.message || 'Verifique os dados');
|
||||
setSaving(false);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('Plano atualizado, atualizando soluções:', selectedSolutions);
|
||||
|
||||
// Atualizar soluções associadas
|
||||
const solutionsResponse = await fetch(`/api/admin/plans/${planId}/solutions`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${localStorage.getItem('token')}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ solution_ids: selectedSolutions }),
|
||||
});
|
||||
|
||||
if (!solutionsResponse.ok) {
|
||||
const errorData = await solutionsResponse.json();
|
||||
console.error('Erro ao atualizar soluções:', errorData);
|
||||
toast.error('Erro ao atualizar soluções', errorData.message || 'Verifique os dados');
|
||||
setSaving(false);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('Soluções atualizadas com sucesso');
|
||||
toast.success('Plano atualizado!', 'Todas as alterações foram salvas com sucesso');
|
||||
onSuccess();
|
||||
onClose();
|
||||
} catch (error) {
|
||||
console.error('Error updating plan:', error);
|
||||
toast.error('Erro ao atualizar plano', 'Ocorreu um erro inesperado');
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
|
||||
const { name, value, type } = e.target;
|
||||
|
||||
if (type === 'checkbox') {
|
||||
const checked = (e.target as HTMLInputElement).checked;
|
||||
setFormData(prev => ({ ...prev, [name]: checked }));
|
||||
} else if (type === 'number') {
|
||||
const numValue = parseFloat(value) || 0;
|
||||
setFormData(prev => {
|
||||
const newData = {
|
||||
...prev,
|
||||
[name]: numValue,
|
||||
};
|
||||
|
||||
// Calcular preço anual automaticamente quando mensal ou discount_months muda
|
||||
if ((name === 'monthly_price' || name === 'discount_months')) {
|
||||
const monthlyPrice = name === 'monthly_price' ? numValue : parseFloat(String(prev.monthly_price)) || 0;
|
||||
const discountMonths = name === 'discount_months' ? numValue : prev.discount_months;
|
||||
|
||||
if (monthlyPrice > 0 && discountMonths >= 0) {
|
||||
// Calcula: (12 meses - meses de desconto) * preço mensal
|
||||
const monthsToPay = Math.max(0, 12 - discountMonths);
|
||||
const annualWithDiscount = (monthlyPrice * monthsToPay).toFixed(2);
|
||||
newData.annual_price = annualWithDiscount;
|
||||
}
|
||||
}
|
||||
|
||||
return newData;
|
||||
});
|
||||
} else {
|
||||
setFormData(prev => ({ ...prev, [name]: value }));
|
||||
}
|
||||
};
|
||||
|
||||
const incrementValue = (field: 'min_users' | 'max_users' | 'storage_gb' | 'discount_months', step: number = 1) => {
|
||||
setFormData(prev => {
|
||||
const newValue = prev[field] + step;
|
||||
const newData = {
|
||||
...prev,
|
||||
[field]: newValue,
|
||||
};
|
||||
|
||||
// Recalcular preço anual se mudou discount_months
|
||||
if (field === 'discount_months') {
|
||||
const monthlyPrice = parseFloat(String(prev.monthly_price)) || 0;
|
||||
if (monthlyPrice > 0 && newValue >= 0) {
|
||||
const monthsToPay = Math.max(0, 12 - newValue);
|
||||
newData.annual_price = (monthlyPrice * monthsToPay).toFixed(2);
|
||||
}
|
||||
}
|
||||
|
||||
return newData;
|
||||
});
|
||||
};
|
||||
|
||||
const decrementValue = (field: 'min_users' | 'max_users' | 'storage_gb' | 'discount_months', step: number = 1, min: number = 0) => {
|
||||
setFormData(prev => {
|
||||
const newValue = Math.max(min, prev[field] - step);
|
||||
const newData = {
|
||||
...prev,
|
||||
[field]: newValue,
|
||||
};
|
||||
|
||||
// Recalcular preço anual se mudou discount_months
|
||||
if (field === 'discount_months') {
|
||||
const monthlyPrice = parseFloat(String(prev.monthly_price)) || 0;
|
||||
if (monthlyPrice > 0 && newValue >= 0) {
|
||||
const monthsToPay = Math.max(0, 12 - newValue);
|
||||
newData.annual_price = (monthlyPrice * monthsToPay).toFixed(2);
|
||||
}
|
||||
}
|
||||
|
||||
return newData;
|
||||
});
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
if (!saving) {
|
||||
onClose();
|
||||
}
|
||||
};
|
||||
|
||||
// Configuração dos tabs
|
||||
const tabsConfig: TabItem[] = [
|
||||
{
|
||||
name: 'Dados Básicos',
|
||||
icon: DocumentIcon,
|
||||
content: (
|
||||
<div className="space-y-4">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-2">
|
||||
Nome do Plano *
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
name="name"
|
||||
value={formData.name}
|
||||
onChange={handleInputChange}
|
||||
required
|
||||
className="w-full px-3 py-2.5 border border-zinc-200 dark:border-zinc-700 rounded-lg bg-white dark:bg-zinc-900 text-zinc-900 dark:text-white placeholder-zinc-400 focus:outline-none focus:ring-2 focus:ring-[var(--brand-color)] focus:border-transparent transition-all"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-2">
|
||||
Slug *
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
name="slug"
|
||||
value={formData.slug}
|
||||
onChange={handleInputChange}
|
||||
required
|
||||
className="w-full px-3 py-2.5 border border-zinc-200 dark:border-zinc-700 rounded-lg bg-white dark:bg-zinc-900 text-zinc-900 dark:text-white placeholder-zinc-400 focus:outline-none focus:ring-2 focus:ring-[var(--brand-color)] focus:border-transparent transition-all"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-2">
|
||||
Descrição
|
||||
</label>
|
||||
<textarea
|
||||
name="description"
|
||||
value={formData.description}
|
||||
onChange={handleInputChange}
|
||||
rows={3}
|
||||
className="w-full px-3 py-2.5 border border-zinc-200 dark:border-zinc-700 rounded-lg bg-white dark:bg-zinc-900 text-zinc-900 dark:text-white placeholder-zinc-400 focus:outline-none focus:ring-2 focus:ring-[var(--brand-color)] focus:border-transparent transition-all resize-none"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="pt-2">
|
||||
<label className="flex items-center gap-3">
|
||||
<input
|
||||
type="checkbox"
|
||||
name="is_active"
|
||||
checked={formData.is_active}
|
||||
onChange={handleInputChange}
|
||||
className="h-5 w-5 rounded border-zinc-300 dark:border-zinc-600 text-[var(--brand-color)] focus:ring-[var(--brand-color)] dark:bg-zinc-800 cursor-pointer"
|
||||
style={{ accentColor: 'var(--brand-color)' }}
|
||||
/>
|
||||
<span className="text-sm font-medium text-zinc-900 dark:text-white">Plano Ativo</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
},
|
||||
{
|
||||
name: 'Limites e Preços',
|
||||
icon: CurrencyDollarIcon,
|
||||
content: (
|
||||
<div className="space-y-4">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-2">
|
||||
Mínimo de Usuários
|
||||
</label>
|
||||
<div className="flex items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => decrementValue('min_users', 1, 1)}
|
||||
className="p-2 rounded-lg border border-zinc-200 dark:border-zinc-700 hover:bg-zinc-50 dark:hover:bg-zinc-800 transition-colors"
|
||||
>
|
||||
<MinusIcon className="w-4 h-4 text-zinc-600 dark:text-zinc-400" />
|
||||
</button>
|
||||
<input
|
||||
type="number"
|
||||
name="min_users"
|
||||
value={formData.min_users}
|
||||
onChange={handleInputChange}
|
||||
min="1"
|
||||
className="flex-1 px-3 py-2.5 border border-zinc-200 dark:border-zinc-700 rounded-lg bg-white dark:bg-zinc-900 text-zinc-900 dark:text-white text-center font-medium focus:outline-none focus:ring-2 focus:ring-[var(--brand-color)] focus:border-transparent transition-all"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => incrementValue('min_users', 1)}
|
||||
className="p-2 rounded-lg border border-zinc-200 dark:border-zinc-700 hover:bg-zinc-50 dark:hover:bg-zinc-800 transition-colors"
|
||||
>
|
||||
<PlusIcon className="w-4 h-4 text-zinc-600 dark:text-zinc-400" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-2">
|
||||
Máximo de Usuários
|
||||
</label>
|
||||
<div className="flex items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => decrementValue('max_users', 5, -1)}
|
||||
className="p-2 rounded-lg border border-zinc-200 dark:border-zinc-700 hover:bg-zinc-50 dark:hover:bg-zinc-800 transition-colors"
|
||||
>
|
||||
<MinusIcon className="w-4 h-4 text-zinc-600 dark:text-zinc-400" />
|
||||
</button>
|
||||
<input
|
||||
type="number"
|
||||
name="max_users"
|
||||
value={formData.max_users}
|
||||
onChange={handleInputChange}
|
||||
className="flex-1 px-3 py-2.5 border border-zinc-200 dark:border-zinc-700 rounded-lg bg-white dark:bg-zinc-900 text-zinc-900 dark:text-white text-center font-medium focus:outline-none focus:ring-2 focus:ring-[var(--brand-color)] focus:border-transparent transition-all"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => incrementValue('max_users', 5)}
|
||||
className="p-2 rounded-lg border border-zinc-200 dark:border-zinc-700 hover:bg-zinc-50 dark:hover:bg-zinc-800 transition-colors"
|
||||
>
|
||||
<PlusIcon className="w-4 h-4 text-zinc-600 dark:text-zinc-400" />
|
||||
</button>
|
||||
</div>
|
||||
<p className="mt-2 text-xs text-zinc-500 dark:text-zinc-400">
|
||||
Use -1 para ilimitado
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-2">
|
||||
Armazenamento (GB)
|
||||
</label>
|
||||
<div className="flex items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => decrementValue('storage_gb', 1, 1)}
|
||||
className="p-2 rounded-lg border border-zinc-200 dark:border-zinc-700 hover:bg-zinc-50 dark:hover:bg-zinc-800 transition-colors"
|
||||
>
|
||||
<MinusIcon className="w-4 h-4 text-zinc-600 dark:text-zinc-400" />
|
||||
</button>
|
||||
<input
|
||||
type="number"
|
||||
name="storage_gb"
|
||||
value={formData.storage_gb}
|
||||
onChange={handleInputChange}
|
||||
min="1"
|
||||
className="flex-1 px-3 py-2.5 border border-zinc-200 dark:border-zinc-700 rounded-lg bg-white dark:bg-zinc-900 text-zinc-900 dark:text-white text-center font-medium focus:outline-none focus:ring-2 focus:ring-[var(--brand-color)] focus:border-transparent transition-all"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => incrementValue('storage_gb', 1)}
|
||||
className="p-2 rounded-lg border border-zinc-200 dark:border-zinc-700 hover:bg-zinc-50 dark:hover:bg-zinc-800 transition-colors"
|
||||
>
|
||||
<PlusIcon className="w-4 h-4 text-zinc-600 dark:text-zinc-400" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-2">
|
||||
Preço Mensal (R$) *
|
||||
</label>
|
||||
<div className="relative">
|
||||
<span className="absolute left-3 top-1/2 -translate-y-1/2 text-zinc-500">R$</span>
|
||||
<input
|
||||
type="number"
|
||||
name="monthly_price"
|
||||
value={formData.monthly_price}
|
||||
onChange={handleInputChange}
|
||||
placeholder="199.99"
|
||||
step="0.01"
|
||||
className="w-full pl-10 pr-3 py-2.5 border border-zinc-200 dark:border-zinc-700 rounded-lg bg-white dark:bg-zinc-900 text-zinc-900 dark:text-white placeholder-zinc-400 focus:outline-none focus:ring-2 focus:ring-[var(--brand-color)] focus:border-transparent transition-all"
|
||||
/>
|
||||
</div>
|
||||
<p className="mt-2 text-xs text-zinc-500 dark:text-zinc-400">
|
||||
Digite o preço mensal
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-2">
|
||||
Meses Grátis (Desconto)
|
||||
</label>
|
||||
<div className="flex items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => decrementValue('discount_months', 1, 0)}
|
||||
className="p-2 rounded-lg border border-zinc-200 dark:border-zinc-700 hover:bg-zinc-50 dark:hover:bg-zinc-800 transition-colors"
|
||||
>
|
||||
<MinusIcon className="w-4 h-4 text-zinc-600 dark:text-zinc-400" />
|
||||
</button>
|
||||
<input
|
||||
type="number"
|
||||
name="discount_months"
|
||||
value={formData.discount_months}
|
||||
onChange={handleInputChange}
|
||||
min="0"
|
||||
max="11"
|
||||
className="flex-1 px-3 py-2.5 border border-zinc-200 dark:border-zinc-700 rounded-lg bg-white dark:bg-zinc-900 text-zinc-900 dark:text-white text-center font-medium focus:outline-none focus:ring-2 focus:ring-[var(--brand-color)] focus:border-transparent transition-all"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => incrementValue('discount_months', 1)}
|
||||
className="p-2 rounded-lg border border-zinc-200 dark:border-zinc-700 hover:bg-zinc-50 dark:hover:bg-zinc-800 transition-colors"
|
||||
>
|
||||
<PlusIcon className="w-4 h-4 text-zinc-600 dark:text-zinc-400" />
|
||||
</button>
|
||||
</div>
|
||||
<p className="mt-2 text-xs text-zinc-500 dark:text-zinc-400">
|
||||
Ex: 2 = cliente paga 10 meses
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-2">
|
||||
Preço Anual (R$) <span className="text-emerald-600 dark:text-emerald-400">✓ Auto</span>
|
||||
</label>
|
||||
<div className="relative">
|
||||
<span className="absolute left-3 top-1/2 -translate-y-1/2 text-zinc-500">R$</span>
|
||||
<input
|
||||
type="number"
|
||||
name="annual_price"
|
||||
value={formData.annual_price}
|
||||
onChange={handleInputChange}
|
||||
placeholder="Calculado automaticamente"
|
||||
step="0.01"
|
||||
className="w-full pl-10 pr-3 py-2.5 border border-zinc-200 dark:border-zinc-700 rounded-lg bg-white dark:bg-zinc-900 text-zinc-900 dark:text-white placeholder-zinc-400 focus:outline-none focus:ring-2 focus:ring-[var(--brand-color)] focus:border-transparent transition-all"
|
||||
/>
|
||||
</div>
|
||||
<p className="mt-2 text-xs text-emerald-600 dark:text-emerald-400">
|
||||
✓ Calculado automaticamente com base no preço mensal e desconto
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
},
|
||||
{
|
||||
name: 'Recursos',
|
||||
icon: SparklesIconOutline,
|
||||
content: (
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-2">
|
||||
Recursos <span className="text-xs font-normal text-zinc-500 dark:text-zinc-400">(separados por vírgula)</span>
|
||||
</label>
|
||||
<textarea
|
||||
name="features"
|
||||
value={typeof formData.features === 'string' ? formData.features : formData.features.join(', ')}
|
||||
onChange={handleInputChange}
|
||||
rows={4}
|
||||
placeholder="Ex: Gestão de leads, Relatórios avançados, API ilimitada"
|
||||
className="w-full px-3 py-2.5 border border-zinc-200 dark:border-zinc-700 rounded-lg bg-white dark:bg-zinc-900 text-zinc-900 dark:text-white placeholder-zinc-400 focus:outline-none focus:ring-2 focus:ring-[var(--brand-color)] focus:border-transparent transition-all resize-none"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-2">
|
||||
Diferenciais <span className="text-xs font-normal text-zinc-500 dark:text-zinc-400">(separados por vírgula)</span>
|
||||
</label>
|
||||
<textarea
|
||||
name="differentiators"
|
||||
value={typeof formData.differentiators === 'string' ? formData.differentiators : formData.differentiators.join(', ')}
|
||||
onChange={handleInputChange}
|
||||
rows={4}
|
||||
placeholder="Ex: Suporte prioritário, Treinamento personalizado, Consultoria mensal"
|
||||
className="w-full px-3 py-2.5 border border-zinc-200 dark:border-zinc-700 rounded-lg bg-white dark:bg-zinc-900 text-zinc-900 dark:text-white placeholder-zinc-400 focus:outline-none focus:ring-2 focus:ring-[var(--brand-color)] focus:border-transparent transition-all resize-none"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
},
|
||||
{
|
||||
name: 'Soluções',
|
||||
icon: CubeIcon,
|
||||
content: (
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<h3 className="text-base font-medium text-zinc-900 dark:text-white mb-1">
|
||||
Soluções Incluídas
|
||||
</h3>
|
||||
<p className="text-sm text-zinc-600 dark:text-zinc-400 mb-4">
|
||||
Selecione quais soluções estarão disponíveis para agências com este plano
|
||||
</p>
|
||||
|
||||
{loadingSolutions ? (
|
||||
<div className="flex items-center justify-center py-8">
|
||||
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-[var(--brand-color)]"></div>
|
||||
</div>
|
||||
) : allSolutions.length === 0 ? (
|
||||
<div className="rounded-lg bg-zinc-50 dark:bg-zinc-800 p-6 text-center">
|
||||
<p className="text-sm text-zinc-600 dark:text-zinc-400">
|
||||
Nenhuma solução cadastrada ainda.
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-3">
|
||||
{allSolutions.map((solution) => (
|
||||
<label
|
||||
key={solution.id}
|
||||
className={`flex items-start gap-3 p-3 rounded-lg border-2 cursor-pointer transition-all ${selectedSolutions.includes(solution.id)
|
||||
? 'bg-zinc-50 dark:bg-zinc-800/50'
|
||||
: 'border-zinc-200 dark:border-zinc-700 hover:border-zinc-300 dark:hover:border-zinc-600'
|
||||
}`}
|
||||
style={{
|
||||
borderColor: selectedSolutions.includes(solution.id) ? 'var(--brand-color)' : undefined
|
||||
}}
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={selectedSolutions.includes(solution.id)}
|
||||
onChange={(e) => {
|
||||
if (e.target.checked) {
|
||||
setSelectedSolutions([...selectedSolutions, solution.id]);
|
||||
} else {
|
||||
setSelectedSolutions(selectedSolutions.filter(id => id !== solution.id));
|
||||
}
|
||||
}}
|
||||
className="mt-0.5 h-4 w-4 rounded border-zinc-300 dark:border-zinc-600 text-[var(--brand-color)] focus:ring-[var(--brand-color)] dark:bg-zinc-800 cursor-pointer"
|
||||
style={{ accentColor: 'var(--brand-color)' }}
|
||||
/>
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="w-7 h-7 rounded-full flex items-center justify-center flex-shrink-0" style={{ background: 'var(--gradient)' }}>
|
||||
{(() => {
|
||||
const Icon = SOLUTION_ICONS[solution.slug] || FolderIcon;
|
||||
return <Icon className="w-3.5 h-3.5 text-white" />;
|
||||
})()}
|
||||
</div>
|
||||
<span className="text-sm font-medium text-zinc-900 dark:text-white truncate">
|
||||
{solution.name}
|
||||
</span>
|
||||
{!solution.is_active && (
|
||||
<span className="px-1.5 py-0.5 text-xs font-medium bg-zinc-200 dark:bg-zinc-700 text-zinc-600 dark:text-zinc-400 rounded">
|
||||
Inativo
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
{solution.description && (
|
||||
<p className="mt-1 text-xs text-zinc-600 dark:text-zinc-400 line-clamp-1">
|
||||
{solution.description}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{selectedSolutions.length > 0 && (
|
||||
<div className="mt-4 p-3 rounded-lg border" style={{
|
||||
backgroundColor: 'var(--brand-color-light, rgba(59, 130, 246, 0.1))',
|
||||
borderColor: 'var(--brand-color)'
|
||||
}}>
|
||||
<p className="text-sm font-medium" style={{ color: 'var(--brand-color)' }}>
|
||||
{selectedSolutions.length} {selectedSolutions.length === 1 ? 'solução selecionada' : 'soluções selecionadas'}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
];
|
||||
|
||||
return (
|
||||
<Transition appear show={isOpen} as={Fragment}>
|
||||
<Dialog as="div" className="relative z-50" onClose={handleClose}>
|
||||
<Transition.Child
|
||||
as={Fragment}
|
||||
enter="ease-out duration-300"
|
||||
enterFrom="opacity-0"
|
||||
enterTo="opacity-100"
|
||||
leave="ease-in duration-200"
|
||||
leaveFrom="opacity-100"
|
||||
leaveTo="opacity-0"
|
||||
>
|
||||
<div className="fixed inset-0 bg-zinc-900/40 backdrop-blur-sm" />
|
||||
</Transition.Child>
|
||||
|
||||
<div className="fixed inset-0 overflow-y-auto">
|
||||
<div className="flex min-h-full items-center justify-center p-4">
|
||||
<Transition.Child
|
||||
as={Fragment}
|
||||
enter="ease-out duration-300"
|
||||
enterFrom="opacity-0 scale-95"
|
||||
enterTo="opacity-100 scale-100"
|
||||
leave="ease-in duration-200"
|
||||
leaveFrom="opacity-100 scale-100"
|
||||
leaveTo="opacity-0 scale-95"
|
||||
>
|
||||
<Dialog.Panel className="w-full max-w-4xl transform overflow-hidden rounded-2xl bg-white dark:bg-zinc-900 text-left align-middle shadow-xl transition-all border border-zinc-200 dark:border-zinc-800">
|
||||
{loading ? (
|
||||
<div className="flex items-center justify-center p-12">
|
||||
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-[var(--brand-color)]"></div>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
{/* Header */}
|
||||
<div className="flex items-start justify-between p-6 border-b border-zinc-200 dark:border-zinc-700">
|
||||
<div className="flex items-start gap-4">
|
||||
<div
|
||||
className="flex h-12 w-12 flex-shrink-0 items-center justify-center rounded-xl shadow-lg"
|
||||
style={{ background: 'var(--gradient)' }}
|
||||
>
|
||||
<SparklesIcon className="h-6 w-6 text-white" />
|
||||
</div>
|
||||
<div>
|
||||
<Dialog.Title className="text-xl font-bold text-zinc-900 dark:text-white">
|
||||
Editar Plano
|
||||
</Dialog.Title>
|
||||
<p className="mt-1 text-sm text-zinc-500 dark:text-zinc-400">
|
||||
Atualize as informações e soluções do plano
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
className="rounded-lg p-1.5 text-zinc-400 hover:text-zinc-600 dark:hover:text-zinc-300 hover:bg-zinc-100 dark:hover:bg-zinc-800 transition-colors"
|
||||
onClick={handleClose}
|
||||
disabled={saving}
|
||||
>
|
||||
<XMarkIcon className="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Form com Tabs */}
|
||||
<form onSubmit={handleSubmit} className="p-6">
|
||||
<Tabs tabs={tabsConfig} />
|
||||
|
||||
{/* Footer com botões */}
|
||||
<div className="mt-6 pt-6 border-t border-zinc-200 dark:border-zinc-700 flex gap-3">
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleClose}
|
||||
disabled={saving}
|
||||
className="flex-1 px-4 py-2.5 border border-zinc-200 dark:border-zinc-700 text-zinc-700 dark:text-zinc-300 font-medium rounded-lg hover:bg-zinc-50 dark:hover:bg-zinc-800 disabled:opacity-50 disabled:cursor-not-allowed transition-colors"
|
||||
>
|
||||
Cancelar
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={saving}
|
||||
className="flex-1 px-4 py-2.5 text-white font-medium rounded-lg transition-all disabled:opacity-50 disabled:cursor-not-allowed shadow-sm hover:shadow-md"
|
||||
style={{ backgroundImage: 'var(--gradient)' }}
|
||||
>
|
||||
{saving ? 'Salvando...' : 'Salvar Alterações'}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</>
|
||||
)}
|
||||
</Dialog.Panel>
|
||||
</Transition.Child>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog>
|
||||
</Transition>
|
||||
);
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
"use client";
|
||||
|
||||
import { ButtonHTMLAttributes, forwardRef } from "react";
|
||||
import { ButtonHTMLAttributes, forwardRef, ReactNode } from "react";
|
||||
|
||||
interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
||||
variant?: "primary" | "secondary" | "outline" | "ghost";
|
||||
size?: "sm" | "md" | "lg";
|
||||
isLoading?: boolean;
|
||||
leftIcon?: string;
|
||||
rightIcon?: string;
|
||||
leftIcon?: string | ReactNode;
|
||||
rightIcon?: string | ReactNode;
|
||||
}
|
||||
|
||||
const Button = forwardRef<HTMLButtonElement, ButtonProps>(
|
||||
@@ -55,11 +55,19 @@ const Button = forwardRef<HTMLButtonElement, ButtonProps>(
|
||||
<i className="ri-loader-4-line animate-spin mr-2 text-[20px]" />
|
||||
)}
|
||||
{!isLoading && leftIcon && (
|
||||
<i className={`${leftIcon} mr-2 text-[20px]`} />
|
||||
typeof leftIcon === 'string' ? (
|
||||
<i className={`${leftIcon} mr-2 text-[20px]`} />
|
||||
) : (
|
||||
<div className="w-5 h-5 mr-2">{leftIcon}</div>
|
||||
)
|
||||
)}
|
||||
{children}
|
||||
{!isLoading && rightIcon && (
|
||||
<i className={`${rightIcon} ml-2 text-[20px]`} />
|
||||
typeof rightIcon === 'string' ? (
|
||||
<i className={`${rightIcon} ml-2 text-[20px]`} />
|
||||
) : (
|
||||
<div className="w-5 h-5 ml-2">{rightIcon}</div>
|
||||
)
|
||||
)}
|
||||
</button>
|
||||
);
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
"use client";
|
||||
|
||||
import { InputHTMLAttributes, forwardRef, useState, ReactNode } from "react";
|
||||
import { EyeIcon, EyeSlashIcon } from '@heroicons/react/24/outline';
|
||||
|
||||
interface InputProps extends InputHTMLAttributes<HTMLInputElement> {
|
||||
label?: string;
|
||||
error?: string;
|
||||
helperText?: ReactNode;
|
||||
leftIcon?: string;
|
||||
rightIcon?: string;
|
||||
leftIcon?: string | ReactNode;
|
||||
rightIcon?: string | ReactNode;
|
||||
onRightIconClick?: () => void;
|
||||
}
|
||||
|
||||
@@ -41,9 +42,13 @@ const Input = forwardRef<HTMLInputElement, InputProps>(
|
||||
)}
|
||||
<div className="relative">
|
||||
{leftIcon && (
|
||||
<i
|
||||
className={`${leftIcon} absolute left-3.5 top-1/2 -translate-y-1/2 text-[#7D7D7D] dark:text-gray-400 text-[20px]`}
|
||||
/>
|
||||
<div className="absolute left-3.5 top-1/2 -translate-y-1/2 text-zinc-400 dark:text-gray-400">
|
||||
{typeof leftIcon === 'string' ? (
|
||||
<i className={`${leftIcon} text-[20px]`} />
|
||||
) : (
|
||||
<div className="w-5 h-5">{leftIcon}</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
<input
|
||||
ref={ref}
|
||||
@@ -69,21 +74,23 @@ const Input = forwardRef<HTMLInputElement, InputProps>(
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowPassword(!showPassword)}
|
||||
className="absolute right-3.5 top-1/2 -translate-y-1/2 text-zinc-500 hover:text-zinc-900 transition-colors cursor-pointer"
|
||||
className="absolute right-3.5 top-1/2 -translate-y-1/2 text-zinc-500 hover:text-zinc-900 dark:text-gray-400 dark:hover:text-white transition-colors cursor-pointer"
|
||||
>
|
||||
<i
|
||||
className={`${showPassword ? "ri-eye-off-line" : "ri-eye-line"} text-[20px]`}
|
||||
/>
|
||||
{showPassword ? (
|
||||
<EyeSlashIcon className="w-5 h-5" />
|
||||
) : (
|
||||
<EyeIcon className="w-5 h-5" />
|
||||
)}
|
||||
</button>
|
||||
)}
|
||||
{!isPassword && rightIcon && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={onRightIconClick}
|
||||
className="absolute right-3.5 top-1/2 -translate-y-1/2 text-zinc-500 hover:text-zinc-900 transition-colors cursor-pointer"
|
||||
>
|
||||
<i className={`${rightIcon} text-[20px]`} />
|
||||
</button>
|
||||
<div className="absolute right-3.5 top-1/2 -translate-y-1/2 text-zinc-400 dark:text-gray-400">
|
||||
{typeof rightIcon === 'string' ? (
|
||||
<i className={`${rightIcon} text-[20px]`} />
|
||||
) : (
|
||||
<div className="w-5 h-5">{rightIcon}</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{error && (
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { SelectHTMLAttributes, forwardRef, useState, useRef, useEffect } from "react";
|
||||
import { SelectHTMLAttributes, forwardRef, useState, useRef, useEffect, ReactNode } from "react";
|
||||
|
||||
interface SelectOption {
|
||||
value: string;
|
||||
@@ -11,7 +11,7 @@ interface SearchableSelectProps extends Omit<SelectHTMLAttributes<HTMLSelectElem
|
||||
label?: string;
|
||||
error?: string;
|
||||
helperText?: string;
|
||||
leftIcon?: string;
|
||||
leftIcon?: string | ReactNode;
|
||||
options: SelectOption[];
|
||||
placeholder?: string;
|
||||
onChange?: (value: string) => void;
|
||||
@@ -115,9 +115,13 @@ const SearchableSelect = forwardRef<HTMLSelectElement, SearchableSelectProps>(
|
||||
|
||||
<div ref={containerRef} className="relative">
|
||||
{leftIcon && (
|
||||
<i
|
||||
className={`${leftIcon} absolute left-3.5 top-1/2 -translate-y-1/2 text-zinc-500 dark:text-zinc-400 text-[20px] pointer-events-none z-10`}
|
||||
/>
|
||||
<div className="absolute left-3.5 top-1/2 -translate-y-1/2 text-zinc-400 dark:text-gray-400 pointer-events-none z-10">
|
||||
{typeof leftIcon === 'string' ? (
|
||||
<i className={`${leftIcon} text-[20px]`} />
|
||||
) : (
|
||||
<div className="w-5 h-5">{leftIcon}</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Custom trigger */}
|
||||
|
||||
102
front-end-dash.aggios.app/components/ui/Tabs.tsx
Normal file
102
front-end-dash.aggios.app/components/ui/Tabs.tsx
Normal file
@@ -0,0 +1,102 @@
|
||||
'use client';
|
||||
|
||||
import { Tab } from '@headlessui/react';
|
||||
import { ReactNode } from 'react';
|
||||
|
||||
function classNames(...classes: string[]) {
|
||||
return classes.filter(Boolean).join(' ');
|
||||
}
|
||||
|
||||
export interface TabItem {
|
||||
name: string;
|
||||
icon?: React.ComponentType<{ className?: string }>;
|
||||
content: ReactNode;
|
||||
}
|
||||
|
||||
interface TabsProps {
|
||||
tabs: TabItem[];
|
||||
defaultIndex?: number;
|
||||
onChange?: (index: number) => void;
|
||||
variant?: 'card' | 'modal'; // Novo: variante para diferentes contextos
|
||||
}
|
||||
|
||||
export default function Tabs({ tabs, defaultIndex = 0, onChange, variant = 'card' }: TabsProps) {
|
||||
if (variant === 'modal') {
|
||||
// Versão para modais - sem card wrapper
|
||||
return (
|
||||
<Tab.Group defaultIndex={defaultIndex} onChange={onChange}>
|
||||
<Tab.List className="flex border-b border-zinc-200 dark:border-zinc-700 px-6">
|
||||
{tabs.map((tab) => (
|
||||
<Tab
|
||||
key={tab.name}
|
||||
className={({ selected }) =>
|
||||
classNames(
|
||||
'px-4 py-3 text-sm font-medium border-b-2 transition-colors focus:outline-none whitespace-nowrap',
|
||||
selected
|
||||
? 'border-[var(--brand-color)] text-[var(--brand-color)]'
|
||||
: 'border-transparent text-zinc-500 hover:text-zinc-700 dark:hover:text-zinc-300'
|
||||
)
|
||||
}
|
||||
>
|
||||
<div className="flex items-center justify-center gap-2">
|
||||
{tab.icon && <tab.icon className="w-4 h-4 flex-shrink-0" />}
|
||||
{tab.name}
|
||||
</div>
|
||||
</Tab>
|
||||
))}
|
||||
</Tab.List>
|
||||
|
||||
<Tab.Panels className="p-6">
|
||||
{tabs.map((tab, idx) => (
|
||||
<Tab.Panel
|
||||
key={idx}
|
||||
className="focus:outline-none"
|
||||
>
|
||||
{tab.content}
|
||||
</Tab.Panel>
|
||||
))}
|
||||
</Tab.Panels>
|
||||
</Tab.Group>
|
||||
);
|
||||
}
|
||||
|
||||
// Versão padrão para páginas - com card wrapper
|
||||
return (
|
||||
<Tab.Group defaultIndex={defaultIndex} onChange={onChange}>
|
||||
<div className="bg-white dark:bg-zinc-900 rounded-xl border border-zinc-200 dark:border-zinc-800 overflow-hidden">
|
||||
<Tab.List className="flex space-x-1 rounded-t-xl bg-zinc-100 dark:bg-zinc-800/50 p-1 overflow-x-auto scrollbar-hide">
|
||||
{tabs.map((tab) => (
|
||||
<Tab
|
||||
key={tab.name}
|
||||
className={({ selected }) =>
|
||||
classNames(
|
||||
'w-full rounded-lg py-2 sm:py-2.5 px-3 sm:px-4 text-xs sm:text-sm font-medium leading-5 transition-all duration-200 whitespace-nowrap',
|
||||
'focus:outline-none',
|
||||
selected
|
||||
? 'bg-white dark:bg-zinc-800 text-zinc-900 dark:text-white shadow'
|
||||
: 'text-zinc-500 hover:bg-white/[0.12] hover:text-zinc-700 dark:hover:text-zinc-300'
|
||||
)
|
||||
}
|
||||
>
|
||||
<div className="flex items-center justify-center gap-1.5 sm:gap-2">
|
||||
{tab.icon && <tab.icon className="w-3.5 h-3.5 sm:w-4 sm:h-4 flex-shrink-0" />}
|
||||
{tab.name}
|
||||
</div>
|
||||
</Tab>
|
||||
))}
|
||||
</Tab.List>
|
||||
|
||||
<Tab.Panels className="p-4 sm:p-6">
|
||||
{tabs.map((tab, idx) => (
|
||||
<Tab.Panel
|
||||
key={idx}
|
||||
className="focus:outline-none"
|
||||
>
|
||||
{tab.content}
|
||||
</Tab.Panel>
|
||||
))}
|
||||
</Tab.Panels>
|
||||
</div>
|
||||
</Tab.Group>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user