Explorar el Código

edit plz shit

amenpunk hace 1 año
padre
commit
e8a4b8706a
Se han modificado 1 ficheros con 24 adiciones y 56 borrados
  1. 24 56
      src/Components/Modal/EditPlaza.js

+ 24 - 56
src/Components/Modal/EditPlaza.js

@@ -70,18 +70,7 @@ const plazeSchema = Yup.object({
70 70
 
71 71
 function Edit(props) {
72 72
 
73
-  // const { resetField, setFocus, setValue, getValues, reset, control, register, handleSubmit, formState: { errors } } = useForm({
74
-  //   resolver: yupResolver(plazeSchema),
75
-  //   defaultValues: {
76
-  //     id: 0,
77
-  //     nombrepuesto: 'mingtest',
78
-  //     puestosuperior: 0,
79
-  //     fecha: '01/01/2019',
80
-  //     notas: 'esto es un ejemplod e una nota',
81
-  //     aredepto: 1,
82
-  //     tests: []
83
-  //   }
84
-  // });
73
+  const [date, setDate] = React.useState(new Date());
85 74
 
86 75
   const formik = useFormik({
87 76
     initialValues: {
@@ -89,7 +78,7 @@ function Edit(props) {
89 78
       nombrepuesto: "",
90 79
       puestosuperior: 0,
91 80
       aredepto: 1,
92
-      fecha: '01/01/2019',
81
+      fecha: date,
93 82
       notas: "",
94 83
       tests: []
95 84
     },
@@ -118,8 +107,6 @@ function Edit(props) {
118 107
         queryClient.invalidateQueries('puestos')
119 108
       },
120 109
       onError: () => {
121
-        //close();
122
-        //setOpen(false)
123 110
         toast.error("Lo sentimos ocurrió error inténtalo más tarde")
124 111
       }
125 112
     })
@@ -149,7 +136,7 @@ function Edit(props) {
149 136
   };
150 137
 
151 138
   const handleSubmitDialog = async (event) => {
152
-    console.log('handlesubmit', dialogValue)
139
+    // console.log('handlesubmit', dialogValue)
153 140
     event.preventDefault();
154 141
     let { id, nombre } = await savePuestoSuperior(dialogValue, auth)
155 142
     if (id) {
@@ -158,43 +145,22 @@ function Edit(props) {
158 145
         id: id,
159 146
       }
160 147
       if (to_set.id) {
161
-        console.log("TO SET", to_set)
148
+        // console.log("TO SET", to_set)
162 149
         setDialogValue(to_set);
163
-        // reset({ ...getValues(),puestosuperior: to_set.id })
150
+        setValues({...values, puestosuperior: to_set.id})
164 151
       }
165 152
     }
166 153
     handleCloseDialog();
167 154
   };
168 155
 
169 156
   let setDialogValue = useCallback((value) => {
170
-    console.log('value receivied', value)
157
+    // console.log('value receivied', value)
171 158
     let id = value?.id || 0;
172 159
     if (id !== 0) {
173 160
       console.log('setting value', id)
174
-      // let temp = getValues();
175
-      // temp['puestosuperior'] = id
176
-      // temp['puestosuperior_id'] = id
177
-      // reset({ ...temp, puestosuperior: id }, { keepDefaultValues: false, })
178
-      // setDialogValueHook(value)
179
-      // setValue('puestosuperior', parseInt(id))
180
-      // resetField('puestosuperior')
181
-      // let a = puestoref.current;
182
-      // a.focus();
183
-      // console.log(a)
184
-      // setValue('puestosuperior', id)
185
-      // reset({ ...temp, puestosuperior_id: id, puestosuperior: id }, {
186
-      //   keepErrors: true ,
187
-      //   keepDirty: true,
188
-      //   keepIsSubmitted: true,
189
-      //   keepTouched: true,
190
-      // })
191 161
 
192 162
     }
193
-    // setFocus("puestosuperior_id",{shouldSelect:true})
194
-    // console.log('SETTING:', value)
195
-    // console.log("final", getValues())
196 163
     setDialogValueHook(value)
197
-
198 164
   }, [])
199 165
 
200 166
   const changeDepartamento = (event) => {
@@ -204,18 +170,10 @@ function Edit(props) {
204 170
   const loading = openSugg && options.length === 0;
205 171
 
206 172
   const AutoCompleteChange = (event, newValue) => {
207
-    // let temp = getValues();
208
-    // console.log('newValue', temp, newValue)
209
-    // temp['puestosuperior'] = newValue?.id;
210
-    // reset(temp)
211
-    // setDialogValue(newValue);
212
-    // return;
213
-    //this should be change
214
-    // setValue('puestosuperior', newValue?.id)
215 173
     setValues({ ...values, puestosuperior: newValue?.id })
216 174
 
217 175
     if (typeof newValue === 'string') {
218
-      console.log('if1')
176
+      // console.log('if1')
219 177
       setTimeout(() => {
220 178
         toggleOpenDialog(true);
221 179
         setDialogValue({
@@ -224,14 +182,14 @@ function Edit(props) {
224 182
         });
225 183
       });
226 184
     } else if (newValue && newValue.inputValue) {
227
-      console.log('if2')
185
+      // console.log('if2')
228 186
       toggleOpenDialog(true);
229 187
       setDialogValue({
230 188
         title: newValue.inputValue,
231 189
         id: '',
232 190
       });
233 191
     } else {
234
-      console.log('if3')
192
+      // console.log('if3')
235 193
       setDialogValue(newValue);
236 194
     }
237 195
   }
@@ -281,10 +239,11 @@ function Edit(props) {
281 239
       rest
282 240
         .getQuery(auth.token)
283 241
         .then(response => {
242
+        console.log('plz to edit: ', response.data)
284 243
           let { areadeptoplz_id, fecha, tests, puestosuperior } = response.data;
285 244
           let temp_test = tests.map(t => ({ id: t.id }))
286 245
           setChecklist(temp_test.map(t => t.id))
287
-          console.log('puesto sup', puestosuperior)
246
+          // console.log('puesto sup', puestosuperior)
288 247
           setDialogValue({
289 248
             title: puestosuperior.nombre,
290 249
             id: puestosuperior.id
@@ -350,7 +309,7 @@ function Edit(props) {
350 309
                 id="name"
351 310
                 value={dialogValue?.title}
352 311
                 onChange={(event) => {
353
-                  console.log('aa', event.target.value)
312
+                  // console.log('aa', event.target.value)
354 313
                   setDialogValue({
355 314
                     ...dialogValue,
356 315
                     title: event.target.value,
@@ -367,7 +326,7 @@ function Edit(props) {
367 326
                 id="name"
368 327
                 value={dialogValue?.id}
369 328
                 onChange={(event) => {
370
-                  console.log('ev', event.target.value)
329
+                  // console.log('ev', event.target.value)
371 330
                   setDialogValue({
372 331
                     ...dialogValue,
373 332
                     id: event.target.value,
@@ -479,7 +438,7 @@ function Edit(props) {
479 438
                             ...params.InputProps,
480 439
                             onChange: (event) => {
481 440
                               let title = event.target.value;
482
-                              console.log('titulo', title)
441
+                              // console.log('titulo', title)
483 442
                               setOptions([]);
484 443
                               setDialogValue({
485 444
                                 title: title,
@@ -525,12 +484,21 @@ function Edit(props) {
525 484
 
526 485
                   <LocalizationProvider dateAdapter={DateFnsUtils}>
527 486
                     <DesktopDatePicker
487
+                      {...getFieldProps('fecha')}
528 488
                       helperText={errors.fecha?.message}
529 489
                       error={Boolean(errors?.fecha)}
530 490
                       label="Fecha Creación"
531 491
                       fullWidth
492
+                      value={date}
493
+                      onChange={setDate}
532 494
                       inputFormat="dd/MM/yyyy"
533
-                      renderInput={(params) => <TextField {...params} helperText={errors.fecha?.message} />}
495
+                      renderInput={ (params) => 
496
+                        <TextField 
497
+                        disabled={true}
498
+                        {...params} 
499
+                        helperText={errors.fecha?.message} 
500
+                        />
501
+                      }
534 502
                     />
535 503
                   </LocalizationProvider>
536 504
                 </Stack>