Candidatos.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import React, { useState, useEffect } from 'react';
  2. import UpdateIcon from '@mui/icons-material/Update';
  3. import { Typography, Pagination, Stack, } from '@mui/material'
  4. import { Row, Col } from 'react-bootstrap';
  5. import { Candidato, Preview } from './Candidato'
  6. function Divide(arregloOriginal) {
  7. const LONGITUD_PEDAZOS = 7;
  8. let arregloDeArreglos = [];
  9. for (let i = 0; i < arregloOriginal.length; i += LONGITUD_PEDAZOS) {
  10. let pedazo = arregloOriginal.slice(i, i + LONGITUD_PEDAZOS);
  11. arregloDeArreglos.push(pedazo);
  12. }
  13. return arregloDeArreglos
  14. }
  15. function fromBase64(text) {
  16. try {
  17. return atob(text)
  18. } catch (_e) {
  19. return text
  20. }
  21. }
  22. export default function Candidatos(props) {
  23. let { passwords, setPassword, setVisible} = props;
  24. const [page, setPage] = useState(1);
  25. const [users, setUser] = useState([]);
  26. const changePage = (_, value) => {
  27. let page_numer = value;
  28. Divide(users)
  29. setPage(page_numer);
  30. };
  31. useEffect(() => {
  32. let list = passwords.map(pwd => {
  33. let { candidatospwds } = pwd
  34. return {
  35. password: fromBase64(pwd.pwd),
  36. candidatos: candidatospwds,
  37. pwd: pwd.pwd,
  38. plz: pwd.plaza_id
  39. }
  40. })
  41. let divided = Divide(list);
  42. setUser(divided)
  43. // setPassword({})
  44. // setVisible(true)
  45. }, [passwords])
  46. return (
  47. <div className="body_historial">
  48. <div className="header_historial">
  49. <UpdateIcon style={{ color: "white", fontSize: 25, margin: 0, marginRight: 15, marginLeft: 15 }} />
  50. <p className="titlie_main">HISTORIAL DE ACCESO DE CANDIDATOS</p>
  51. </div>
  52. <div className="content_historial">
  53. <p>Últimos candidatos que han ingresado al sistema:</p>
  54. <div className="cabeceras">
  55. <Row>
  56. <div className="col20 "><p>Contraseña</p></div>
  57. <div className="col20 "><p></p> </div>
  58. <div className="col20 "><p>Usuarios</p> </div>
  59. <div className="col20 "><p>Asignaciones</p> </div>
  60. </Row>
  61. </div>
  62. {
  63. users.length
  64. ? users[page - 1].map((user, i) => (
  65. <Candidato
  66. onClick={() => {
  67. setPassword(user)
  68. setVisible(true)
  69. }}
  70. key={i}
  71. user={user}
  72. />
  73. ))
  74. : <Preview style={{ paddingTop: 10 }} lenght={10} />
  75. }
  76. <Row style={{ padding: 5 }}>
  77. <Col>
  78. <Stack style={{ display: 'flex', flexDirection: 'row', alignItems: 'baseline', justifyContent: 'space-evenly' }} spacing={2}>
  79. <Typography style={{ paddingTop: 15, paddingRight: 10 }}>Página: {page}</Typography>
  80. <Pagination
  81. siblingCount={1}
  82. boundaryCount={1}
  83. shape='rounded'
  84. count={users.length}
  85. page={page}
  86. onChange={changePage}
  87. />
  88. </Stack>
  89. </Col>
  90. </Row>
  91. </div>
  92. </div>
  93. )
  94. }