Forráskód Böngészése

fix in service consum

amenpunk 3 éve
szülő
commit
491318b980

+ 77 - 31
src/Components/Modal/AgregarManual.js

@@ -3,36 +3,56 @@ import * as Yup from 'yup';
 import { useFormik, Form, FormikProvider } from 'formik';
 import { Modal } from 'react-bootstrap'
 
-import {  
-    Box, Button,
-    Stack, TextField, 
-    InputLabel,MenuItem,FormControl,Select
-} from '@mui/material';
+import DateFnsUtils from '@date-io/date-fns';
+import { DesktopDatePicker,LocalizationProvider } from '@mui/lab';
+import {  Button, Stack, TextField, } from '@mui/material';
 
+import { Service } from '../../Utils/HTTP';
+import  useAuth from '../../Auth/useAuth';
 
 
 export default function Manual ( props ) {
 
     const NewPlazaSchema = Yup.object().shape({
         nombrepuesto : Yup.string().required('El nombre es requerido').min(5).max(100),
-        puestosuperior : Yup.number("El puesto superior debe ser un numero"),
-        areadepto : Yup.number().required('Escoge alguna area'),
-        fecha : Yup.date("Ingresa una fecha válida").required('Ingresa una fecha válida'),
-        notas : Yup.string().required('Ingresa una fecha válida'),
+        puestosuperior : Yup.number("El puesto superior debe ser un número"),
+        aredepto : Yup.number().required('Escoge alguna área'),
+        fecha : Yup.date("Ingresa una fecha válida"),
+        notas : Yup.string("Ingresa una nota válida").min(5).max(150),
     })
 
+    const [date, setDate] = React.useState(new Date());
+    const auth = useAuth();
+    const token = auth.getToken();
+
     let { visible, onClose, success } = props
 
     const formik = useFormik({
         initialValues: {
-            nombrepuesto: "",
-            puestosuperior: "",
-            areadepto: "",
-            fecha: "",
-            notas: "",
+            nombrepuesto: "QA ENGINIER",
+            puestosuperior: 3,
+            aredepto: 1,
+            fecha: date,
+            notas: "alguna nota ",
         },
         onSubmit: (fields) => {
-            console.log(fields)
+            fields['fecha'] = "2023-06-11T00:22:15.211"//new Date(fields.fecha).toString() //getDate(fields.fecha);
+            fields['areadeptoplz_id'] = 1;
+            fields['id'] = -1;
+
+            console.log(fields);
+
+            let Rest = new Service('/plaza/save');
+
+            Rest
+            .post( fields, token )
+            .then(data => {
+                console.log('data ', data)
+            })
+            .catch(err => {
+                console.error(err)
+            })
+
         },
         validationSchema: NewPlazaSchema,
     });
@@ -54,7 +74,7 @@ export default function Manual ( props ) {
                             <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
 
                                 <TextField
-                                    label="Nombre: "
+                                    label="Nombre"
                                     fullWidth
                                     {...getFieldProps('nombrepuesto')}
                                     error={Boolean(touched.nombrepuesto && errors.nombrepuesto)}
@@ -62,7 +82,7 @@ export default function Manual ( props ) {
                                 />
 
                                 <TextField
-                                    label="Puesto Superior: "
+                                    label="Puesto Superior"
                                     fullWidth
                                     {...getFieldProps('puestosuperior')}
                                     error={Boolean(touched.puestosuperior && errors.puestosuperior)}
@@ -75,19 +95,32 @@ export default function Manual ( props ) {
                                     label="Departamento"
                                     fullWidth
                                     type="text"
-                                    {...getFieldProps('puestosuperior')}
-                                    error={Boolean(touched.areadepto && errors.areadepto)}
-                                    helperText={touched.areadepto && errors.areadepto}
-                                />
-                                <TextField
-                                    label="Fecha Creacion"
-                                    fullWidth
-                                    type="text"
-                                    {...getFieldProps('fecha')}
-                                    error={Boolean(touched.fecha && errors.fecha)}
-                                    helperText={touched.fecha && errors.fecha}
+                                    {...getFieldProps('aredepto')}
+                                    error={Boolean(touched.aredepto && errors.aredepto)}
+                                    helperText={touched.aredepto && errors.aredepto}
                                 />
+                                
+                                <LocalizationProvider 
+                                    dateAdapter={DateFnsUtils}>
+                                    <DesktopDatePicker
+                                        label="Fecha Creación"
+                                        fullWidth
+                                        inputFormat="dd/MM/yyyy"
+                                        {...getFieldProps('fecha')}
+                                        value={date}
+                                        onChange={setDate}
+                                        renderInput={(params) => 
+                                            <TextField 
+                                                disabled={true}
+                                                label="Fecha Creación"
+                                                fullWidth
+                                                {...params} 
+                                            />}
+                                    />
+                                </LocalizationProvider>
+
                             </Stack>
+
                             <Stack direction={{ xs: 'column', sm: 'row' }} spacing={1}>
                                 <TextField
                                     id="filled-multiline-static"
@@ -95,19 +128,32 @@ export default function Manual ( props ) {
                                     rows={4}
                                     defaultValue="Default Value"
                                     variant="filled"
-                                    label="notas"
+                                    label="Notas"
                                     fullWidth
                                     type="text"
                                     {...getFieldProps('notas')}
                                     error={Boolean(touched.notas && errors.notas)}
                                     helperText={touched.notas && errors.notas}
-                                />
+                                    />
                             </Stack>
                         </Stack>
+
+
+                        <Modal.Footer>
+                            <Button
+                                type="submit"
+                                className="registerBtn" 
+                                variant="contained"
+                                sx={{ mt: 1, mr: 1 }}
+                            >
+                                {'Guardar'}
+                            </Button>
+                        </Modal.Footer>
+
                     </Form>
                 </FormikProvider>
 
-                <Modal.Footer>OK</Modal.Footer>
+
 
             </Modal.Body>
         </Modal>

+ 2 - 1
src/Components/Register/PersonalInfo.js

@@ -60,7 +60,8 @@ export function PersonalInfo(props) {
 
             let req =  new Service('/registro');
 
-            req.post(body)
+            req
+            .post(body)
             .then( data => {
 
                 setTimeout(() => {

+ 11 - 15
src/Utils/HTTP.js

@@ -44,35 +44,31 @@ export class Service {
     async post(body, token){
 
         if(!token){
-            let response = await fetch(this.url, {
+            let response = await axios({
                 method: "POST",
+                url: this.url,
                 headers:{
                     'Content-Type': 'application/json',
                 },
-                body : JSON.stringify(body)
+                data :body
             })
-            return await response.json(); 
+            return await response.data; 
         }
 
 
         const MyHeaders ={
-            'Content-Type': 'application/json',
-            'Authorization': 'Bearer '+ token
+            'Authorization': 'Bearer '+ token,
         }
         
-        console.log('MY TOKEN ::', token)
-        console.log('MY URL ::', this.url)
-        console.log('MY HEADER ::', MyHeaders)
-
-        let response = await fetch(this.url, {
-            credentials: 'include',
+        let response = await axios({
             method: "POST",
-            mode: 'cors',
-            cache: 'default',
+            url : this.url,
             headers: MyHeaders,
-            body : JSON.stringify(body)
+            data: body
         })
-        return await response.json(); 
+        console.log('response', response)
+
+        return await response.data; 
 
     }