浏览代码

modal edit user

amenpunk 2 年之前
父节点
当前提交
0e4af8830e
共有 2 个文件被更改,包括 262 次插入102 次删除
  1. 258 97
      src/Components/Password/Operation.jsx
  2. 4 5
      src/Components/Password/Rows.js

+ 258 - 97
src/Components/Password/Operation.jsx

@@ -1,10 +1,15 @@
1 1
 import * as React from 'react';
2 2
 import {
3 3
   Button, Dialog, DialogActions, DialogContent,
4
-  FormControlLabel, Checkbox,
5
-  TextField, Stack,
4
+  FormControlLabel, Checkbox, Box, Stack,
5
+  TextField,CircularProgress
6 6
 } from '@mui/material'
7 7
 
8
+import { AddCircle } from '@mui/icons-material/';
9
+import { MailTable } from './Steps/MailTable';
10
+
11
+import { Col, Row } from 'react-bootstrap'
12
+
8 13
 import toast, { Toaster } from 'react-hot-toast';
9 14
 import * as Yup from 'yup';
10 15
 
@@ -17,14 +22,150 @@ import { AdapterDateFns as DateFnsUtils } from '@mui/x-date-pickers/AdapterDateF
17 22
 import { DesktopDatePicker } from '@mui/x-date-pickers/DesktopDatePicker';
18 23
 import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
19 24
 
25
+
26
+function Candidatos(props){
27
+
28
+  const CandidatoSchema = Yup.object().shape({
29
+    nombres:
30
+      Yup.string()
31
+        .min(2, 'Demasiado corto!')
32
+        .max(50, 'Demasiado largo!'),
33
+    apellidos:
34
+      Yup.string()
35
+        .min(2, 'Demasiado corto!').max(50, 'Demasiado Largo!'),
36
+    mail:
37
+      Yup.string()
38
+        .email("Correo no valido")
39
+  });
40
+
41
+  let [password, setPassword] = React.useState([]);
42
+
43
+  let { candidatos } = props
44
+  console.log('operation props candidatos', candidatos)
45
+
46
+  const formik = useFormik({
47
+    initialValues: {
48
+      nombres: "",
49
+      apellidos: "",
50
+      mail: "",
51
+    },
52
+    onSubmit: () => {
53
+      if(password.length <= 0){
54
+        toast.error("Seleciona almenos un destino")
55
+        return;
56
+      }
57
+      console.log('submited')
58
+    },
59
+    validationSchema: CandidatoSchema,
60
+  });
61
+
62
+  const { errors, touched, handleSubmit, getFieldProps, values, resetForm,isValid } = formik;
63
+
64
+  const addToList = () => {
65
+
66
+    if(!values.nombres || !values.apellidos || !values.mail){
67
+      return toast.error("Completa la informacion del candidato")
68
+    }
69
+
70
+    if(!isValid) {
71
+      return toast.error("Completa la informacion del candidato")
72
+    }
73
+
74
+    let user = {
75
+      'nombres': values.nombres,
76
+      'apellidos': values.apellidos,
77
+      'mail': values.mail,
78
+    }
79
+    let new_users = [...password.candidatos, user ]
80
+
81
+    setPassword({...candidatos, candidatos: new_users })
82
+    resetForm();
83
+
84
+  }
85
+
86
+  const removeFromList = (umail) => {
87
+    let without = password.candidatos.filter( user => user.mail !== umail )
88
+    setPassword({...password, candidatos: without })
89
+  }
90
+
91
+  return (
92
+    <FormikProvider style={{ padding: 25 }} value={formik}>
93
+      <Form autoComplete="off" noValidate onSubmit={handleSubmit}>
94
+        <Stack spacing={3}>
95
+          <Stack style={{paddingTop: 15}} direction={{ xs: 'column', sm: 'row' }} spacing={2}>
96
+            <TextField
97
+              label="Nombre"
98
+              fullWidth
99
+              {...getFieldProps('nombres')}
100
+              error={Boolean(touched.nombres && errors.nombres)}
101
+              helperText={touched.nombres && errors.nombres}
102
+            />
103
+
104
+            <TextField
105
+              label="Apellidos"
106
+              fullWidth
107
+              {...getFieldProps('apellidos')}
108
+              error={Boolean(touched.apellidos && errors.apellidos)}
109
+              helperText={touched.apellidos && errors.apellidos}
110
+            />
111
+          </Stack>
112
+
113
+          <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
114
+            <TextField
115
+              fullWidth
116
+              type="email"
117
+              label="Correo Electronico"
118
+              {...getFieldProps('mail')}
119
+              error={Boolean(touched.mail && errors.mail)}
120
+              helperText={touched.mail && errors.mail}
121
+            />
122
+
123
+            <Button onClick={addToList}>
124
+              <AddCircle style={{color:'var(--main)'}}/>
125
+            </Button>
126
+
127
+          </Stack>
128
+
129
+          <MailTable 
130
+            remove={removeFromList} 
131
+            users={candidatos}
132
+            />
133
+
134
+          <Box sx={{ mb: 2 }}>
135
+            <div style={{ paddingTop: 15 }}>
136
+              <Button
137
+                type="submit"
138
+                className="registerBtn"
139
+                variant="contained"
140
+                sx={{ mt: 1, mr: 1 }}
141
+              >
142
+                {'Siguiente'}
143
+              </Button>
144
+              <Button
145
+                disabled={false}
146
+                onClick={() => console.log('regresar')}
147
+                sx={{ mt: 1, mr: 1 }}
148
+              >
149
+                Regresar
150
+              </Button>
151
+            </div>
152
+          </Box>
153
+
154
+        </Stack>
155
+        <Toaster position="top-right" />
156
+      </Form>
157
+    </FormikProvider>
158
+  );
159
+}
160
+
20 161
 export function ModalEdit(props) {
21 162
 
22 163
   const auth = useSelector((state) => state.token)
23
-  let [data,setData] = React.useState(null)
164
+  let [data, setData] = React.useState(null)
24 165
   let { password, open, handleOpen } = props
25 166
   let { pwd, plz } = password
26 167
 
27
-  React.useEffect(()=> {
168
+  React.useEffect(() => {
28 169
 
29 170
     const getPassword = async () => {
30 171
       let rest = new Service(`/contrasenia/${btoa(pwd)}/${plz}`)
@@ -32,12 +173,14 @@ export function ModalEdit(props) {
32 173
     }
33 174
 
34 175
     getPassword()
35
-      .then( resp => setData(resp.data))
36
-      .catch( error => console.log(error))
37
-  },[auth.token,pwd,plz])
176
+      .then(resp => setData(resp.data))
177
+      .catch(error => console.log(error))
178
+  }, [auth.token, pwd, plz])
38 179
 
39 180
   return (
40 181
     <Dialog
182
+      fullWidth="md"
183
+      maxWidth="md"
41 184
       open={open}
42 185
       onClose={() => handleOpen(false)}
43 186
       aria-labelledby="alert-dialog-title"
@@ -50,13 +193,19 @@ export function ModalEdit(props) {
50 193
               password={data}
51 194
               handleOpen={handleOpen}
52 195
               token={auth.token}
53
-            />  : <h1>loding...</h1>
196
+            /> : <Loading />
54 197
         }
55 198
       </DialogContent>
56 199
     </Dialog>
57 200
   )
58 201
 }
59 202
 
203
+function Loading() {
204
+  return (
205
+    <CircularProgress style={{ color: 'var(--main)' }} />
206
+  )
207
+}
208
+
60 209
 function ModalForm(props) {
61 210
 
62 211
   const pwdSchema = Yup.object().shape({
@@ -69,11 +218,17 @@ function ModalForm(props) {
69 218
 
70 219
   const queryClient = useQueryClient();
71 220
   let { password } = props
221
+  console.log("227 PWD: ", password)
222
+
223
+  let candidatos = password.candidatospwds.map( pwd => {
224
+    let { apellidos, nombre,mail} = pwd.candi
225
+    return { nombres: nombre, apellidos, mail }
226
+  })
72 227
 
73 228
   const formik = useFormik({
74 229
     initialValues: {
75 230
       state: 1,
76
-      pwd: atob( password.pwd),
231
+      pwd: atob(password.pwd),
77 232
       deadpwd: password.deadpwd,
78 233
       dateToActived: password.dateToActived,
79 234
     },
@@ -108,106 +263,112 @@ function ModalForm(props) {
108 263
   const { errors, touched, handleSubmit, getFieldProps, values, setValues } = formik;
109 264
 
110 265
   return (
111
-    <FormikProvider value={formik}>
112
-      <Form style={{ padding: 20, maxWidth: 950 }} autoComplete="off" noValidate onSubmit={handleSubmit}>
113
-        <Stack spacing={4}>
114
-          <TextField
115
-            value={btoa(values.pwd)}
116
-            variant="filled"
117
-            disabled
118
-            fullWidth
119
-            type="text"
120
-            label="Contraseña Cifrada"
121
-          />
266
+    <Row>
267
+      <Col>
268
+        <FormikProvider value={formik}>
269
+          <Form style={{ padding: 20, maxWidth: 950 }} autoComplete="off" noValidate onSubmit={handleSubmit}>
270
+            <Stack spacing={4}>
271
+              <TextField
272
+                value={btoa(values.pwd)}
273
+                variant="filled"
274
+                disabled
275
+                fullWidth
276
+                type="text"
277
+                label="Contraseña Cifrada"
278
+              />
122 279
 
123
-          <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
280
+              <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
124 281
 
125
-            <TextField
126
-              type="text"
127
-              label="Contraseña"
128
-              {...getFieldProps('pwd')}
129
-              error={Boolean(touched.pwd && errors.pwd)}
130
-              helperText={touched.pwd && errors.pwd}
131
-            />
282
+                <TextField
283
+                  type="text"
284
+                  label="Contraseña"
285
+                  {...getFieldProps('pwd')}
286
+                  error={Boolean(touched.pwd && errors.pwd)}
287
+                  helperText={touched.pwd && errors.pwd}
288
+                />
132 289
 
133
-            <FormControlLabel
134
-              control={
135
-                <Checkbox
136
-                  checked={values.state === 1}
137
-                  onChange={(event) => {
138
-                    let check = event.target.checked;
139
-                    setValues({
140
-                      ...values,
141
-                      state: check ? 1 : 0
142
-                    })
143
-                  }}
290
+                <FormControlLabel
291
+                  control={
292
+                    <Checkbox
293
+                      checked={values.state === 1}
294
+                      onChange={(event) => {
295
+                        let check = event.target.checked;
296
+                        setValues({
297
+                          ...values,
298
+                          state: check ? 1 : 0
299
+                        })
300
+                      }}
301
+                    />
302
+                  }
303
+                  label="Activa"
144 304
                 />
145
-              }
146
-              label="Activa"
147
-            />
148
-          </Stack>
305
+              </Stack>
149 306
 
150 307
 
151
-          <LocalizationProvider
152
-            dateAdapter={DateFnsUtils}>
153
-            <DesktopDatePicker
154
-              label="Fecha de Activación"
155
-              fullWidth
156
-              inputFormat="dd/MM/yyyy"
157
-              value={values.dateToActived}
158
-              onChange={(val) => setValues({ ...values, dateToActived: val })}
159
-              renderInput={(params) =>
160
-                <TextField
161
-                  {...getFieldProps('dateToActived')}
162
-                  error={Boolean(touched.dateToActived && errors.dateToActived)}
163
-                  helperText={touched.dateToActived && errors.dateToActived}
164
-                  disabled={true}
308
+              <LocalizationProvider
309
+                dateAdapter={DateFnsUtils}>
310
+                <DesktopDatePicker
165 311
                   label="Fecha de Activación"
166 312
                   fullWidth
167
-                  {...params}
168
-                />}
169
-            />
170
-          </LocalizationProvider>
313
+                  inputFormat="dd/MM/yyyy"
314
+                  value={values.dateToActived}
315
+                  onChange={(val) => setValues({ ...values, dateToActived: val })}
316
+                  renderInput={(params) =>
317
+                    <TextField
318
+                      {...getFieldProps('dateToActived')}
319
+                      error={Boolean(touched.dateToActived && errors.dateToActived)}
320
+                      helperText={touched.dateToActived && errors.dateToActived}
321
+                      disabled={true}
322
+                      label="Fecha de Activación"
323
+                      fullWidth
324
+                      {...params}
325
+                    />}
326
+                />
327
+              </LocalizationProvider>
171 328
 
172
-          <LocalizationProvider
173
-            dateAdapter={DateFnsUtils}>
174
-            <DesktopDatePicker
175
-              label="Fecha de Vencimiento"
176
-              fullWidth
177
-              inputFormat="dd/MM/yyyy"
178
-              {...getFieldProps('deadpwd')}
179
-              value={values.deadpwd}
180
-              onChange={(val) => setValues({ ...values, deadpwd: new Date(val) })
181
-              }
182
-              renderInput={(params) =>
183
-                <TextField
184
-                  error={Boolean(touched.deadpwd && errors.deadpwd)}
185
-                  helperText={touched.deadpwd && errors.deadpwd}
186
-                  disabled={true}
329
+              <LocalizationProvider
330
+                dateAdapter={DateFnsUtils}>
331
+                <DesktopDatePicker
187 332
                   label="Fecha de Vencimiento"
188 333
                   fullWidth
189
-                  {...params}
190
-                />}
191
-            />
192
-          </LocalizationProvider>
193
-          <DialogActions>
194
-            <Button onClick={() => props.handleOpen(false)}>
195
-              Cerrar
196
-            </Button>
197
-            <Button
198
-              type="submit"
199
-              className="registerBtn"
200
-              style={{ color: 'white' }}
201
-            >
202
-              Guardar
203
-            </Button>
204
-          </DialogActions>
334
+                  inputFormat="dd/MM/yyyy"
335
+                  {...getFieldProps('deadpwd')}
336
+                  value={values.deadpwd}
337
+                  onChange={(val) => setValues({ ...values, deadpwd: new Date(val) })
338
+                  }
339
+                  renderInput={(params) =>
340
+                    <TextField
341
+                      error={Boolean(touched.deadpwd && errors.deadpwd)}
342
+                      helperText={touched.deadpwd && errors.deadpwd}
343
+                      disabled={true}
344
+                      label="Fecha de Vencimiento"
345
+                      fullWidth
346
+                      {...params}
347
+                    />}
348
+                />
349
+              </LocalizationProvider>
350
+              <DialogActions>
351
+                <Button onClick={() => props.handleOpen(false)}>
352
+                  Cerrar
353
+                </Button>
354
+                <Button
355
+                  type="submit"
356
+                  className="registerBtn"
357
+                  style={{ color: 'white' }}
358
+                >
359
+                  Guardar
360
+                </Button>
361
+              </DialogActions>
205 362
 
206
-        </Stack>
207
-      </Form>
208
-      <Toaster position="bottom-right" />
209
-    </FormikProvider >
363
+            </Stack>
364
+          </Form>
365
+          <Toaster position="bottom-right" />
366
+        </FormikProvider >
367
+      </Col>
368
+      <Col>
369
+        <Candidatos candidatos={candidatos} />
370
+      </Col>
371
+    </Row>
210 372
   )
211
-
212 373
 }
213 374
 

+ 4 - 5
src/Components/Password/Rows.js

@@ -61,13 +61,12 @@ export const niveles_educativos = [
61 61
 
62 62
 export function Build(pwds) {
63 63
   return pwds.map(password => {
64
-    // console.log(password)
65
-    let { pwd, plaza_id } = password
64
+    let { pwd, plaza_id,deadpwd,dateToActived } = password
66 65
     return {
67 66
       id: plaza_id,
68
-      name: fromBase64( pwd ),//atob( pwd ),
69
-      activacion: new Date().toUTCString(),//dateToActived, 
70
-      dead: new Date().toUTCString(), //deadpwd,
67
+      name: fromBase64( pwd ),
68
+      activacion: dateToActived,//new Date( dateToActived ), 
69
+      dead: deadpwd //new Date( deadpwd ),
71 70
     }
72 71
   })
73 72
 }