diff --git a/app/bulkcreate/page.js b/app/bulkcreate/page.js new file mode 100644 index 0000000..356be79 --- /dev/null +++ b/app/bulkcreate/page.js @@ -0,0 +1,113 @@ +"use client" +import React, { useState } from 'react'; +import Box from '@mui/material/Box'; +import TextField from '@mui/material/TextField'; +import Button from '@mui/material/Button'; +import Navbar from '@/components/Navbar'; +import AuthService from '@/services/AuthService'; +import { Snackbar, Alert } from '@mui/material'; + +const BulkAddUsers = () => { + const [users, setUsers] = useState([ + { name: '', email: '', cellphone: '', password: '' }, + ]); + const [snackbarOpen, setSnackbarOpen] = useState(false); + const [message, setMessage] = useState(''); + + const handleUserChange = (index, event) => { + const newUsers = [...users]; + newUsers[index][event.target.name] = event.target.value; + setUsers(newUsers); + }; + + const addUser = () => { + setUsers([...users, { name: '', email: '', cellphone: '', password: '' }]); + }; + + const removeUser = (index) => { + const newUsers = [...users]; + newUsers.splice(index, 1); + setUsers(newUsers); + }; + + const handleSubmit = async (e) => { + e.preventDefault(); + try { + const payload = { + usersList: users + }; + const token = localStorage.getItem('token'); + const response = await AuthService.bulkCreate(payload, token); + + if(response){ + console.log(response.data); + setMessage(response.data); + setSnackbarOpen(true) + } + + } + catch(e){ + console.error(e); + setMessage("hubo un error"); + setSnackbarOpen(true) + }; + }; + + const handleCloseSnackbar = (event, reason) => { + if (reason === 'clickaway') { + return; + } + setSnackbarOpen(false); + }; + + return ( +
+ + + + {users.map((user, index) => ( + + handleUserChange(index, e)} + /> + handleUserChange(index, e)} + /> + handleUserChange(index, e)} + /> + handleUserChange(index, e)} + /> + {index === users.length - 1 && ( + + )} + {users.length > 1 && ( + + )} + + ))} + + + + ); +}; + +export default BulkAddUsers; \ No newline at end of file diff --git a/app/findUsers/page.js b/app/findUsers/page.js new file mode 100644 index 0000000..58c7789 --- /dev/null +++ b/app/findUsers/page.js @@ -0,0 +1,92 @@ +"use client" +import React, { useState, useEffect } from 'react'; +import { TextField, Button, Stack, Container, Switch, Table, TableBody, TableCell, TableHead, TableRow } from '@mui/material'; +import Navbar from '@/components/Navbar'; +import AuthService from "../../services/AuthService"; +import { useRouter } from 'next/navigation'; + + const UserFilters = ({ onFilter }) => { + const router = useRouter(); + +const [query, setQuery] = useState({ name : '', loginBeforeDate: '', loginAfterDate: '', status : true }); + +const handleInputChange = (e) => { + const { name, value } = e.target; + setQuery((prevQuery) => ({ + ...prevQuery, + [name]: value, + })); +} + + const [users, setUsers] = useState([]); + useEffect(() => { + const user = JSON.parse(localStorage.getItem('user')); + if(!user){ + router.push('/login'); + } + + getUser(); + +}, []); + +const getUser = async (query) => { + const token = localStorage.getItem('token'); + const data = await AuthService.getfindUsers(query, token); + setUsers(data); + console.log(data); +} + +const handleSubmit = (event) => { + event.preventDefault(); + getUser(query); + console.log(users); +}; +console.log(query); +return ( +
+ + + + + + + + { + const updatedQuery = { ...query, status: e.target.checked }; + setQuery(updatedQuery); + }} + inputProps={{ 'aria-label': 'Status' }} + /> + + + + + + Nombre + Email + Estado + Última Sesión + + + + { + users.map((user) => ( + + {user.name} + {user.email} + {user.status ? 'ACTIVO' : 'CERRADO'} + {new Date(user.updatedAt).toLocaleDateString('es-ES')} + + )) + } + +
+
+
+ +); +}; + +export default UserFilters; \ No newline at end of file diff --git a/components/Navbar.js b/components/Navbar.js index c281d22..2664a78 100644 --- a/components/Navbar.js +++ b/components/Navbar.js @@ -3,6 +3,7 @@ import './Navbar.css'; import Button from '@mui/material/Button'; import AuthService from '@/services/AuthService'; import { useRouter } from 'next/navigation'; +import Stack from '@mui/material/Stack'; const Navbar = () => { const router = useRouter(); @@ -22,9 +23,13 @@ const Navbar = () => { return (
-
+ {user?.name} -
+ + + + +