Explorar el Código

edit modal first effects

amenpunk hace 2 años
padre
commit
6f94025b78
Se han modificado 2 ficheros con 147 adiciones y 16 borrados
  1. 147 14
      src/Components/Password/Operation.jsx
  2. 0 2
      src/Components/Password/Steps/password.jsx

+ 147 - 14
src/Components/Password/Operation.jsx

@@ -6,10 +6,20 @@ import {
6 6
     DialogContentText, DialogTitle
7 7
 } from '@mui/material'
8 8
 
9
+import * as Yup from 'yup';
10
+
9 11
 import { useQuery } from 'react-query'
10 12
 import { Service } from '../../Utils/HTTP.js'
11 13
 import useAuth from '../../Auth/useAuth.js';
12 14
 
15
+import { useFormik, Form, FormikProvider } from 'formik';
16
+
17
+import { Stack, TextField } from '@mui/material';
18
+
19
+import DateFnsUtils from '@date-io/date-fns';
20
+import { DesktopDatePicker, LocalizationProvider } from '@mui/lab';
21
+
22
+
13 23
 export function Operation(props) {
14 24
 
15 25
     let [open, setOpen] = React.useState(false);
@@ -22,13 +32,13 @@ export function Operation(props) {
22 32
                 <SendIcon className="icon_op" />
23 33
             </div>
24 34
             {
25
-                open ? 
26
-                <ModalEdit 
27
-                    password={props}
28
-                    open={open}
29
-                    handleOpen={handleOpen}
30
-                    /> 
31
-                : null
35
+                open ?
36
+                    <ModalEdit
37
+                        password={props}
38
+                        open={open}
39
+                        handleOpen={handleOpen}
40
+                    />
41
+                    : null
32 42
             }
33 43
         </div>
34 44
     )
@@ -36,7 +46,7 @@ export function Operation(props) {
36 46
 
37 47
 function ModalEdit(props) {
38 48
 
39
-    let { password, open, handleOpen} = props
49
+    let { password, open, handleOpen } = props
40 50
     let { pwd, plz } = password
41 51
     const auth = useAuth();
42 52
     const token = React.useRef(auth.getToken());
@@ -45,9 +55,16 @@ function ModalEdit(props) {
45 55
         return await rest.getQuery(token.current)
46 56
     }
47 57
 
48
-    let { data, status, } = useQuery('contra', getPassword);
49
-    console.log(data, status)
58
+    let { data: result } = useQuery('contra', getPassword);
50 59
 
60
+    let initialValues = {
61
+        id: result?.data?.id,
62
+        pwd: result?.data?.pwd,
63
+        deadpwd: result?.data?.deadpwd,
64
+        state: result?.data?.state,
65
+        dateToActived: result?.data?.dateToActived,
66
+        plaza_id: result?.data?.plaza_id,
67
+    }
51 68
 
52 69
     return (
53 70
         <Dialog
@@ -61,18 +78,134 @@ function ModalEdit(props) {
61 78
             </DialogTitle>
62 79
             <DialogContent>
63 80
                 <DialogContentText id="alert-dialog-description">
64
-                    Let Google help apps determine location. This means sending anonymous
65
-                    location data to Google, even when no apps are running.
81
+                    <ModalForm initialValues={initialValues} />
66 82
                 </DialogContentText>
67 83
             </DialogContent>
68 84
             <DialogActions>
69
-                <Button onClick={() => handleOpen(false)}>Disagree</Button>
70 85
                 <Button onClick={() => handleOpen(false)} autoFocus>
71
-                    Agree
86
+                    Salir
72 87
                 </Button>
88
+                <Button onClick={() => handleOpen(false)}>Guardar</Button>
73 89
             </DialogActions>
74 90
         </Dialog>
75 91
     )
76 92
 }
77 93
 
94
+function ModalForm(props) {
95
+    console.log("PROPS >> ", props)
96
+
97
+    const pwdSchema = Yup.object().shape({
98
+        id: Yup.number(),
99
+        pwd: Yup.string().required(),
100
+        deadpwd: Yup.date(),
101
+        state: Yup.number().required(),
102
+        dateToActived: Yup.date().required(),
103
+        plaza_id: Yup.number().required()
104
+    })
105
+
106
+
107
+    const formik = useFormik({
108
+        initialValues: props.initialValues,
109
+        onSubmit: (fields) => {
110
+            console.log('campos> ', fields)
111
+        },
112
+        validationSchema: pwdSchema,
113
+    })
114
+
115
+    const { errors, touched, handleSubmit, getFieldProps, values, setValues } = formik;
116
+    console.log('formik values >> ', values )
117
+
118
+    return (
119
+        <FormikProvider  value={formik}>
120
+            <Form style={{padding : 15,minWidth:450}} autoComplete="off" noValidate onSubmit={handleSubmit}>
121
+                <Stack spacing={4}>
122
+
123
+                    <TextField
124
+                        fullWidth
125
+                        type="text"
126
+                        label="Nombre o identificador"
127
+                        {...getFieldProps('pwd')}
128
+                        error={Boolean(touched.pwd && errors.pwd)}
129
+                        helperText={touched.pwd && errors.pwd}
130
+                    />
131
+                    
132
+
133
+                    <TextField
134
+                        fullWidth
135
+                        type="text"
136
+                        label="Nombre o identificador"
137
+                        {...getFieldProps('pwd')}
138
+                        error={Boolean(touched.pwd && errors.pwd)}
139
+                        helperText={touched.pwd && errors.pwd}
140
+                    />
141
+
142
+                    <TextField
143
+                        fullWidth
144
+                        type="text"
145
+                        label="Nombre o identificador"
146
+                        {...getFieldProps('pwd')}
147
+                        error={Boolean(touched.pwd && errors.pwd)}
148
+                        helperText={touched.pwd && errors.pwd}
149
+                    />
150
+                    
151
+                    <TextField
152
+                        fullWidth
153
+                        type="text"
154
+                        label="Nombre o identificador"
155
+                        {...getFieldProps('pwd')}
156
+                        error={Boolean(touched.pwd && errors.pwd)}
157
+                        helperText={touched.pwd && errors.pwd}
158
+                    />
159
+
160
+                        <LocalizationProvider
161
+                            dateAdapter={DateFnsUtils}>
162
+                            <DesktopDatePicker
163
+                                label="Fecha de Activación"
164
+                                fullWidth
165
+                                inputFormat="dd/MM/yyyy"
166
+                                {...getFieldProps('dateToActived')}
167
+                                value={values.dateToActived}
168
+                                onChange={(val) => setValues({ ...values, dateToActived: new Date(val) })
169
+                                }
170
+                                renderInput={(params) =>
171
+                                    <TextField
172
+                                        error={Boolean(touched.dateToActived && errors.dateToActived)}
173
+                                        helperText={touched.dateToActived && errors.dateToActived}
174
+                                        disabled={true}
175
+                                        label="Fecha de Activación"
176
+                                        fullWidth
177
+                                        {...params}
178
+                                        />}
179
+                                />
180
+                        </LocalizationProvider>
181
+
182
+                        <LocalizationProvider
183
+                            dateAdapter={DateFnsUtils}>
184
+                            <DesktopDatePicker
185
+                                label="Fecha de Vencimiento"
186
+                                fullWidth
187
+                                inputFormat="dd/MM/yyyy"
188
+                                {...getFieldProps('deadpwd')}
189
+                                value={values.deadpwd}
190
+                                onChange={(val) => setValues({ ...values, deadpwd: new Date(val) })
191
+                                }
192
+                                renderInput={(params) =>
193
+                                    <TextField
194
+                                        error={Boolean(touched.deadpwd && errors.deadpwd)}
195
+                                        helperText={touched.deadpwd && errors.deadpwd}
196
+                                        disabled={true}
197
+                                        label="Fecha de Vencimiento"
198
+                                        fullWidth
199
+                                        {...params}
200
+                                        />}
201
+                                />
202
+                        </LocalizationProvider>
203
+
204
+
205
+                </Stack>
206
+            </Form>
207
+        </FormikProvider >
208
+    )
209
+
210
+}
78 211
 

+ 0 - 2
src/Components/Password/Steps/password.jsx

@@ -33,7 +33,6 @@ export function Password(props) {
33 33
             dateToActived: password.dateToActived,
34 34
         },
35 35
         onSubmit: (fields) => {
36
-            console.log('PASS::::',fields)
37 36
             fields['deadpwd'] = new Date(fields.deadpwd).toISOString();
38 37
             fields['dateToActived'] = new Date(fields.dateToActived).toISOString();
39 38
             setPassword({
@@ -51,7 +50,6 @@ export function Password(props) {
51 50
         <FormikProvider style={{ padding : 25, paddingTop : 5 }} value={formik}>
52 51
             <Form autoComplete="off" noValidate onSubmit={handleSubmit}>
53 52
                 <Stack spacing={3}>
54
-
55 53
                     <TextField
56 54
                         fullWidth
57 55
                         type="text"