소스 검색

Puesto superior logic

amenpunk 2 년 전
부모
커밋
1477f93710
1개의 변경된 파일41개의 추가작업 그리고 14개의 파일을 삭제
  1. 41 14
      src/Components/Modal/AgregarManual.js

+ 41 - 14
src/Components/Modal/AgregarManual.js

25
 const filter = createFilterOptions();
25
 const filter = createFilterOptions();
26
 
26
 
27
 async function getPuestoSuperior(puesto, auth) {
27
 async function getPuestoSuperior(puesto, auth) {
28
-  if (puesto.length < 3) return []
28
+  if (puesto.length < 2) return []
29
   let rest = new Service(`/plaza/keypuestosup?keyword=${puesto}`)
29
   let rest = new Service(`/plaza/keypuestosup?keyword=${puesto}`)
30
   let result = await rest.get(auth.token)
30
   let result = await rest.get(auth.token)
31
   // console.log(result)
31
   // console.log(result)
32
   if (result?.data?.length > 0) {
32
   if (result?.data?.length > 0) {
33
-    result = result.data.map((item) => ({ 'title': item.nombre, year: item.id }))
33
+    result = result.data.map((item) => ({ 'title': item.nombre, id: item.id }))
34
     return result;
34
     return result;
35
   }
35
   }
36
   return [];
36
   return [];
37
 }
37
 }
38
 
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
+
39
 
56
 
40
 function Manual(props) {
57
 function Manual(props) {
41
 
58
 
58
 
75
 
59
   const NewPlazaSchema = Yup.object().shape({
76
   const NewPlazaSchema = Yup.object().shape({
60
     nombrepuesto: Yup.string().required('El nombre es requerido').min(5, "El nombre del  puesto debe ser mayor a 5 caracteres").max(100),
77
     nombrepuesto: Yup.string().required('El nombre es requerido').min(5, "El nombre del  puesto debe ser mayor a 5 caracteres").max(100),
61
-    puestosuperior: Yup.string().required("El puesto es requerido").min(5, "El nombre del  puesto debe ser mayor a 5 caracteres").max(30),
78
+    puestosuperior: Yup.number().required("El puesto superior es requerido"),
62
     aredepto: Yup.number().required('Escoge alguna área'),
79
     aredepto: Yup.number().required('Escoge alguna área'),
63
     fecha: Yup.date("Ingresa una fecha válida"),
80
     fecha: Yup.date("Ingresa una fecha válida"),
64
     notas: Yup.string("Ingresa una nota válida").min(5, "Ingresa una nota válida").max(150),
81
     notas: Yup.string("Ingresa una nota válida").min(5, "Ingresa una nota válida").max(150),
75
   const [options, setOptions] = React.useState([]);
92
   const [options, setOptions] = React.useState([]);
76
   const [dialogValue, setDialogValueHook] = React.useState({
93
   const [dialogValue, setDialogValueHook] = React.useState({
77
     title: '',
94
     title: '',
78
-    year: '',
95
+    id: '',
79
   });
96
   });
80
 
97
 
81
   let setDialogValue = (value) => {
98
   let setDialogValue = (value) => {
82
-    console.log('llamada', value)
99
+    // console.log('llamada', value)
83
     // setValues({...values, puestosuperior: value?.title })
100
     // setValues({...values, puestosuperior: value?.title })
84
     setDialogValueHook(value)
101
     setDialogValueHook(value)
85
   }
102
   }
117
   const handleCloseDialog = () => {
134
   const handleCloseDialog = () => {
118
     setDialogValue({
135
     setDialogValue({
119
       title: '',
136
       title: '',
120
-      year: '',
137
+      id: '',
121
     });
138
     });
122
     toggleOpenDialog(false);
139
     toggleOpenDialog(false);
123
   };
140
   };
124
 
141
 
125
 
142
 
126
-  const handleSubmitDialog = (event) => {
143
+  const handleSubmitDialog = async (event) => {
127
     event.preventDefault();
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
+
128
     setDialogValue({
154
     setDialogValue({
129
       title: dialogValue.title,
155
       title: dialogValue.title,
130
-      year: parseInt(dialogValue.year, 10),
156
+      id: dialogValue.id
131
     });
157
     });
132
     handleCloseDialog();
158
     handleCloseDialog();
133
   };
159
   };
135
   const AutoCompleteChange = (event, newValue) => {
161
   const AutoCompleteChange = (event, newValue) => {
136
     console.log('newValue', newValue)
162
     console.log('newValue', newValue)
137
     // TODO : formik logic to validate autocomplete
163
     // TODO : formik logic to validate autocomplete
164
+    setValues({ ...values, puestosuperior: newValue?.id })
138
 
165
 
139
     if (typeof newValue === 'string') {
166
     if (typeof newValue === 'string') {
140
       setTimeout(() => {
167
       setTimeout(() => {
141
         toggleOpenDialog(true);
168
         toggleOpenDialog(true);
142
         setDialogValue({
169
         setDialogValue({
143
           title: newValue,
170
           title: newValue,
144
-          year: '',
171
+          id: '',
145
         });
172
         });
146
       });
173
       });
147
     } else if (newValue && newValue.inputValue) {
174
     } else if (newValue && newValue.inputValue) {
148
       toggleOpenDialog(true);
175
       toggleOpenDialog(true);
149
       setDialogValue({
176
       setDialogValue({
150
         title: newValue.inputValue,
177
         title: newValue.inputValue,
151
-        year: '',
178
+        id: '',
152
       });
179
       });
153
     } else {
180
     } else {
154
       setDialogValue(newValue);
181
       setDialogValue(newValue);
166
   const formik = useFormik({
193
   const formik = useFormik({
167
     initialValues: {
194
     initialValues: {
168
       nombrepuesto: "",
195
       nombrepuesto: "",
169
-      puestosuperior: "",
196
+      puestosuperior: null,
170
       aredepto: 1,
197
       aredepto: 1,
171
       fecha: date,
198
       fecha: date,
172
       notas: "",
199
       notas: "",
265
               <TextField
292
               <TextField
266
                 margin="dense"
293
                 margin="dense"
267
                 id="name"
294
                 id="name"
268
-                value={dialogValue?.year}
295
+                value={dialogValue?.id}
269
                 onChange={(event) =>
296
                 onChange={(event) =>
270
                   setDialogValue({
297
                   setDialogValue({
271
                     ...dialogValue,
298
                     ...dialogValue,
272
-                    year: event.target.value,
299
+                    id: event.target.value,
273
                   })
300
                   })
274
                 }
301
                 }
275
                 label="Descripción"
302
                 label="Descripción"
386
                               setOptions([]);
413
                               setOptions([]);
387
                               setDialogValue({
414
                               setDialogValue({
388
                                 title: event.target.value,
415
                                 title: event.target.value,
389
-                                year: '',
416
+                                id: '',
390
                               });
417
                               });
391
                             },
418
                             },
392
                             endAdornment: (
419
                             endAdornment: (