浏览代码

fix update puesto

amenpunk 2 年之前
父节点
当前提交
52e0c4aea9
共有 4 个文件被更改,包括 132 次插入113 次删除
  1. 49 49
      src/Components/Modal/AgregarManual.js
  2. 83 62
      src/Components/Modal/EditPlaza.js
  3. 0 1
      src/Components/Puestos/Card.jsx
  4. 0 1
      src/Pages/Puestos.jsx

+ 49 - 49
src/Components/Modal/AgregarManual.js

@@ -8,9 +8,9 @@ import DateFnsUtils from '@date-io/date-fns';
8 8
 import { DesktopDatePicker, LocalizationProvider } from '@mui/lab';
9 9
 
10 10
 import {
11
-    Button, Stack, TextField, MenuItem, FormControl, InputLabel, Select,
12
-    Backdrop, CircularProgress,Box,Divider,
13
-    Tabs, Tab, FormGroup, Checkbox,FormControlLabel
11
+  Button, Stack, TextField, MenuItem, FormControl, InputLabel, Select,
12
+  Backdrop, CircularProgress, Box, Divider,
13
+  Tabs, Tab, FormGroup, Checkbox, FormControlLabel
14 14
 } from '@mui/material';
15 15
 
16 16
 import { Service } from '../../Utils/HTTP';
@@ -78,7 +78,7 @@ function Manual(props) {
78 78
       aredepto: 1,
79 79
       fecha: date,
80 80
       notas: "",
81
-      tests:[]
81
+      tests: []
82 82
     },
83 83
     onSubmit: (fields, { resetForm }) => {
84 84
 
@@ -111,16 +111,16 @@ function Manual(props) {
111 111
 
112 112
   const { errors, touched, handleSubmit, getFieldProps, values, setValues } = formik;
113 113
 
114
-  const addPrueba = (check,id) => {
114
+  const addPrueba = (check, id) => {
115 115
     let { tests } = values
116
-    let temp ;
117
-    if(check){
118
-      temp = [...tests, {id}]
119
-    }else{
120
-      temp = tests.filter( test => test.id !== id);
116
+    let temp;
117
+    if (check) {
118
+      temp = [...tests, { id }]
119
+    } else {
120
+      temp = tests.filter(test => test.id !== id);
121 121
     }
122
-    setChecklist(  temp.map( test => test.id) )
123
-    setValues({...values, tests: temp})
122
+    setChecklist(temp.map(test => test.id))
123
+    setValues({ ...values, tests: temp })
124 124
   };
125 125
 
126 126
   return (
@@ -143,26 +143,26 @@ function Manual(props) {
143 143
 
144 144
             <TabPanel value={tab} index={1}>
145 145
               <Stack spacing={1}>
146
-                <Box style={{ paddingTop :5, paddingLeft :15 }}>
147
-                  <Divider/>
148
-                  <h4 style={{paddingTop :10, paddingBottom:10}}>Seleciona los test a realizar</h4>
149
-                  <Divider/>
146
+                <Box style={{ paddingTop: 5, paddingLeft: 15 }}>
147
+                  <Divider />
148
+                  <h4 style={{ paddingTop: 10, paddingBottom: 10 }}>Seleciona los test a realizar</h4>
149
+                  <Divider />
150 150
                   <FormGroup>
151 151
                     {
152
-                    testsCatalog ?
153
-                      testsCatalog.data.map( test => (
154
-                        <FormControlLabel 
155
-                          key={test.id}
156
-                          control={
157
-                          <Checkbox 
158
-                            checked={checklist.includes((test.id))}
159
-                            onChange={(event)=> addPrueba(event.target.checked,test.id)}
160
-                            />
161
-                        } 
162
-                          label={test.nombre} 
152
+                      testsCatalog ?
153
+                        testsCatalog.data.map(test => (
154
+                          <FormControlLabel
155
+                            key={test.id}
156
+                            control={
157
+                              <Checkbox
158
+                                checked={checklist.includes((test.id))}
159
+                                onChange={(event) => addPrueba(event.target.checked, test.id)}
160
+                              />
161
+                            }
162
+                            label={test.nombre}
163 163
                           />
164
-                      )): null
165
-                  }
164
+                        )) : null
165
+                    }
166 166
                   </FormGroup>
167 167
                 </Box>
168 168
               </Stack>
@@ -179,7 +179,7 @@ function Manual(props) {
179 179
                     fullWidth
180 180
                     {...getFieldProps('nombrepuesto')}
181 181
                     error={Boolean(touched.nombrepuesto && errors.nombrepuesto)}
182
-                    />
182
+                  />
183 183
 
184 184
                   <FormControl fullWidth>
185 185
                     <InputLabel id="demo-simple-select-label">Puesto Superior</InputLabel>
@@ -191,14 +191,14 @@ function Manual(props) {
191 191
                       {...getFieldProps('puestosuperior')}
192 192
                       error={Boolean(touched.puestosuperior && errors.puestosuperior)} >
193 193
                       {
194
-                      data ?
195
-                        data.data.map(cate => {
196
-                          return (
197
-                            <MenuItem key={cate.id} value={cate.id}>{cate.nombre}</MenuItem>
198
-)
199
-                        })
200
-                        : <MenuItem>Null</MenuItem>
201
-                    }
194
+                        data ?
195
+                          data.data.map(cate => {
196
+                            return (
197
+                              <MenuItem key={cate.id} value={cate.id}>{cate.nombre}</MenuItem>
198
+                            )
199
+                          })
200
+                          : <MenuItem>Null</MenuItem>
201
+                      }
202 202
                     </Select>
203 203
                   </FormControl>
204 204
 
@@ -216,14 +216,14 @@ function Manual(props) {
216 216
                       {...getFieldProps('aredepto')}
217 217
                       error={Boolean(touched.aredepto && errors.aredepto)} >
218 218
                       {
219
-                      data ?
220
-                        data.data.map(cate => {
221
-                          return (
222
-                            <MenuItem key={cate.id} value={cate.id}>{cate.nombre}</MenuItem>
223
-                          )
224
-                        })
225
-                        : <MenuItem>Null</MenuItem>
226
-                    }
219
+                        data ?
220
+                          data.data.map(cate => {
221
+                            return (
222
+                              <MenuItem key={cate.id} value={cate.id}>{cate.nombre}</MenuItem>
223
+                            )
224
+                          })
225
+                          : <MenuItem>Null</MenuItem>
226
+                      }
227 227
                     </Select>
228 228
                   </FormControl>
229 229
 
@@ -243,8 +243,8 @@ function Manual(props) {
243 243
                           label="Fecha Creación"
244 244
                           fullWidth
245 245
                           {...params}
246
-                          />}
247
-                      />
246
+                        />}
247
+                    />
248 248
                   </LocalizationProvider>
249 249
 
250 250
                 </Stack>
@@ -261,7 +261,7 @@ function Manual(props) {
261 261
                     {...getFieldProps('notas')}
262 262
                     error={Boolean(touched.notas && errors.notas)}
263 263
                     helperText={touched.notas && errors.notas}
264
-                    />
264
+                  />
265 265
                 </Stack>
266 266
               </Stack>
267 267
 

+ 83 - 62
src/Components/Modal/EditPlaza.js

@@ -11,7 +11,7 @@ import { TabPanel } from './TabPanel'
11 11
 import {
12 12
   Button, Stack, TextField, MenuItem, FormControl, InputLabel, Select,
13 13
   Backdrop, CircularProgress,
14
-  Tabs,Tab,Box, Divider,FormGroup,FormControlLabel,Checkbox
14
+  Tabs, Tab, Box, Divider, FormGroup, FormControlLabel, Checkbox
15 15
 } from '@mui/material';
16 16
 
17 17
 import toast, { Toaster } from 'react-hot-toast';
@@ -23,9 +23,9 @@ import { useQuery, useMutation, useQueryClient } from 'react-query'
23 23
 const plazeSchema = Yup.object({
24 24
   id: Yup.number(),
25 25
   nombrepuesto:
26
-  Yup.string().required('El nombre es requerido')
27
-  .min(5, "El nombre del  puesto debe ser mayor a 5 caracteres")
28
-  .max(100),
26
+    Yup.string().required('El nombre es requerido')
27
+      .min(5, "El nombre del  puesto debe ser mayor a 5 caracteres")
28
+      .max(100),
29 29
   puestosuperior: Yup.number("El puesto superior debe ser un número").required("El puesto es requerido"),
30 30
   aredepto: Yup.number('El área debe ser un número').required('Escoge alguna área'),
31 31
   fecha: Yup.date("Ingresa una fecha válida").required(),
@@ -36,15 +36,15 @@ const plazeSchema = Yup.object({
36 36
 
37 37
 function Edit(props) {
38 38
 
39
-  const { setValue,getValues,reset,control,register, handleSubmit, formState: { errors } } = useForm({
40
-    resolver : yupResolver(plazeSchema),
39
+  const { setValue, getValues, reset, control, register, handleSubmit, formState: { errors } } = useForm({
40
+    resolver: yupResolver(plazeSchema),
41 41
     defaultValues: {
42 42
       nombrepuesto: 'mingtest',
43 43
       puestosuperior: 77,
44 44
       fecha: '01/01/2019',
45 45
       notas: 'esto es un ejemplod e una nota',
46
-      aredepto : 1,
47
-      tests : []
46
+      aredepto: 1,
47
+      tests: []
48 48
     }
49 49
   });
50 50
 
@@ -52,7 +52,7 @@ function Edit(props) {
52 52
 
53 53
     let body = {
54 54
       ...data,
55
-      fecha : new Date(data.fecha).toISOString()
55
+      fecha: new Date(data.fecha).toISOString()
56 56
     }
57 57
 
58 58
     puestoMutation.mutate(body, {
@@ -62,7 +62,7 @@ function Edit(props) {
62 62
         toast.success("Puesto Actualizado!!")
63 63
         queryClient.invalidateQueries('puestos')
64 64
       },
65
-      onError:() => {
65
+      onError: () => {
66 66
         //close();
67 67
         //setOpen(false)
68 68
         toast.error("Lo sentimos ocurrió error inténtalo más tarde")
@@ -74,21 +74,26 @@ function Edit(props) {
74 74
   const auth = useSelector((state) => state.token)
75 75
   const queryClient = useQueryClient()
76 76
   let { visible, toggle } = props
77
+  const [puestoSup, setPuestoSup] = React.useState('');
77 78
 
78 79
   const [open, setOpen] = React.useState(false);
79 80
   const [tab, setTab] = React.useState(0);
80 81
   const [checklist, setChecklist] = React.useState([]);
81 82
 
82
-  const addPrueba = (check,id) => {
83
+  const changePuestoSup = (event) => {
84
+    setPuestoSup(event.target.value);
85
+  };
86
+
87
+  const addPrueba = (check, id) => {
83 88
     let tests = getValues("tests")
84 89
     console.log(tests)
85
-    let temp ;
86
-    if(check){
87
-      temp = [...tests, {id}]
88
-    }else{
89
-      temp = tests.filter( test => test.id !== id);
90
+    let temp;
91
+    if (check) {
92
+      temp = [...tests, { id }]
93
+    } else {
94
+      temp = tests.filter(test => test.id !== id);
90 95
     }
91
-    setChecklist(temp.map( test => test.id) )
96
+    setChecklist(temp.map(test => test.id))
92 97
     setValue('tests', temp)
93 98
   };
94 99
 
@@ -109,25 +114,25 @@ function Edit(props) {
109 114
 
110 115
   const puestoMutation = useMutation(updatePuesto)
111 116
 
112
-  const close = () => toggle("EDIT", {id : null});
117
+  const close = () => toggle("EDIT", { id: null });
113 118
 
114 119
   const { data: categories } = useQuery('categories', getCategories);
115 120
   const { data: testsCatalog } = useQuery('tests', getTest);
116 121
 
117 122
   useEffect(() => {
118
-    if(visible == null) return;
123
+    if (visible == null) return;
119 124
     let rest = new Service(`/plaza/getthis/${visible}`)
120 125
     rest
121 126
       .getQuery(auth.token)
122
-      .then( response => {
127
+      .then(response => {
123 128
         console.log(response.data)
124 129
         let { areadeptoplz_id, fecha, tests } = response.data;
125
-        let temp_test = tests.map( t => ({ id : t.id} ))
126
-        setChecklist(temp_test.map( t => t.id))
127
-        reset({...response.data, aredepto : areadeptoplz_id, fecha : new Date(fecha) , tests : temp_test  })
130
+        let temp_test = tests.map(t => ({ id: t.id }))
131
+        setChecklist(temp_test.map(t => t.id))
132
+        reset({ ...response.data, aredepto: areadeptoplz_id, fecha: new Date(fecha), tests: temp_test })
128 133
       })
129 134
       .catch(console.log)
130
-  },[visible, auth,reset])
135
+  }, [visible, auth, reset])
131 136
 
132 137
   const changeTab = (_event, newValue) => setTab(newValue);
133 138
 
@@ -148,24 +153,24 @@ function Edit(props) {
148 153
         <form onSubmit={handleSubmit(onSubmit)}>
149 154
           <TabPanel value={tab} index={1}>
150 155
             <Stack spacing={1}>
151
-              <Box style={{ paddingTop :5, paddingLeft :15 }}>
152
-                <Divider/>
153
-                <h4 style={{paddingTop :10, paddingBottom:10}}>Seleciona los test a realizar</h4>
154
-                <Divider/>
156
+              <Box style={{ paddingTop: 5, paddingLeft: 15 }}>
157
+                <Divider />
158
+                <h4 style={{ paddingTop: 10, paddingBottom: 10 }}>Seleciona los test a realizar</h4>
159
+                <Divider />
155 160
                 <FormGroup>
156 161
                   {
157
-                  testsCatalog ?
158
-                    testsCatalog.data.map( test => (
159
-                      <FormControlLabel 
160
-                        label={test.nombre} 
161
-                        key={test.id}
162
-                        control={
163
-                        <Checkbox 
164
-                          checked={checklist.includes((test.id))}
165
-                          onChange={(event)=> addPrueba(event.target.checked,test.id)} /> } 
162
+                    testsCatalog ?
163
+                      testsCatalog.data.map(test => (
164
+                        <FormControlLabel
165
+                          label={test.nombre}
166
+                          key={test.id}
167
+                          control={
168
+                            <Checkbox
169
+                              checked={checklist.includes((test.id))}
170
+                              onChange={(event) => addPrueba(event.target.checked, test.id)} />}
166 171
                         />
167
-                    )): null
168
-                }
172
+                      )) : null
173
+                  }
169 174
                 </FormGroup>
170 175
               </Box>
171 176
             </Stack>
@@ -184,38 +189,54 @@ function Edit(props) {
184 189
                   error={Boolean(errors?.nombrepuesto)}
185 190
                   {...register("nombrepuesto")} />
186 191
 
187
-                <TextField
188
-                  name="puestosuperior"
189
-                  label="Puesto superior"
190
-                  fullWidth
191
-                  helperText={errors.puestosuperior?.message}
192
-                  error={Boolean(errors?.puestosuperior)}
193
-                  {...register("puestosuperior")} />
194
-
192
+                <FormControl fullWidth>
193
+                  <InputLabel id="demo-simple-select-label">Puesto Superior</InputLabel>
194
+                  <Controller
195
+                    helperText={errors.puestosuperior?.message}
196
+                    error={Boolean(errors?.puestosuperior)}
197
+                    name="puestosuperior"
198
+                    control={control}
199
+                    render={({field}) => 
200
+                      <Select {...field}>
201
+                        {
202
+                          categories ?
203
+                            categories.data.map(cate => {
204
+                              return (
205
+                                <MenuItem key={cate.id} value={cate.id}>{cate.nombre}</MenuItem>
206
+                              )
207
+                            })
208
+                            : <MenuItem>Null</MenuItem>
209
+                        }
210
+                      </Select>
211
+                    }
212
+                    >
213
+                    
214
+                  </Controller>
215
+                </FormControl>
195 216
               </Stack>
196 217
 
197 218
               <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
198 219
 
199 220
                 <FormControl fullWidth>
200
-                  <InputLabel>Departamento</InputLabel>
221
+                  <InputLabel id="demo-simple-select-label2">Departamento</InputLabel>
201 222
                   <Controller
202 223
                     helperText={errors.aredepto?.message}
203 224
                     error={Boolean(errors?.aredepto)}
204 225
                     name="aredepto"
205 226
                     control={control}
206
-                    render={ ({field}) =>
227
+                    render={({ field }) =>
207 228
                       <Select {...field}>
208 229
                         {
209
-                        categories ?
210
-                          categories.data.map(cate => {
211
-                            return (
212
-                              <MenuItem key={cate.id} value={cate.id}>{cate.nombre}</MenuItem>
213
-                            )
214
-                          })
215
-                          : <MenuItem value={1}>hola</MenuItem>
216
-                      }
230
+                          categories ?
231
+                            categories.data.map(cate => {
232
+                              return (
233
+                                <MenuItem key={cate.id} value={cate.id}>{cate.nombre}</MenuItem>
234
+                              )
235
+                            })
236
+                            : <MenuItem value={1}>hola</MenuItem>
237
+                        }
217 238
                       </Select>
218
-                  }>
239
+                    }>
219 240
                   </Controller>
220 241
                 </FormControl>
221 242
 
@@ -223,7 +244,7 @@ function Edit(props) {
223 244
                   <Controller
224 245
                     name="fecha"
225 246
                     control={control}
226
-                    render={({field}) => 
247
+                    render={({ field }) =>
227 248
                       <DesktopDatePicker
228 249
                         {...field}
229 250
                         helperText={errors.fecha?.message}
@@ -231,8 +252,8 @@ function Edit(props) {
231 252
                         label="Fecha Creación"
232 253
                         fullWidth
233 254
                         inputFormat="dd/MM/yyyy"
234
-                        renderInput={(params) => <TextField {...params}  helperText={errors.fecha?.message} />} /> } 
235
-                      >
255
+                        renderInput={(params) => <TextField {...params} helperText={errors.fecha?.message} />} />}
256
+                  >
236 257
                   </Controller>
237 258
                 </LocalizationProvider>
238 259
               </Stack>
@@ -248,7 +269,7 @@ function Edit(props) {
248 269
                   fullWidth
249 270
                   type="text"
250 271
                   {...register("notas")}
251
-                  />
272
+                />
252 273
               </Stack>
253 274
             </Stack>
254 275
           </TabPanel>

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

@@ -10,7 +10,6 @@ import QA from '../../Images/puesto.jpg'
10 10
 
11 11
 export function PuestoCard(props) {
12 12
 
13
-  console.log('render')
14 13
     let { plaza } = props
15 14
     let { nombrepuesto, notas } = plaza
16 15
 

+ 0 - 1
src/Pages/Puestos.jsx

@@ -31,7 +31,6 @@ import { useQuery } from 'react-query';
31 31
 
32 32
 export function Puestos() {
33 33
 
34
-  console.log('render puestos')
35 34
   const auth = useSelector((state) => state.token)
36 35
   const [page, setPage] = useState(1);
37 36