ソースを参照

using namespace std

amenpunk 3 年 前
コミット
d31303dd73
3 ファイル変更29 行追加20 行削除
  1. 25 17
      src/Components/Modal/EditPlaza.js
  2. 1 1
      src/Pages/Puestos.jsx
  3. 3 2
      src/temp.js

+ 25 - 17
src/Components/Modal/EditPlaza.js

@@ -27,17 +27,16 @@ const plazeSchema = Yup.object({
   .min(5, "El nombre del  puesto debe ser mayor a 5 caracteres")
   .max(100),
   puestosuperior: Yup.number("El puesto superior debe ser un número").required("El puesto es requerido"),
-  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),
+  aredepto: Yup.number('El área debe ser un número').required('Escoge alguna área'),
+  fecha: Yup.date("Ingresa una fecha válida").required(),
+  notas: Yup.string("Ingresa una nota válida").min(5, "Ingresa una nota mayor a 5").max(150, "Ingresa una nota menor a 150 caracteres"),
   tests: Yup.array()
 }).required();
 
 
 function Edit(props) {
 
-  const {
-    reset,control,register, handleSubmit, formState: { errors } } = useForm({
+  const { setValue,getValues,reset,control,register, handleSubmit, formState: { errors } } = useForm({
     resolver : yupResolver(plazeSchema),
     defaultValues: {
       nombrepuesto: 'mingtest',
@@ -45,6 +44,7 @@ function Edit(props) {
       fecha: '01/01/2019',
       notas: 'esto es un ejemplod e una nota',
       aredepto : 1,
+      tests : []
     }
   });
 
@@ -62,7 +62,8 @@ function Edit(props) {
   const [checklist, setChecklist] = React.useState([]);
 
   const addPrueba = (check,id) => {
-    let { tests } = { tests : []}
+    let tests = getValues("tests")
+    console.log(tests)
     let temp ;
     if(check){
       temp = [...tests, {id}]
@@ -70,7 +71,8 @@ function Edit(props) {
       temp = tests.filter( test => test.id !== id);
     }
     setChecklist(temp.map( test => test.id) )
-    // setValues({...values, tests: temp})
+    setValue('tests', temp)
+    // setValue({...values, tests: temp})
   };
 
   const getCategories = async () => {
@@ -101,17 +103,16 @@ function Edit(props) {
     rest
       .getQuery(auth.token)
       .then( response => {
-        let { areadeptoplz_id, fecha } = response.data;
-        reset({...response.data, areadepto : areadeptoplz_id, fecha : new Date(fecha)  })
+        console.log(response.data)
+        let { areadeptoplz_id, fecha, tests } = response.data;
+        let temp_test = tests.map( t => ({ id : t.id} ))
+        setChecklist(temp_test.map( t => t.id))
+        reset({...response.data, areadepto : areadeptoplz_id, fecha : new Date(fecha) , tests : temp_test  })
       })
       .catch(console.log)
   },[visible])
 
-  console.log("RENDER", props)
-
-  const changeTab = (_event, newValue) => {
-    setTab(newValue);
-  };
+  const changeTab = (_event, newValue) => setTab(newValue);
 
   return (
 
@@ -170,6 +171,8 @@ function Edit(props) {
                   name="puestosuperior"
                   label="Puesto superior"
                   fullWidth
+                  helperText={errors.puestosuperior?.message}
+                  error={Boolean(errors?.puestosuperior)}
                   {...register("puestosuperior")} />
 
               </Stack>
@@ -179,6 +182,8 @@ function Edit(props) {
                 <FormControl fullWidth>
                   <InputLabel>Departamento</InputLabel>
                   <Controller
+                    helperText={errors.areadepto?.message}
+                    error={Boolean(errors?.areadepto)}
                     name="aredepto"
                     control={control}
                     render={ ({field}) =>
@@ -204,18 +209,21 @@ function Edit(props) {
                     render={({field}) => 
                       <DesktopDatePicker
                         {...field}
+                        helperText={errors.fecha?.message}
+                        error={Boolean(errors?.fecha)}
                         label="Fecha Creación"
                         fullWidth
                         inputFormat="dd/MM/yyyy"
-                        renderInput={(params) => <TextField {...params} />}
-                        />
-                  } >
+                        renderInput={(params) => <TextField {...params}  helperText={errors.fecha?.message} />} /> } 
+                      >
                   </Controller>
                 </LocalizationProvider>
               </Stack>
 
               <Stack direction={{ xs: 'column', sm: 'row' }} spacing={1}>
                 <TextField
+                  helperText={errors.notas?.message}
+                  error={Boolean(errors?.notas)}
                   name="notas"
                   multiline
                   rows={4}

+ 1 - 1
src/Pages/Puestos.jsx

@@ -69,7 +69,7 @@ export function Puestos() {
   let [show, setShow] = React.useState(null);
 
   const toggle = useCallback((type, puesto) => {
-    console.log('usecall: ',puesto)
+   // console.log('usecall: ',puesto)
     // setPuesto(puesto)
     switch (type) {
       case "VER": {

+ 3 - 2
src/temp.js

@@ -36,7 +36,7 @@ const NewPlazaSchema = Yup.object().shape({
 
 function Edit(props) {
 
-  const { control,register, handleSubmit, watch, formState: { errors } } = useForm({
+  const { getValues ,control,register, handleSubmit, watch, formState: { errors } } = useForm({
     defaultValues: {
       departamento: 1,
     }
@@ -64,7 +64,8 @@ function Edit(props) {
   const [checklist, setChecklist] = React.useState([]);
 
   const addPrueba = (check,id) => {
-    let { tests } = { tests : []}
+    let { tests } = getValues("tests")
+    console.log(tests);
     let temp ;
     if(check){
       temp = [...tests, {id}]