feat: replace mock system with real backend, RBAC, and Teams management
All checks were successful
Build and Deploy / build-and-push (push) Successful in 2m3s

- Implemented real JWT authentication and persistent user sessions
- Replaced all hardcoded mock data with dynamic MySQL-backed API calls
- Created new 'Times' (Teams) dashboard with performance metrics
- Renamed 'Equipe' to 'Membros' and centralized team management
- Added Role-Based Access Control (RBAC) for Admin/Manager/Agent roles
- Implemented secure invite-only member creation and password setup flow
- Enhanced Login with password visibility and real-time validation
- Added safe delete confirmation modal and custom Toast notifications
This commit is contained in:
Cauê Faleiros
2026-03-02 10:26:20 -03:00
parent 76b919d857
commit b7e73fce3d
19 changed files with 1707 additions and 553 deletions

View File

@@ -1,56 +1,62 @@
import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { Hexagon, Lock, Mail, ArrowRight, Loader2, Info } from 'lucide-react';
import { getUsers } from '../services/dataService';
import { useNavigate, Link } from 'react-router-dom';
import { Hexagon, Lock, Mail, ArrowRight, Loader2, Eye, EyeOff, AlertCircle } from 'lucide-react';
import { login } from '../services/dataService';
export const Login: React.FC = () => {
const navigate = useNavigate();
const [isLoading, setIsLoading] = useState(false);
const [email, setEmail] = useState('lidya@fasto.com');
const [password, setPassword] = useState('password');
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [showPassword, setShowPassword] = useState(false);
const [error, setError] = useState('');
const [emailError, setEmailError] = useState('');
const validateEmail = (value: string) => {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!value) {
setEmailError('');
} else if (!emailRegex.test(value)) {
setEmailError('Por favor, insira um e-mail válido.');
} else {
setEmailError('');
}
};
const handleEmailChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const value = e.target.value;
setEmail(value);
validateEmail(value);
};
const handleLogin = async (e: React.FormEvent) => {
e.preventDefault();
if (emailError) return;
setIsLoading(true);
setError('');
try {
// Fetch all users to find match (simplified auth for demo)
const users = await getUsers('all');
const user = users.find(u => u.email.toLowerCase() === email.toLowerCase());
if (user) {
localStorage.setItem('ctms_user_id', user.id);
localStorage.setItem('ctms_tenant_id', user.tenant_id || '');
setIsLoading(false);
if (user.role === 'super_admin') {
navigate('/super-admin');
} else {
navigate('/');
}
const data = await login({ email, password });
localStorage.setItem('ctms_token', data.token);
localStorage.setItem('ctms_user_id', data.user.id);
localStorage.setItem('ctms_tenant_id', data.user.tenant_id || '');
setIsLoading(false);
if (data.user.role === 'super_admin') {
navigate('/super-admin');
} else {
setIsLoading(false);
setError('Usuário não encontrado.');
navigate('/');
}
} catch (err) {
} catch (err: any) {
console.error("Login error:", err);
setIsLoading(false);
setError('Erro ao conectar ao servidor.');
setError(err.message || 'E-mail ou senha incorretos.');
}
};
const fillCredentials = (type: 'admin' | 'super') => {
if (type === 'admin') {
setEmail('lidya@fasto.com');
} else {
setEmail('root@system.com');
}
setPassword('password');
};
return (
<div className="min-h-screen bg-slate-50 flex flex-col justify-center py-12 sm:px-6 lg:px-8">
<div className="sm:mx-auto sm:w-full sm:max-w-md">
@@ -63,29 +69,11 @@ export const Login: React.FC = () => {
<h2 className="mt-6 text-center text-3xl font-bold tracking-tight text-slate-900">
Acesse sua conta
</h2>
<p className="mt-2 text-center text-sm text-slate-600">
Ou <a href="#" className="font-medium text-blue-600 hover:text-blue-500">inicie seu teste grátis de 14 dias</a>
</p>
</div>
<div className="mt-8 sm:mx-auto sm:w-full sm:max-w-md">
<div className="bg-white py-8 px-4 shadow-xl shadow-slate-200/50 rounded-2xl sm:px-10 border border-slate-100">
{/* Demo Helper - Remove in production */}
<div className="mb-6 p-3 bg-blue-50 border border-blue-100 rounded-lg text-xs text-blue-700">
<div className="flex items-center gap-2 font-bold mb-2">
<Info size={14} /> Dicas de Acesso (Demo):
</div>
<div className="flex gap-2">
<button onClick={() => fillCredentials('admin')} className="px-2 py-1 bg-white border border-blue-200 rounded shadow-sm hover:bg-blue-100 transition">
Admin da Empresa
</button>
<button onClick={() => fillCredentials('super')} className="px-2 py-1 bg-white border border-blue-200 rounded shadow-sm hover:bg-blue-100 transition">
Super Admin
</button>
</div>
</div>
<form className="space-y-6" onSubmit={handleLogin}>
<div>
<label htmlFor="email" className="block text-sm font-medium text-slate-700">
@@ -93,7 +81,7 @@ export const Login: React.FC = () => {
</label>
<div className="mt-1 relative rounded-md shadow-sm">
<div className="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
<Mail className="h-5 w-5 text-slate-400" />
<Mail className={`h-5 w-5 ${emailError ? 'text-red-400' : 'text-slate-400'}`} />
</div>
<input
id="email"
@@ -102,15 +90,24 @@ export const Login: React.FC = () => {
autoComplete="email"
required
value={email}
onChange={(e) => setEmail(e.target.value)}
className="block w-full pl-10 pr-3 py-2 border border-slate-300 rounded-lg leading-5 bg-white placeholder-slate-400 focus:outline-none focus:ring-2 focus:ring-blue-100 focus:border-blue-500 sm:text-sm transition-all"
onChange={handleEmailChange}
className={`block w-full pl-10 pr-3 py-2 border rounded-lg leading-5 bg-white placeholder-slate-400 focus:outline-none focus:ring-2 transition-all sm:text-sm ${
emailError
? 'border-red-300 focus:ring-red-100 focus:border-red-500'
: 'border-slate-300 focus:ring-blue-100 focus:border-blue-500'
}`}
placeholder="voce@empresa.com"
/>
</div>
{emailError && (
<p className="mt-1.5 text-xs text-red-500 font-medium flex items-center gap-1">
<AlertCircle size={12} /> {emailError}
</p>
)}
</div>
<div>
<label htmlFor="password" className="block text-sm font-medium text-slate-700">
<label htmlFor="password" senior-admin-password className="block text-sm font-medium text-slate-700">
Senha
</label>
<div className="mt-1 relative rounded-md shadow-sm">
@@ -120,19 +117,27 @@ export const Login: React.FC = () => {
<input
id="password"
name="password"
type="password"
type={showPassword ? 'text' : 'password'}
autoComplete="current-password"
required
value={password}
onChange={(e) => setPassword(e.target.value)}
className="block w-full pl-10 pr-3 py-2 border border-slate-300 rounded-lg leading-5 bg-white placeholder-slate-400 focus:outline-none focus:ring-2 focus:ring-blue-100 focus:border-blue-500 sm:text-sm transition-all"
className="block w-full pl-10 pr-10 py-2 border border-slate-300 rounded-lg leading-5 bg-white placeholder-slate-400 focus:outline-none focus:ring-2 focus:ring-blue-100 focus:border-blue-500 sm:text-sm transition-all"
placeholder="••••••••"
/>
<button
type="button"
onClick={() => setShowPassword(!showPassword)}
className="absolute inset-y-0 right-0 pr-3 flex items-center text-slate-400 hover:text-slate-600 transition-colors"
>
{showPassword ? <EyeOff size={18} /> : <Eye size={18} />}
</button>
</div>
</div>
{error && (
<div className="text-red-500 text-sm font-medium text-center">
<div className="bg-red-50 border border-red-100 text-red-600 px-4 py-3 rounded-xl text-sm font-medium flex items-center gap-2 animate-in fade-in slide-in-from-top-2 duration-200">
<AlertCircle size={18} className="shrink-0" />
{error}
</div>
)}
@@ -151,16 +156,16 @@ export const Login: React.FC = () => {
</div>
<div className="text-sm">
<a href="#" className="font-medium text-blue-600 hover:text-blue-500">
<Link to="/forgot-password" title="Recuperar Senha" className="font-medium text-blue-600 hover:text-blue-500">
Esqueceu sua senha?
</a>
</Link>
</div>
</div>
<div>
<button
type="submit"
disabled={isLoading}
disabled={isLoading || !!emailError || !email}
className="w-full flex justify-center items-center gap-2 py-2.5 px-4 border border-transparent rounded-lg shadow-sm text-sm font-semibold text-white bg-slate-900 hover:bg-slate-800 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-slate-900 disabled:opacity-70 disabled:cursor-not-allowed transition-all"
>
{isLoading ? (
@@ -183,7 +188,9 @@ export const Login: React.FC = () => {
<div className="w-full border-t border-slate-200" />
</div>
<div className="relative flex justify-center text-sm">
<span className="px-2 bg-white text-slate-500">Protegido por SSO Corporativo</span>
<span className="px-2 bg-white text-slate-500 text-xs">
Desenvolvido por <a href="https://blyzer.com.br" target="_blank" rel="noopener noreferrer" className="text-blue-600 hover:underline">Blyzer</a>
</span>
</div>
</div>
</div>
@@ -191,4 +198,4 @@ export const Login: React.FC = () => {
</div>
</div>
);
};
};