Bladeren bron

list all pwd of user

amenpunk 3 jaren geleden
bovenliggende
commit
dc6829b610
3 gewijzigde bestanden met toevoegingen van 45 en 66 verwijderingen
  1. 26 44
      src/Components/Password/Rows.js
  2. 16 19
      src/Pages/ContrasV2.jsx
  3. 3 3
      src/Pages/Puestos.jsx

+ 26 - 44
src/Components/Password/Rows.js

@@ -1,57 +1,27 @@
-export const encabezados = [
+export const Encabezados = [
     {
-        id: 'pass',
+        name: 'pass',
         numeric: false,
         disablePadding: true,
-        label: 'Contraseñas',
+        label: 'Contraseña',
     },
     {
-        id: 'nivel',
-        numeric: true,
-        disablePadding: false,
-        label: 'Nivel',
-    },
-    {
-        id: 'puesto',
-        numeric: true,
-        disablePadding: false,
-        label: 'Puesto',
-    },
-    {
-        id: 'cui',
-        numeric: true,
-        disablePadding: false,
-        label: 'CUI/Cedula',
-    },
-    {
-        id: 'uso',
-        numeric: true,
-        disablePadding: false,
-        label: 'En uso?',
-    },
-    {
-        id: 'picture',
-        numeric: true,
-        disablePadding: false,
-        label: 'Fotografía',
-    },
-    {
-        id: 'cv',
-        numeric: true,
-        disablePadding: false,
-        label: 'Con CV',
+        name: 'name',
+        numeric: false,
+        disablePadding: true,
+        label: 'Nombre',
     },
     {
-        id: 'estado',
-        numeric: true,
-        disablePadding: false,
-        label: 'Envido?',
+        name: 'apell',
+        numeric: false,
+        disablePadding: true,
+        label: 'Apellido',
     },
     {
-        id: 'ope',
+        name: 'mail',
         numeric: false,
-        disablePadding: false,
-        label: 'Operacion',
+        disablePadding: true,
+        label: 'Correo',
     },
 ]
 
@@ -76,3 +46,15 @@ export const departamentos = [
     "Guatemala",
     "Guatemala",
 ]
+
+export function Build(pwds){
+    return pwds.map( pwd => {
+        let { candidato: user } = pwd
+        return {
+            pass : pwd.pwd,
+            name: user.nombre,
+            apell: user.apellidos,
+            mail: user.mail,
+        }
+    })
+}

+ 16 - 19
src/Pages/ContrasV2.jsx

@@ -3,27 +3,24 @@ import { default as CustomToolbar } from '../Components/Password/CustomToolbar';
 import { Paper, Box, ThemeProvider } from '@mui/material';
 
 import MUIDataTable from "mui-datatables";
-import { encabezados } from '../Components/Password/Rows';
+import { Encabezados, Build } from '../Components/Password/Rows';
 import { TableStyle, TextLabels } from '../Components/Password/TableStyle'
 
+import { useQuery } from 'react-query';
+import { Service } from '../Utils/HTTP.js'
+import useAuth from '../Auth/useAuth'
+
 export function Contrasv2() {
 
-    const columns = encabezados.map(({ label }) => label); //["Name", "Company", "City", "State"];
-
-    const data = [
-        ["Joe James", "Test Corp", "Yonkers", "NY"],
-        ["John Walsh", "Test Corp", "Hartford", "CT"],
-        ["Bob Herm", "Test Corp", "Tampa", "FL"],
-        ["James Houston", "Test Corp", "Dallas", "TX"],
-        ["Joe James", "Test Corp", "Yonkers", "NY"],
-        ["John Walsh", "Test Corp", "Hartford", "CT"],
-        ["Bob Herm", "Test Corp", "Tampa", "FL"],
-        ["James Houston", "Test Corp", "Dallas", "TX"],
-        ["Joe James", "Test Corp", "Yonkers", "NY"],
-        ["John Walsh", "Test Corp", "Hartford", "CT"],
-        ["Bob Herm", "Test Corp", "Tampa", "FL"],
-        ["James Houston", "Test Corp", "Dallas", "TX"],
-    ];
+    const auth = useAuth();
+    const token = React.useRef(auth.getToken())
+
+    const getAllPwd = async () => {
+        let rest = new Service('/contrasenia/getallbyidUsr');
+        return await rest.getQuery(token.current)
+    }
+
+    const { data : { data : result} } = useQuery('passwords', getAllPwd );
 
     const options = {
         filterType: 'checkbox',
@@ -45,8 +42,8 @@ export function Contrasv2() {
                             <MUIDataTable
                                 sx={{ '& MuiPaper': { elevation: 0, boxShadow: 'none', color: "red" } }}
                                 title={"Contraseñas"}
-                                data={data}
-                                columns={columns}
+                                data={Build(result)}
+                                columns={Encabezados}
                                 options={options}
                             />
                         </ThemeProvider>

+ 3 - 3
src/Pages/Puestos.jsx

@@ -1,4 +1,4 @@
-import React, { useState, useCallback} from 'react';
+import React, { useState, useCallback, useRef} from 'react';
 import { Row, Col } from 'react-bootstrap'
 import { Toaster } from 'react-hot-toast';
 
@@ -32,12 +32,12 @@ import { useQuery } from 'react-query';
 export function Puestos() {
 
     const auth = useAuth();
-    const token = auth.getToken();
+    const token = useRef(auth.getToken());
     const [page, setPage] = useState(1);
 
     const getAll = async () => {
         let rest = new Service("/plaza/getall")
-        let response =  await rest.getQuery(token); 
+        let response =  await rest.getQuery(token.current); 
         return response;
     }