feature/T2026-05-031 crear usuarios
This commit is contained in:
11
src/App.jsx
11
src/App.jsx
@@ -14,6 +14,7 @@ import LandingAnimated from './pages/LandingAnimated';
|
|||||||
import Expedientes from './pages/Expedientes';
|
import Expedientes from './pages/Expedientes';
|
||||||
import Organization from './pages/Organization';
|
import Organization from './pages/Organization';
|
||||||
import Users from './pages/Users';
|
import Users from './pages/Users';
|
||||||
|
import UserForm from './pages/UserForm';
|
||||||
import Reports from './pages/Reports';
|
import Reports from './pages/Reports';
|
||||||
import Settings from './pages/Settings';
|
import Settings from './pages/Settings';
|
||||||
import Importers from './pages/Importers';
|
import Importers from './pages/Importers';
|
||||||
@@ -76,6 +77,16 @@ function AppContent() {
|
|||||||
<Users />
|
<Users />
|
||||||
</RequireAuth>
|
</RequireAuth>
|
||||||
} />
|
} />
|
||||||
|
<Route path="/users/new" element={
|
||||||
|
<RequireAuth>
|
||||||
|
<UserForm />
|
||||||
|
</RequireAuth>
|
||||||
|
} />
|
||||||
|
<Route path="/users/:id/edit" element={
|
||||||
|
<RequireAuth>
|
||||||
|
<UserForm />
|
||||||
|
</RequireAuth>
|
||||||
|
} />
|
||||||
<Route path="/reports" element={
|
<Route path="/reports" element={
|
||||||
<RequireAuth>
|
<RequireAuth>
|
||||||
<Reports />
|
<Reports />
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { fetchUsers, createUser, updateUser, deleteUser, getCurrentUser } from '../api/users.ts';
|
import { fetchUsers, createUser, updateUser, deleteUser, getCurrentUser } from '../api/users.ts';
|
||||||
import { useNotification } from '../context/NotificationContext';
|
import { useNotification } from '../context/NotificationContext';
|
||||||
|
|
||||||
@@ -47,6 +48,7 @@ export default function Users() {
|
|||||||
const [currentPage, setCurrentPage] = useState(1);
|
const [currentPage, setCurrentPage] = useState(1);
|
||||||
const [itemsPerPage, setItemsPerPage] = useState(10);
|
const [itemsPerPage, setItemsPerPage] = useState(10);
|
||||||
const { showMessage } = useNotification();
|
const { showMessage } = useNotification();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
// Estados para validación de contraseña
|
// Estados para validación de contraseña
|
||||||
const [passwordValidation, setPasswordValidation] = useState({
|
const [passwordValidation, setPasswordValidation] = useState({
|
||||||
@@ -552,44 +554,17 @@ export default function Users() {
|
|||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col sm:flex-row gap-2 sm:gap-3">
|
<div className="flex flex-col sm:flex-row gap-2 sm:gap-3">
|
||||||
<button
|
<button
|
||||||
onClick={() => { setShowCreateModal(true); setCreateType('agente'); }}
|
onClick={() => navigate('/users/new')}
|
||||||
type="button"
|
type="button"
|
||||||
className="inline-flex items-center justify-center px-4 py-2 border border-transparent rounded-lg shadow-sm text-sm font-medium text-white bg-gradient-to-r from-blue-600 to-blue-700 hover:from-blue-700 hover:to-blue-800 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 transition-all duration-200 transform hover:scale-105"
|
className="inline-flex items-center justify-center px-4 py-2 border border-transparent rounded-lg shadow-sm text-sm font-medium text-white bg-gradient-to-r from-blue-600 to-blue-700 hover:from-blue-700 hover:to-blue-800 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 transition-all duration-200 transform hover:scale-105"
|
||||||
>
|
>
|
||||||
<svg className="-ml-1 mr-2 h-5 w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
<svg className="-ml-1 mr-2 h-5 w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
|
||||||
</svg>
|
</svg>
|
||||||
<span className="hidden sm:inline">Nuevo Agente</span>
|
<span className="hidden sm:inline">Nuevo Usuario</span>
|
||||||
<span className="sm:hidden">Agente</span>
|
<span className="sm:hidden">Usuario</span>
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
onClick={async () => {
|
|
||||||
setCreateType('importador');
|
|
||||||
// Fetch importadores RFC
|
|
||||||
try {
|
|
||||||
const res = await fetch(`${import.meta.env.VITE_EFC_API_URL}/customs/importadores/`, { method: 'GET', headers: { 'Authorization': `Bearer ${localStorage.getItem('access')}` } });
|
|
||||||
const data = await res.json();
|
|
||||||
if (Array.isArray(data)) {
|
|
||||||
setImportadores(data);
|
|
||||||
} else {
|
|
||||||
setImportadores([]);
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
setImportadores([]);
|
|
||||||
}
|
|
||||||
setShowCreateModal(true);
|
|
||||||
}}
|
|
||||||
type="button"
|
|
||||||
className="inline-flex items-center justify-center px-4 py-2 border border-transparent rounded-lg shadow-sm text-sm font-medium text-white bg-gradient-to-r from-green-600 to-green-700 hover:from-green-700 hover:to-green-800 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500 transition-all duration-200 transform hover:scale-105"
|
|
||||||
>
|
|
||||||
<svg className="-ml-1 mr-2 h-5 w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
||||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
|
|
||||||
</svg>
|
|
||||||
<span className="hidden sm:inline">Nuevo Importador</span>
|
|
||||||
<span className="sm:hidden">Importador</span>
|
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
{/* Modal para crear usuario (agente o importador) eliminado */}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Filtros avanzados */}
|
{/* Filtros avanzados */}
|
||||||
@@ -777,6 +752,16 @@ export default function Users() {
|
|||||||
</td>
|
</td>
|
||||||
<td className="px-6 py-4 whitespace-nowrap text-center">
|
<td className="px-6 py-4 whitespace-nowrap text-center">
|
||||||
<div className="flex justify-center space-x-2">
|
<div className="flex justify-center space-x-2">
|
||||||
|
<button
|
||||||
|
onClick={() => navigate(`/users/${user.id}/edit`)}
|
||||||
|
className="inline-flex items-center px-3 py-1.5 border border-blue-300 shadow-sm text-xs font-medium rounded-lg text-blue-700 bg-white hover:bg-blue-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 transition-all duration-200 transform hover:scale-105"
|
||||||
|
title="Editar usuario"
|
||||||
|
>
|
||||||
|
<svg className="w-4 h-4 mr-1.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z" />
|
||||||
|
</svg>
|
||||||
|
Editar
|
||||||
|
</button>
|
||||||
<button
|
<button
|
||||||
onClick={() => { setShowDeleteModal(true); setUserToDelete(user); }}
|
onClick={() => { setShowDeleteModal(true); setUserToDelete(user); }}
|
||||||
disabled={user.username === localStorage.getItem('username')}
|
disabled={user.username === localStorage.getItem('username')}
|
||||||
@@ -874,6 +859,16 @@ export default function Users() {
|
|||||||
<div className="text-xs text-gray-500 mt-1">ID: {user.id}</div>
|
<div className="text-xs text-gray-500 mt-1">ID: {user.id}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<button
|
||||||
|
onClick={() => navigate(`/users/${user.id}/edit`)}
|
||||||
|
className="inline-flex items-center px-3 py-2 border border-blue-300 shadow-sm text-xs font-medium rounded-lg text-blue-700 bg-white hover:bg-blue-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 transition-all duration-200"
|
||||||
|
title="Editar usuario"
|
||||||
|
>
|
||||||
|
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z" />
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
<button
|
<button
|
||||||
onClick={() => { setShowDeleteModal(true); setUserToDelete(user); }}
|
onClick={() => { setShowDeleteModal(true); setUserToDelete(user); }}
|
||||||
disabled={user.username === localStorage.getItem('username')}
|
disabled={user.username === localStorage.getItem('username')}
|
||||||
@@ -885,6 +880,7 @@ export default function Users() {
|
|||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<div className="grid grid-cols-2 gap-4 text-xs">
|
<div className="grid grid-cols-2 gap-4 text-xs">
|
||||||
<div>
|
<div>
|
||||||
<span className="font-medium text-gray-500">Estado:</span>
|
<span className="font-medium text-gray-500">Estado:</span>
|
||||||
|
|||||||
Reference in New Issue
Block a user