4 Commits 9e4f6d4da1 ... 1477f93710

Autor SHA1 Mensagem Data
  amenpunk 1477f93710 Puesto superior logic 1 ano atrás
  amenpunk 06a41cd137 pre save new puesto superior 1 ano atrás
  amenpunk 39fb32f322 find and add puesto superior 1 ano atrás
  amenpunk 04b853435f new apis fixes 1 ano atrás

+ 250 - 36
src/Components/Modal/AgregarManual.js

@@ -1,7 +1,6 @@
1 1
 import React, { memo } from 'react';
2 2
 import * as Yup from 'yup';
3 3
 import { useFormik, Form, FormikProvider } from 'formik';
4
-import { Dialog, DialogContent, DialogTitle, DialogActions } from '@mui/material'
5 4
 import toast from 'react-hot-toast';
6 5
 
7 6
 import { AdapterDateFns as DateFnsUtils } from '@mui/x-date-pickers/AdapterDateFns';
@@ -11,14 +10,50 @@ import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
11 10
 import {
12 11
   Button, Stack, TextField, MenuItem, FormControl, InputLabel, Select,
13 12
   Backdrop, CircularProgress, Box, Divider,
14
-  Tabs, Tab, FormGroup, Checkbox, FormControlLabel
13
+  Tabs, Tab, FormGroup, Checkbox, FormControlLabel,
14
+  Dialog, DialogContent, DialogTitle, DialogActions,
15
+  DialogContentText,
15 16
 } from '@mui/material';
16 17
 
18
+import Autocomplete, { createFilterOptions } from '@mui/material/Autocomplete';
19
+
17 20
 import { Service } from '../../Utils/HTTP';
18 21
 import { useQuery, useMutation, useQueryClient } from 'react-query';
19 22
 import { TabPanel } from './TabPanel'
20 23
 import { useSelector } from 'react-redux';
21 24
 
25
+const filter = createFilterOptions();
26
+
27
+async function getPuestoSuperior(puesto, auth) {
28
+  if (puesto.length < 2) return []
29
+  let rest = new Service(`/plaza/keypuestosup?keyword=${puesto}`)
30
+  let result = await rest.get(auth.token)
31
+  // console.log(result)
32
+  if (result?.data?.length > 0) {
33
+    result = result.data.map((item) => ({ 'title': item.nombre, id: item.id }))
34
+    return result;
35
+  }
36
+  return [];
37
+}
38
+
39
+async function savePuestoSuperior(input, auth) {
40
+  let rest = new Service("/plaza/puestosuperior")
41
+  let body = {
42
+    "active": 1,
43
+    "nombre": input.title,
44
+    "decription": input.id,
45
+    "modifyday": "2023-02-12T23:55:26.007",
46
+    "createday": "2023-02-12T23:55:26.007",
47
+    "id": null,
48
+    "descripction": input.id,
49
+    "modify_day": "2023-02-12T23:55:26.007",
50
+  }
51
+  let result = await rest.post(body, auth.token);
52
+  let { id, nombre } = result;
53
+  return { id, nombre }
54
+}
55
+
56
+
22 57
 function Manual(props) {
23 58
 
24 59
   const auth = useSelector((state) => state.token)
@@ -33,13 +68,14 @@ function Manual(props) {
33 68
     return await rest.getQuery(auth.token)
34 69
   }
35 70
 
71
+
36 72
   const { data } = useQuery('categories', getCategories);
37 73
   const { data: testsCatalog } = useQuery('tests', getTest);
38 74
   const queryClient = useQueryClient();
39 75
 
40 76
   const NewPlazaSchema = Yup.object().shape({
41 77
     nombrepuesto: Yup.string().required('El nombre es requerido').min(5, "El nombre del  puesto debe ser mayor a 5 caracteres").max(100),
42
-    puestosuperior: Yup.number("El puesto superior debe ser un número").required("El puesto es requerido"),
78
+    puestosuperior: Yup.number().required("El puesto superior es requerido"),
43 79
     aredepto: Yup.number().required('Escoge alguna área'),
44 80
     fecha: Yup.date("Ingresa una fecha válida"),
45 81
     notas: Yup.string("Ingresa una nota válida").min(5, "Ingresa una nota válida").max(150),
@@ -47,11 +83,47 @@ function Manual(props) {
47 83
   })
48 84
 
49 85
   const [departamento, setDepartamento] = React.useState('');
50
-  const [puestoSup, setPuestoSup] = React.useState('');
51 86
   const [open, setOpen] = React.useState(false);
52 87
   const [date, setDate] = React.useState(new Date());
53 88
   const [tab, setTab] = React.useState(0);
54 89
   const [checklist, setChecklist] = React.useState([]);
90
+  const [openDialog, toggleOpenDialog] = React.useState(false);
91
+  const [openSugg, setOpenSugg] = React.useState(false);
92
+  const [options, setOptions] = React.useState([]);
93
+  const [dialogValue, setDialogValueHook] = React.useState({
94
+    title: '',
95
+    id: '',
96
+  });
97
+
98
+  let setDialogValue = (value) => {
99
+    // console.log('llamada', value)
100
+    // setValues({...values, puestosuperior: value?.title })
101
+    setDialogValueHook(value)
102
+  }
103
+
104
+  const loading = openSugg && options.length === 0;
105
+
106
+  React.useEffect(() => {
107
+
108
+    let active = true;
109
+    if (!loading) {
110
+      return undefined;
111
+    }
112
+
113
+    (async () => {
114
+      let puestos = await getPuestoSuperior(dialogValue.title, auth)
115
+      if (active) {
116
+        setOptions(puestos);
117
+      }
118
+    })();
119
+
120
+    return () => {
121
+      active = false;
122
+    };
123
+
124
+  }, [loading, dialogValue, auth]);
125
+
126
+
55 127
 
56 128
   const handleClose = () => false
57 129
 
@@ -59,23 +131,69 @@ function Manual(props) {
59 131
     setDepartamento(event.target.value);
60 132
   };
61 133
 
62
-  const changePuestoSup = (event) => {
63
-    setPuestoSup(event.target.value);
134
+  const handleCloseDialog = () => {
135
+    setDialogValue({
136
+      title: '',
137
+      id: '',
138
+    });
139
+    toggleOpenDialog(false);
64 140
   };
65 141
 
142
+
143
+  const handleSubmitDialog = async (event) => {
144
+    event.preventDefault();
145
+    console.log('to save: ', dialogValue)
146
+    let { id, nombre } = await savePuestoSuperior(dialogValue, auth)
147
+    if (id) {
148
+      setDialogValue({
149
+        title: nombre,
150
+        id: id,
151
+      });
152
+    }
153
+
154
+    setDialogValue({
155
+      title: dialogValue.title,
156
+      id: dialogValue.id
157
+    });
158
+    handleCloseDialog();
159
+  };
160
+
161
+  const AutoCompleteChange = (event, newValue) => {
162
+    console.log('newValue', newValue)
163
+    // TODO : formik logic to validate autocomplete
164
+    setValues({ ...values, puestosuperior: newValue?.id })
165
+
166
+    if (typeof newValue === 'string') {
167
+      setTimeout(() => {
168
+        toggleOpenDialog(true);
169
+        setDialogValue({
170
+          title: newValue,
171
+          id: '',
172
+        });
173
+      });
174
+    } else if (newValue && newValue.inputValue) {
175
+      toggleOpenDialog(true);
176
+      setDialogValue({
177
+        title: newValue.inputValue,
178
+        id: '',
179
+      });
180
+    } else {
181
+      setDialogValue(newValue);
182
+    }
183
+  }
184
+
66 185
   const agregarPuesto = async (puesto) => {
67 186
     let rest = new Service('/plaza/save');
68 187
     return await rest.postQuery(puesto, auth.token);
69 188
   }
70 189
 
71 190
   const puestoMutation = useMutation(agregarPuesto)
72
-
73 191
   let { visible, onClose } = props
74 192
 
75 193
   const formik = useFormik({
76 194
     initialValues: {
77 195
       nombrepuesto: "",
78
-      puestosuperior: 1,
196
+      puestosuperior: null,
79 197
       aredepto: 1,
80 198
       fecha: date,
81 199
       notas: "",
@@ -83,17 +201,15 @@ function Manual(props) {
83 201
     },
84 202
     onSubmit: (fields, { resetForm }) => {
85 203
 
86
-      if(fields.tests.length === 0){
204
+      if (fields.tests.length === 0) {
87 205
         toast.error("Recuerda que seleccionar al menos un test")
88 206
         setTab(1)
89 207
         return
90 208
       }
91
-
92 209
       setOpen(true)
93 210
       fields['fecha'] = new Date(fields.fecha).toISOString();
94 211
       fields['areadeptoplz_id'] = 1;
95 212
       fields['id'] = -1;
96
-
97 213
       puestoMutation.mutate(fields, {
98 214
         onSuccess: () => {
99 215
           setOpen(false)
@@ -111,12 +227,10 @@ function Manual(props) {
111 227
     validationSchema: NewPlazaSchema,
112 228
   });
113 229
 
114
-  const changeTab = (_event, newValue) => {
115
-    setTab(newValue);
116
-  };
117
-
230
+  const changeTab = (_event, newValue) => setTab(newValue);
118 231
 
119 232
   const { errors, touched, handleSubmit, getFieldProps, values, setValues } = formik;
233
+  // console.log({ values })
120 234
 
121 235
   const addPrueba = (check, id) => {
122 236
     let { tests } = values
@@ -139,9 +253,9 @@ function Manual(props) {
139 253
       aria-labelledby="contained-modal-title-vcenter"
140 254
       onClose={onClose}>
141 255
 
142
-      <DialogTitle>
256
+      <DialogTitle className="modal-title" style={{ color: '#252525' }}>
143 257
         <button onClick={onClose} type="button" className="close" data-dismiss="modal">&times;</button>
144
-        <h4 className="modal-title" style={{ color: '#252525' }}>Agregar Puesto</h4>
258
+        Agregar Puesto
145 259
       </DialogTitle>
146 260
 
147 261
       <DialogContent className="modal-body">
@@ -151,6 +265,54 @@ function Manual(props) {
151 265
           <Tab label="Pruebas" />
152 266
         </Tabs>
153 267
 
268
+        <Dialog open={openDialog} onClose={handleCloseDialog}>
269
+          <form onSubmit={handleSubmitDialog}>
270
+            <DialogTitle>Agrega un nuevo Puesto</DialogTitle>
271
+            <DialogContent>
272
+              <DialogContentText>
273
+                Agrega la descripcion del puesto
274
+              </DialogContentText>
275
+
276
+              <TextField
277
+                autoFocus
278
+                margin="dense"
279
+                id="name"
280
+                value={dialogValue?.title}
281
+                onChange={(event) =>
282
+                  setDialogValue({
283
+                    ...dialogValue,
284
+                    title: event.target.value,
285
+                  })
286
+                }
287
+                label="Puesto"
288
+                type="text"
289
+                variant="standard"
290
+              />
291
+
292
+              <TextField
293
+                margin="dense"
294
+                id="name"
295
+                value={dialogValue?.id}
296
+                onChange={(event) =>
297
+                  setDialogValue({
298
+                    ...dialogValue,
299
+                    id: event.target.value,
300
+                  })
301
+                }
302
+                label="Descripción"
303
+                type="text"
304
+                variant="standard"
305
+              />
306
+            </DialogContent>
307
+            <DialogActions>
308
+              <Button onClick={handleCloseDialog}>Cancelar</Button>
309
+              <Button type="submit">Agregar</Button>
310
+            </DialogActions>
311
+          </form>
312
+        </Dialog>
313
+
314
+
315
+
154 316
         <FormikProvider style={{ paddingTop: 25 }} value={formik}>
155 317
           <Form autoComplete="off" noValidate onSubmit={handleSubmit}>
156 318
 
@@ -185,7 +347,6 @@ function Manual(props) {
185 347
 
186 348
               <Stack spacing={3}>
187 349
 
188
-
189 350
                 <Stack direction={{ xs: 'column', sm: 'row' }} spacing={4}>
190 351
                   <TextField
191 352
                     label="Nombre"
@@ -196,24 +357,77 @@ function Manual(props) {
196 357
                   />
197 358
 
198 359
                   <FormControl fullWidth>
199
-                    <InputLabel id="demo-simple-select-label">Puesto Superior</InputLabel>
200
-                    <Select
201
-                      labelId="demo-simple-select-label"
202
-                      value={puestoSup}
203
-                      label="Puesto Superior"
204
-                      onChange={changePuestoSup}
205
-                      {...getFieldProps('puestosuperior')}
206
-                      error={Boolean(touched.puestosuperior && errors.puestosuperior)} >
207
-                      {
208
-                        data ?
209
-                          data.data.map(cate => {
210
-                            return (
211
-                              <MenuItem key={cate.id} value={cate.id}>{cate.nombre}</MenuItem>
212
-                            )
213
-                          })
214
-                          : <MenuItem>Null</MenuItem>
215
-                      }
216
-                    </Select>
360
+
361
+                    <Autocomplete
362
+                      fullWidth
363
+                      value={dialogValue}
364
+                      onChange={AutoCompleteChange}
365
+                      open={openSugg}
366
+                      onOpen={() => {
367
+                        setOpenSugg(true);
368
+                      }}
369
+                      onClose={() => {
370
+                        setOpenSugg(false);
371
+                      }}
372
+                      isOptionEqualToValue={(option, value) => option.title === value.title}
373
+                      filterOptions={(options, params) => {
374
+                        const filtered = filter(options, params);
375
+
376
+                        if (params.inputValue !== '') {
377
+                          filtered.push({
378
+                            inputValue: params.inputValue,
379
+                            title: `Add "${params.inputValue}"`,
380
+                          });
381
+                        }
382
+
383
+                        return filtered;
384
+                      }}
385
+                      id="puesto_superior_autocomplete"
386
+                      options={options}
387
+                      loading={loading}
388
+                      getOptionLabel={(option) => {
389
+                        if (typeof option === 'string') {
390
+                          return option;
391
+                        }
392
+                        if (option.inputValue) {
393
+                          return option.inputValue;
394
+                        }
395
+                        return option.title;
396
+                      }}
397
+                      selectOnFocus
398
+                      clearOnBlur
399
+                      handleHomeEndKeys
400
+                      renderOption={(props, option) => <li {...props}>{option.title}</li>}
401
+                      freeSolo
402
+                      renderInput={(params) => (
403
+                        <TextField
404
+                          {...params}
405
+                          {...getFieldProps('puestosuperior')}
406
+                          error={Boolean(touched.puestosuperior && errors.puestosuperior)}
407
+                          label="Puesto Superior"
408
+                          InputProps={{
409
+                            ...params.InputProps,
410
+                            onChange: (event) => {
411
+                              // let title = event.target.value;
412
+                              // console.log('titulo',title)
413
+                              setOptions([]);
414
+                              setDialogValue({
415
+                                title: event.target.value,
416
+                                id: '',
417
+                              });
418
+                            },
419
+                            endAdornment: (
420
+                              <React.Fragment>
421
+                                {loading ? <CircularProgress color="inherit" size={20} /> : null}
422
+                                {params.InputProps.endAdornment}
423
+                              </React.Fragment>
424
+                            ),
425
+                          }}
426
+                        />
427
+                      )}
428
+
429
+                    />
430
+
217 431
                   </FormControl>
218 432
 
219 433
                 </Stack>

+ 1 - 1
src/Components/Puestos/Card.jsx

@@ -16,7 +16,7 @@ export function PuestoCard(props) {
16 16
     return (
17 17
         <Card sx={{ maxWidth: 345 }}>
18 18
             <CardMedia
19
-        className="cardmedia_puesto"
19
+                className="cardmedia_puesto"
20 20
                 component="img"
21 21
                 alt="green iguana"
22 22
                 height="140"

+ 171 - 0
src/Components/Resultados/Config.jsx

@@ -0,0 +1,171 @@
1
+import { createTheme } from '@mui/material';
2
+
3
+export const TableStyle = () => createTheme({
4
+  components: {
5
+
6
+    MuiSvgIcon: {
7
+      styleOverrides: {
8
+        root: {
9
+          color: 'var(--main)'
10
+        }
11
+      }
12
+    },
13
+
14
+    MUIDataTableSelectCell: {
15
+      styleOverrides: {
16
+        root: {
17
+          backgroundColor: '#FFF'
18
+        }
19
+      }
20
+    },
21
+    MuiCheckbox: {
22
+      styleOverrides: {
23
+        root: {
24
+          color: 'var(--main)'
25
+        }
26
+      }
27
+    },
28
+    MuiChecked: {
29
+      styleOverrides: {
30
+        root: {
31
+          color: 'red'
32
+        }
33
+      }
34
+    },
35
+    MUIDataTableToolbar: {
36
+      styleOverrides: {
37
+        root: {
38
+          paddingLeft: 15
39
+        }
40
+      }
41
+    },
42
+    MuiRowSelected: {
43
+      styleOverrides: {
44
+        root: {
45
+          backgroundColor: "#FFF"
46
+        }
47
+      }
48
+    },
49
+    MuiPaper: {
50
+      styleOverrides: {
51
+        root: {
52
+          boxShadow: 'none'
53
+        }
54
+      }
55
+
56
+    },
57
+    MUIDataTableSelectedCell: {
58
+      styleOverrides: {
59
+        root: {
60
+          backgroundColor: "#FFF"
61
+        }
62
+      }
63
+    },
64
+    MUITableCell: {
65
+      styleOverrides: {
66
+        root: {
67
+          backgroundColor: "#FFF"
68
+        }
69
+      }
70
+    },
71
+    MUIDataTableBodyRow: {
72
+      styleOverrides: {
73
+        root: {
74
+          backgroundColor: "#FFF"
75
+        }
76
+      }
77
+    },
78
+    MUIDataTableBodyCell: {
79
+      styleOverrides: {
80
+        root: {
81
+          backgroundColor: "#FFF"
82
+        }
83
+      }
84
+    },
85
+    MuiTablePagination: {
86
+      styleOverrides: {
87
+        toolbar: {
88
+          paddingTop: 7,
89
+          alignItems: 'baseline'
90
+        }
91
+      }
92
+    }
93
+  }
94
+})
95
+
96
+export const Encabezados = [
97
+  {
98
+    name: 'id',
99
+    numeric: true,
100
+    label: 'ID',
101
+    options: {
102
+      display: false
103
+    }
104
+  },
105
+  {
106
+    name: 'pwd',
107
+    numeric: false,
108
+    disablePadding: true,
109
+    label: 'Contraseña',
110
+  },
111
+  {
112
+    name: 'users',
113
+    numeric: false,
114
+    disablePadding: true,
115
+    label: 'Usuarios',
116
+  },
117
+  {
118
+    name: 'asings',
119
+    numeric: false,
120
+    disablePadding: true,
121
+    label: 'Asignaciones',
122
+  },
123
+]
124
+
125
+
126
+export const TextLabels = {
127
+  body: {
128
+    noMatch: "No se encontró ningún elemento",
129
+    toolTip: "Ordenar",
130
+    columnHeaderTooltip: column => `Ordenar por ${column.label}`
131
+  },
132
+  pagination: {
133
+    next: "Siguiente Pagina",
134
+    previous: "Pagina Anterior",
135
+    rowsPerPage: "Elementos por Página",
136
+    displayRows: "de",
137
+  },
138
+  toolbar: {
139
+    search: "Buscar",
140
+    downloadCsv: "Descargar CSV",
141
+    print: "Imprimir",
142
+    viewColumns: "Seleccionar Columnas",
143
+    filterTable: "Filtrar Tabla",
144
+  },
145
+  filter: {
146
+    all: "Todos",
147
+    title: "FILTROS",
148
+    reset: "Limpiar",
149
+  },
150
+  viewColumns: {
151
+    title: "Mostrar Columnas",
152
+    titleAria: "Mostrar/Ocultar Columnas",
153
+  },
154
+  selectedRows: {
155
+    text: "Elemento(s) selecionado",
156
+    delete: "Eliminar",
157
+    deleteAria: "Eliminar Columnas Seleccionadas",
158
+  },
159
+}
160
+
161
+export const BuildColumns = (columns) => {
162
+  return columns.map((column) => {
163
+    return {
164
+      'id' : 0,
165
+      'pwd' : atob( column.pwd ),
166
+      'users' : "",
167
+      'asings' : "",
168
+    }
169
+  })
170
+
171
+}

+ 46 - 0
src/Components/Resultados/TestDataTable.jsx

@@ -0,0 +1,46 @@
1
+// import { useEffect } from 'react';
2
+import { ThemeProvider } from '@mui/material/styles';
3
+import { TableStyle, Encabezados, BuildColumns } from './Config'
4
+import { useSelector } from 'react-redux';
5
+import { useQuery } from 'react-query';
6
+import { Service } from '../../Utils/HTTP'
7
+import MUIDataTable from "mui-datatables";
8
+
9
+export const TestDataTable = () => {
10
+  
11
+  const auth = useSelector((state) => state.token)
12
+
13
+  const options = {
14
+    filterType: 'checkbox',
15
+    customToolbar: () => { },
16
+    // textLabels: TextLabels,
17
+    onRowClick: (test) => {
18
+      console.log(test)
19
+      // let [plaza, pwd] = password;
20
+      // setPassword({pwd,plz:plaza});
21
+      // setVisible(true);
22
+    },
23
+    elevation: 9
24
+  };
25
+
26
+  const getAllPwd = async () => {
27
+    let rest = new Service('/contrasenia/getallbyidUsr');
28
+    return await rest.getQuery(auth.token)
29
+  }
30
+
31
+  const { data, status } = useQuery('homepwd', getAllPwd);
32
+  console.log('DATA: ', data)
33
+
34
+
35
+  return (
36
+    <ThemeProvider theme={TableStyle}>
37
+      <MUIDataTable
38
+        sx={{ '& MuiPaper': { elevation: 0, boxShadow: 'none', color: "red" } }}
39
+        title={"Expedientes"}
40
+        data={BuildColumns( status === 'success' ? data.data : [])}
41
+        columns={Encabezados}
42
+        options={options}
43
+      />
44
+    </ThemeProvider>
45
+  )
46
+}

+ 1 - 0
src/Components/Routes.js

@@ -63,6 +63,7 @@ export default function MyRoutes() {
63 63
           </RequireToken>
64 64
         }>
65 65
 
66
+        <Route path="" element={<Home />} />
66 67
         <Route path="home" element={<Home />} />
67 68
         <Route path="puestos" element={<Puestos />} />
68 69
         <Route path="perfil" element={<Profile />} />

+ 1 - 0
src/Pages/Login.jsx

@@ -68,6 +68,7 @@ export function Login() {
68 68
           toast.success(`Bienvenido ${nombre} ${apelidos} !!`)
69 69
           token = token.replace("Bearer ", "")
70 70
           console.log("TOKEN: ", token)
71
+          window.token = token;
71 72
           let body_token = jwt_decode(token);
72 73
           let timestamp = body_token.exp * 1000;
73 74
           let restante = timestamp - Date.now();

+ 2 - 2
src/Pages/Puestos.jsx

@@ -139,7 +139,7 @@ export function Puestos() {
139 139
             </Row>
140 140
             <div style={{ padding: 7 }}>
141 141
               <div className={` main_grid_plazas main_productos ${alignment === 'grid' ? 'activar_vista' : 'desactivar_vista'}`} id="grid_view">
142
-                <Row style={{ minHeight: '75vh' }}>
142
+                <Row style={{ minHeight: '57vh' }}>
143 143
                   <GridMode
144 144
                     toggle={toggle}
145 145
                     showing={alignment}
@@ -149,7 +149,7 @@ export function Puestos() {
149 149
                 </Row>
150 150
               </div>
151 151
               <div className={`main_list_products ${alignment === 'list' ? 'activar_vista' : 'desactivar_vista'}`} id="list_view_products">
152
-                <Row style={{ minHeight: '75vh' }}>
152
+                <Row style={{ minHeight: '57vh' }}>
153 153
                   <ListMode
154 154
                     toggle={toggle}
155 155
                     showing={alignment}

+ 25 - 17
src/Pages/Resultados.jsx

@@ -4,11 +4,14 @@ import { Service } from '../Utils/HTTP';
4 4
 import { useSelector } from 'react-redux';
5 5
 import { Document, Page, pdfjs } from 'react-pdf/dist/esm/entry.webpack';
6 6
 import { Loading } from '../Components/Generics/loading'
7
+import { TestDataTable } from '../Components/Resultados/TestDataTable'
7 8
 import DownloadIcon from '@mui/icons-material/Download';
8 9
 import 'react-pdf/dist/esm/Page/AnnotationLayer.css';
9 10
 import 'react-pdf/dist/esm/Page/TextLayer.css';
10 11
 import '../pdf.css'
11 12
 // import 'react-pdf/dist/esm/Page/AnnotationLayer.css';
13
+//
14
+//
12 15
 import { 
13 16
   Button, Box, Paper,LinearProgress,
14 17
   Typography
@@ -55,12 +58,6 @@ const MyDocument = (props) => {
55 58
 
56 59
   const [progress, setProgress] = useState(10);
57 60
 
58
-  if(!pdf){
59
-    <Loading/>
60
-  }
61
-
62
-  console.log(progress)
63
-
64 61
   return (
65 62
     <div>
66 63
 
@@ -107,17 +104,19 @@ const MyDocument = (props) => {
107 104
 
108 105
       <div className="Example__container">
109 106
         <div className="Example__container__document">
110
-          <Document 
111
-            renderMode="canvas" 
112
-            file={pdf?.data} 
113
-            onLoadSuccess={onDocumentLoadSuccess} 
114
-            loading={Loading}
115
-            onLoadProgress={({loaded, total}) => {
116
-              setProgress((loaded / total) * 100)
117
-            }}
118
-          >
107
+          { pdf ?
108
+            (<Document 
109
+              renderMode="canvas" 
110
+              file={pdf?.data} 
111
+              onLoadSuccess={onDocumentLoadSuccess} 
112
+              loading={Loading}
113
+              onLoadProgress={({loaded, total}) => {
114
+                setProgress((loaded / total) * 100)
115
+              }}
116
+            >
119 117
               <Page loading={Loading} pageNumber={pageNumber} />
120
-          </Document>
118
+            </Document>) : null
119
+          }
121 120
         </div>
122 121
       </div>
123 122
     </div>
@@ -133,6 +132,10 @@ export function Resultados() {
133 132
 
134 133
   useEffect(() => {
135 134
 
135
+    if(!id) {
136
+      console.log('no hay id')
137
+      return
138
+    }
136 139
     let url = `/report/cleaverResult/${id}?output=pdf`
137 140
     let rest = new Service(url);
138 141
 
@@ -152,7 +155,12 @@ export function Resultados() {
152 155
           <Paper 
153 156
             elevation={2} 
154 157
             sx={{ mb: 2, padding: 2, height: '100%', minHeight: '95vh', boxShadow: 'none !important' }}>
155
-            <MyDocument token={auth.token} id={id} pdf={pdf} />
158
+            <h1>Reporte de Resultados</h1><hr/>
159
+            {
160
+              pdf ? 
161
+                ( <MyDocument token={auth.token} id={id} pdf={pdf} />) : null
162
+            }
163
+            <TestDataTable/>
156 164
           </Paper>
157 165
         </Box>
158 166
       </div>

+ 117 - 42
src/temp.js

@@ -1,51 +1,126 @@
1 1
 import * as React from 'react';
2
-import dayjs from 'dayjs';
3
-import Stack from '@mui/material/Stack';
4 2
 import TextField from '@mui/material/TextField';
5
-import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
6
-import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
7
-import { TimePicker } from '@mui/x-date-pickers/TimePicker';
8
-import { DateTimePicker } from '@mui/x-date-pickers/DateTimePicker';
9
-import { DesktopDatePicker } from '@mui/x-date-pickers/DesktopDatePicker';
10
-import { MobileDatePicker } from '@mui/x-date-pickers/MobileDatePicker';
3
+import Autocomplete from '@mui/material/Autocomplete';
4
+import CircularProgress from '@mui/material/CircularProgress';
11 5
 
12
-export default function MaterialUIPickers() {
13
-  const [value, setValue] = React.useState(dayjs('2014-08-18T21:11:54'));
6
+function sleep(delay = 0) {
7
+  return new Promise((resolve) => {
8
+    setTimeout(resolve, delay);
9
+  });
10
+}
11
+
12
+export default function Asynchronous() {
13
+  const [open, setOpen] = React.useState(false);
14
+  const [options, setOptions] = React.useState([]);
15
+  const loading = open && options.length === 0;
16
+
17
+  React.useEffect(() => {
18
+    let active = true;
19
+
20
+    if (!loading) {
21
+      return undefined;
22
+    }
23
+
24
+    (async () => {
25
+      await sleep(1e3); // For demo purposes.
26
+
27
+      if (active) {
28
+        setOptions([...topFilms]);
29
+      }
30
+    })();
14 31
 
15
-  const handleChange = (newValue) => {
16
-    setValue(newValue);
17
-  };
32
+    return () => {
33
+      active = false;
34
+    };
35
+  }, [loading]);
36
+
37
+  React.useEffect(() => {
38
+    if (!open) {
39
+      setOptions([]);
40
+    }
41
+  }, [open]);
18 42
 
19 43
   return (
20
-    <LocalizationProvider dateAdapter={AdapterDayjs}>
21
-      <Stack spacing={3}>
22
-        <DesktopDatePicker
23
-          label="Date desktop"
24
-          inputFormat="MM/DD/YYYY"
25
-          value={value}
26
-          onChange={handleChange}
27
-          renderInput={(params) => <TextField {...params} />}
28
-        />
29
-        <MobileDatePicker
30
-          label="Date mobile"
31
-          inputFormat="MM/DD/YYYY"
32
-          value={value}
33
-          onChange={handleChange}
34
-          renderInput={(params) => <TextField {...params} />}
35
-        />
36
-        <TimePicker
37
-          label="Time"
38
-          value={value}
39
-          onChange={handleChange}
40
-          renderInput={(params) => <TextField {...params} />}
44
+    <Autocomplete
45
+      id="asynchronous-demo"
46
+      sx={{ width: 300 }}
47
+      open={open}
48
+      onOpen={() => {
49
+        setOpen(true);
50
+      }}
51
+      onClose={() => {
52
+        setOpen(false);
53
+      }}
54
+      isOptionEqualToValue={(option, value) => option.title === value.title}
55
+      getOptionLabel={(option) => option.title}
56
+      options={options}
57
+      loading={loading}
58
+      renderInput={(params) => (
59
+        <TextField
60
+          {...params}
61
+          label="Asynchronous"
62
+          InputProps={{
63
+            ...params.InputProps,
64
+            endAdornment: (
65
+              <React.Fragment>
66
+                {loading ? <CircularProgress color="inherit" size={20} /> : null}
67
+                {params.InputProps.endAdornment}
68
+              </React.Fragment>
69
+            ),
70
+          }}
41 71
         />
42
-        <DateTimePicker
43
-          label="Date&Time picker"
44
-          value={value}
45
-          onChange={handleChange}
46
-          renderInput={(params) => <TextField {...params} />}
47
-        />
48
-      </Stack>
49
-    </LocalizationProvider>
72
+      )}
73
+    />
50 74
   );
51 75
 }
76
+
77
+// Top films as rated by IMDb users. http://www.imdb.com/chart/top
78
+const topFilms = [
79
+  { title: 'The Shawshank Redemption', year: 1994 },
80
+  { title: 'The Godfather', year: 1972 },
81
+  { title: 'The Godfather: Part II', year: 1974 },
82
+  { title: 'The Dark Knight', year: 2008 },
83
+  { title: '12 Angry Men', year: 1957 },
84
+  { title: "Schindler's List", year: 1993 },
85
+  { title: 'Pulp Fiction', year: 1994 },
86
+  {
87
+    title: 'The Lord of the Rings: The Return of the King',
88
+    year: 2003,
89
+  },
90
+  { title: 'The Good, the Bad and the Ugly', year: 1966 },
91
+  { title: 'Fight Club', year: 1999 },
92
+  {
93
+    title: 'The Lord of the Rings: The Fellowship of the Ring',
94
+    year: 2001,
95
+  },
96
+  {
97
+    title: 'Star Wars: Episode V - The Empire Strikes Back',
98
+    year: 1980,
99
+  },
100
+  { title: 'Forrest Gump', year: 1994 },
101
+  { title: 'Inception', year: 2010 },
102
+  {
103
+    title: 'The Lord of the Rings: The Two Towers',
104
+    year: 2002,
105
+  },
106
+  { title: "One Flew Over the Cuckoo's Nest", year: 1975 },
107
+  { title: 'Goodfellas', year: 1990 },
108
+  { title: 'The Matrix', year: 1999 },
109
+  { title: 'Seven Samurai', year: 1954 },
110
+  {
111
+    title: 'Star Wars: Episode IV - A New Hope',
112
+    year: 1977,
113
+  },
114
+  { title: 'City of God', year: 2002 },
115
+  { title: 'Se7en', year: 1995 },
116
+  { title: 'The Silence of the Lambs', year: 1991 },
117
+  { title: "It's a Wonderful Life", year: 1946 },
118
+  { title: 'Life Is Beautiful', year: 1997 },
119
+  { title: 'The Usual Suspects', year: 1995 },
120
+  { title: 'Léon: The Professional', year: 1994 },
121
+  { title: 'Spirited Away', year: 2001 },
122
+  { title: 'Saving Private Ryan', year: 1998 },
123
+  { title: 'Once Upon a Time in the West', year: 1968 },
124
+  { title: 'American History X', year: 1998 },
125
+  { title: 'Interstellar', year: 2014 },
126
+];