Browse Source

update pwd

amenpunk 2 years ago
parent
commit
e2405f82fc
1 changed files with 90 additions and 50 deletions
  1. 90 50
      src/Components/Password/Operation.jsx

+ 90 - 50
src/Components/Password/Operation.jsx

4
 import {
4
 import {
5
     Button, Dialog, DialogActions, DialogContent, DialogTitle,
5
     Button, Dialog, DialogActions, DialogContent, DialogTitle,
6
     FormControlLabel, Checkbox,
6
     FormControlLabel, Checkbox,
7
-    Autocomplete, TextField, Stack,
7
+    TextField, Stack,
8
+    //Autocomplete
8
 } from '@mui/material'
9
 } from '@mui/material'
9
 
10
 
11
+import toast, { Toaster } from 'react-hot-toast';
12
+
13
+
14
+
10
 import * as Yup from 'yup';
15
 import * as Yup from 'yup';
11
 
16
 
12
 import { useQuery } from 'react-query'
17
 import { useQuery } from 'react-query'
18
 import DateFnsUtils from '@date-io/date-fns';
23
 import DateFnsUtils from '@date-io/date-fns';
19
 import { DesktopDatePicker, LocalizationProvider } from '@mui/lab';
24
 import { DesktopDatePicker, LocalizationProvider } from '@mui/lab';
20
 
25
 
26
+// function getNombrePuesto(id_plaz, puestos){
27
+//     let nombre = "";
28
+//     puestos.forEach(( p) => {
29
+//         if(p.id === id_plaz){
30
+//             nombre = p.nombrepuesto;
31
+//         }
32
+//     })
33
+//     return nombre;
34
+// }
35
+//
21
 
36
 
22
 export function Operation(props) {
37
 export function Operation(props) {
23
 
38
 
56
     }
71
     }
57
 
72
 
58
     let { data: result } = useQuery('contra', getPassword);
73
     let { data: result } = useQuery('contra', getPassword);
59
-    console.log('DATA:',result)
74
+
75
+    // const getPuestos = async () => {
76
+    //     let rest = new Service('/plaza/getall')
77
+    //     return rest.getQuery(token);
78
+    // }
79
+    //
80
+    // let { data } = useQuery('puestos', getPuestos)
81
+    // let puestos = data ? data.data.map(({ nombrepuesto, id }) => ({ nombrepuesto, id })) : []
82
+
60
 
83
 
61
     let initialValues = {
84
     let initialValues = {
62
         id: result?.data?.id,
85
         id: result?.data?.id,
63
         pwd: result?.data?.pwd,
86
         pwd: result?.data?.pwd,
64
         deadpwd: result?.data?.deadpwd ? new Date(result?.data?.deadpwd) : now.current,
87
         deadpwd: result?.data?.deadpwd ? new Date(result?.data?.deadpwd) : now.current,
65
         state: result?.data?.state,
88
         state: result?.data?.state,
66
-        dateToActived: 
67
-        result?.data.dateToActived ? new Date(result?.data?.dateToActived) : now.current,
68
-        plaza_id: result?.data?.plaza_id,
89
+        dateToActived:
90
+            result?.data.dateToActived ? new Date(result?.data?.dateToActived) : now.current,
91
+        // plaza_id: [{ id:result?.data?.plaza_id, }]
69
     }
92
     }
70
 
93
 
71
     return (
94
     return (
79
                 {pwd}
102
                 {pwd}
80
             </DialogTitle>
103
             </DialogTitle>
81
             <DialogContent>
104
             <DialogContent>
82
-                <ModalForm initialValues={initialValues} />
105
+                <ModalForm
106
+                    initialValues={initialValues}
107
+                    handleOpen={handleOpen}
108
+                />
83
             </DialogContent>
109
             </DialogContent>
84
-            <DialogActions>
85
-                <Button onClick={() => handleOpen(false)} autoFocus>
86
-                    Salir
87
-                </Button>
88
-                <Button onClick={() => handleOpen(false)}>Guardar</Button>
89
-            </DialogActions>
90
         </Dialog>
110
         </Dialog>
91
     )
111
     )
92
 }
112
 }
93
 
113
 
94
 function ModalForm(props) {
114
 function ModalForm(props) {
95
 
115
 
96
-    const auth = useAuth();
97
-    const token = auth.getToken();
98
-
99
-    const getPuestos = async () => {
100
-        let rest = new Service('/plaza/getall')
101
-        return rest.getQuery(token);
102
-    }
103
-
104
-    let { data } = useQuery('puestos', getPuestos)
105
-    let puestos = data ? data.data.map(({ nombrepuesto, id }) => ({ nombrepuesto, id })) : []
106
-    // console.log('puestos: ', puestos)
107
 
116
 
108
     const pwdSchema = Yup.object().shape({
117
     const pwdSchema = Yup.object().shape({
109
         id: Yup.number(),
118
         id: Yup.number(),
110
-        pwd: Yup.string().required(),
111
-        deadpwd: Yup.date(),
112
-        state: Yup.number().required(),
113
-        dateToActived: Yup.date().required(),
114
-        plaza_id: Yup.number().required()
119
+        pwd: Yup.string().required("Escoge un nombre valido"),
120
+        deadpwd: Yup.date().required("Escoge una fecha valida"),
121
+        state: Yup.number(),
122
+        dateToActived: Yup.date('Escoge una fecha valida').required("Escoge una fecha valida"),
123
+        // plaza_id: Yup.array().required("Escoge una plaza valida")
115
     })
124
     })
116
 
125
 
117
 
126
 
118
     const formik = useFormik({
127
     const formik = useFormik({
119
         initialValues: {
128
         initialValues: {
120
-            state:1,
121
-            ...props.initialValues,
129
+            state: 1,
130
+            pwd:"",
131
+            deadpwd:"",
132
+            dateToActived:"",
133
+            // plaza_id:[]
122
         },
134
         },
123
         onSubmit: (fields) => {
135
         onSubmit: (fields) => {
124
             console.log('campos> ', fields)
136
             console.log('campos> ', fields)
137
+            toast.success("Contraseña Actualizada")
138
+            setTimeout(()=>{
139
+                props.handleOpen(false)
140
+            },1000)
125
         },
141
         },
126
         validationSchema: pwdSchema,
142
         validationSchema: pwdSchema,
127
     })
143
     })
128
 
144
 
129
     const { errors, touched, handleSubmit, getFieldProps, values, setValues } = formik;
145
     const { errors, touched, handleSubmit, getFieldProps, values, setValues } = formik;
130
 
146
 
131
-    React.useEffect(() =>{
132
-        setValues({ ...props.initialValues})
133
-    },[props, setValues] )
147
+    React.useEffect(() => {
148
+        setValues({ ...props.initialValues })
149
+    }, [props, setValues])
134
 
150
 
135
     return (
151
     return (
136
         <FormikProvider value={formik}>
152
         <FormikProvider value={formik}>
137
-            <Form style={{ padding: 15, maxWidth: 450 }} autoComplete="off" noValidate onSubmit={handleSubmit}>
153
+            <Form style={{ padding: 20, maxWidth: 450 }} autoComplete="off" noValidate onSubmit={handleSubmit}>
138
                 <Stack spacing={4}>
154
                 <Stack spacing={4}>
139
 
155
 
140
-                    <Stack direction={{ xs: 'column', sm: 'row' }} spacing={1}>
156
+                    <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
157
+
141
                         <TextField
158
                         <TextField
142
-                            focused
143
                             fullWidth
159
                             fullWidth
144
                             type="text"
160
                             type="text"
145
                             label="Contraseña"
161
                             label="Contraseña"
151
                         <FormControlLabel
167
                         <FormControlLabel
152
                             control={
168
                             control={
153
                                 <Checkbox
169
                                 <Checkbox
154
-                                checked={values.state  === 1 }
155
-                                onChange={(event)=>{
156
-                                    let check = event.target.checked;
157
-                                    setValues({
158
-                                        state : check ? 1:0
159
-                                    })
160
-                                }}
170
+                                    checked={values.state === 1}
171
+                                    onChange={(event) => {
172
+                                        let check = event.target.checked;
173
+                                        setValues({
174
+                                            ...values,
175
+                                            state: check ? 1 : 0
176
+                                        })
177
+                                    }}
161
                                 />
178
                                 />
162
                             }
179
                             }
163
                             label="Activa"
180
                             label="Activa"
172
                             label="Fecha de Activación"
189
                             label="Fecha de Activación"
173
                             fullWidth
190
                             fullWidth
174
                             inputFormat="dd/MM/yyyy"
191
                             inputFormat="dd/MM/yyyy"
175
-                            {...getFieldProps('dateToActived')}
176
                             value={values.dateToActived}
192
                             value={values.dateToActived}
177
-                            onChange={(val) => setValues({ ...values, dateToActived: new Date(val) })
178
-                            }
193
+                            onChange={(val) => setValues({ ...values, dateToActived: val }) }
179
                             renderInput={(params) =>
194
                             renderInput={(params) =>
180
                                 <TextField
195
                                 <TextField
196
+                                    {...getFieldProps('dateToActived')}
181
                                     error={Boolean(touched.dateToActived && errors.dateToActived)}
197
                                     error={Boolean(touched.dateToActived && errors.dateToActived)}
182
                                     helperText={touched.dateToActived && errors.dateToActived}
198
                                     helperText={touched.dateToActived && errors.dateToActived}
183
                                     disabled={true}
199
                                     disabled={true}
210
                         />
226
                         />
211
                     </LocalizationProvider>
227
                     </LocalizationProvider>
212
 
228
 
213
-                    
229
+
230
+                        {/*
214
                     <Autocomplete
231
                     <Autocomplete
215
                         id="combo-box-demo"
232
                         id="combo-box-demo"
216
-                        options={puestos}
217
-                        isOptionEqualToValue={(option, value) => option.nombrepuesto === value.nombrepuesto}
233
+                        options={props.puestos}
234
+                        isOptionEqualToValue={
235
+                            (option, value) => option.nombrepuesto === value.nombrepuesto
236
+                        }
218
                         getOptionLabel={(option) => {
237
                         getOptionLabel={(option) => {
219
                             return option.nombrepuesto
238
                             return option.nombrepuesto
220
                         }}
239
                         }}
240
+                        onChange={(_e, newValue) => {
241
+                            console.log('CHANGE',newValue);
242
+                            setValues({
243
+                                ...values,
244
+                                plaza_id:newValue
245
+                            })
246
+                        }}
221
                         renderInput={(params) =>
247
                         renderInput={(params) =>
222
                             <TextField
248
                             <TextField
223
                                 {...params}
249
                                 {...params}
225
                             />
251
                             />
226
                         }
252
                         }
227
                     />
253
                     />
228
-
254
+*/}
255
+
256
+                    <DialogActions>
257
+                        <Button onClick={() => props.handleOpen(false)}>
258
+                            Cerrar
259
+                        </Button>
260
+                        <Button
261
+                            type="submit"
262
+                            className="registerBtn"
263
+                            style={{ color: 'white' }}
264
+                            >
265
+                            Guardar
266
+                        </Button>
267
+                    </DialogActions>
229
 
268
 
230
                 </Stack>
269
                 </Stack>
231
             </Form>
270
             </Form>
271
+            <Toaster position="bottom-right" />
232
         </FormikProvider >
272
         </FormikProvider >
233
     )
273
     )
234
 
274