import React, { useState, useEffect } from 'react';
import {
Users, FileText, Wrench, LogOut, Plus, Trash2,
Lock, Unlock, Shield, Eye, FileUp, Globe, Link as LinkIcon, AlertCircle
} from 'lucide-react';
// --- INITIAL MOCK DATA ---
const INITIAL_USERS = [
{ id: 1, username: 'admin', password: 'admin', role: 'admin', active: true }
];
const App = () => {
// --- STATE ---
const [user, setUser] = useState(null);
const [users, setUsers] = useState(INITIAL_USERS);
const [notes, setNotes] = useState([]);
const [tools, setTools] = useState([]);
const [activeTab, setActiveTab] = useState('notes');
const [toast, setToast] = useState(null);
// --- SESSION MANAGEMENT ---
useEffect(() => {
// Check session expiration (1 hour)
const checkSession = setInterval(() => {
if (user && user.loginTime) {
const now = new Date().getTime();
const diff = now - user.loginTime;
if (diff > 3600000) { // 1 hour in ms
handleLogout();
showToast('Sessão expirada. Faça login novamente.');
}
}
}, 60000); // Check every minute
return () => clearInterval(checkSession);
}, [user]);
const showToast = (message) => {
setToast(message);
setTimeout(() => setToast(null), 3000);
};
const handleLogin = (username, password) => {
const foundUser = users.find(u => u.username === username && u.password === password);
if (foundUser) {
if (!foundUser.active) {
showToast('Sua conta está bloqueada.');
return;
}
setUser({ ...foundUser, loginTime: new Date().getTime() });
setActiveTab(foundUser.role === 'admin' ? 'users' : 'notes');
showToast(`Bem-vindo, ${username}!`);
} else {
showToast('Usuário ou senha inválidos.');
}
};
const handleLogout = () => {
setUser(null);
setActiveTab('notes');
};
if (!user) {
return ;
}
return (
{/* Toast Notification */}
{toast && (
)}
{/* Page Content with simple fade transition */}
{activeTab === 'users' && user.role === 'admin' && (
)}
{activeTab === 'notes' && (
)}
{activeTab === 'tools' && (
)}
);
};
// --- COMPONENTS ---
const LoginScreen = ({ onLogin, toast }) => {
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const onSubmit = (e) => {
e.preventDefault();
onLogin(username, password);
};
return (
{/* Decorative background elements */}
Painel da Equipe
{toast && (
{toast}
)}
);
};
const Sidebar = ({ role, activeTab, setActiveTab, onLogout }) => {
const navItems = [
...(role === 'admin' ? [{ id: 'users', icon: Users, label: 'Usuários' }] : []),
{ id: 'notes', icon: FileText, label: 'Anotações' },
{ id: 'tools', icon: Wrench, label: 'Ferramentas' },
];
return (
Workspace
);
};
const Header = ({ user, users, setUsers, showToast }) => {
const [showPasswordModal, setShowPasswordModal] = useState(false);
return (
);
};
// --- PANELS ---
const UsersPanel = ({ users, setUsers, showToast, currentUser }) => {
const [showAddModal, setShowAddModal] = useState(false);
const toggleUserStatus = (id) => {
if (id === currentUser.id) return showToast("Você não pode bloquear a si mesmo.");
setUsers(users.map(u => u.id === id ? { ...u, active: !u.active } : u));
showToast("Status do usuário atualizado.");
};
const deleteUser = (id) => {
if (id === currentUser.id) return showToast("Você não pode excluir a si mesmo.");
if(confirm("Tem certeza que deseja excluir este usuário?")) {
setUsers(users.filter(u => u.id !== id));
showToast("Usuário excluído.");
}
};
return (
Gerenciar Usuários
Crie, bloqueie ou remova acessos da equipe.
| Usuário |
Tipo |
Status |
Ações |
{users.map(u => (
{u.username.charAt(0).toUpperCase()}
{u.username}
|
{u.role === 'admin' ? 'Admin' : 'Usuário'}
|
{u.active ? : }
{u.active ? 'Ativo' : 'Bloqueado'}
|
|
))}
{showAddModal && (
setShowAddModal(false)}
onAdd={(newUser) => {
setUsers([...users, { ...newUser, id: Date.now(), active: true }]);
showToast("Usuário criado com sucesso!");
setShowAddModal(false);
}}
/>
)}
);
};
const NotesPanel = ({ notes, setNotes, user, showToast }) => {
const [showAddModal, setShowAddModal] = useState(false);
const visibleNotes = notes.filter(n =>
user.role === 'admin' || n.authorId === user.id || n.isPublic
);
const deleteNote = (id) => {
if(confirm("Excluir esta anotação?")) {
setNotes(notes.filter(n => n.id !== id));
showToast("Anotação excluída.");
}
};
return (
Anotações
Crie e compartilhe notas e arquivos com a equipe.
{visibleNotes.length === 0 ? (
Nenhuma anotação encontrada.
) : (
visibleNotes.map(note => (
{note.title}
{(user.role === 'admin' || note.authorId === user.id) && (
)}
{note.description}
{note.fileName && (
{note.fileName}
)}
{note.authorName.charAt(0).toUpperCase()}
{note.authorName}
{note.isPublic ? (
Público
) : (
Privado
)}
))
)}
{showAddModal && (
setShowAddModal(false)}
onAdd={(newNote) => {
setNotes([{...newNote, id: Date.now(), authorId: user.id, authorName: user.username, date: new Date().toISOString() }, ...notes]);
showToast("Anotação salva!");
setShowAddModal(false);
}}
/>
)}
);
};
const ToolsPanel = ({ tools, setTools, user, showToast }) => {
const [showAddModal, setShowAddModal] = useState(false);
const deleteTool = (id) => {
if(confirm("Excluir esta ferramenta?")) {
setTools(tools.filter(t => t.id !== id));
showToast("Ferramenta removida.");
}
};
return (
Ferramentas Rápidas
Atalhos e links úteis para a equipe.
{user.role === 'admin' && (
)}
{showAddModal && user.role === 'admin' && (
setShowAddModal(false)}
onAdd={(newTool) => {
setTools([...tools, { ...newTool, id: Date.now() }]);
showToast("Ferramenta adicionada!");
setShowAddModal(false);
}}
/>
)}
);
};
// --- MODALS ---
const ModalOverlay = ({ children, onClose }) => (
);
const AddUserModal = ({ onClose, onAdd }) => {
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const [role, setRole] = useState('user');
return (
);
};
const AddNoteModal = ({ onClose, onAdd }) => {
const [title, setTitle] = useState('');
const [description, setDescription] = useState('');
const [isPublic, setIsPublic] = useState(false);
const [file, setFile] = useState(null);
return (
);
};
const AddToolModal = ({ onClose, onAdd }) => {
const [name, setName] = useState('');
const [link, setLink] = useState('');
return (
);
};
const ChangePasswordModal = ({ user, users, setUsers, onClose, showToast }) => {
const [newPassword, setNewPassword] = useState('');
const handleSubmit = (e) => {
e.preventDefault();
setUsers(users.map(u => u.id === user.id ? { ...u, password: newPassword } : u));
showToast("Senha alterada com sucesso!");
onClose();
};
return (
);
};
export default App;