|
@@ -1,8 +1,8 @@
|
1
|
1
|
import * as React from 'react';
|
2
|
2
|
import {
|
3
|
3
|
Button, Dialog, DialogActions, DialogContent,
|
4
|
|
- FormControlLabel, Checkbox, Box, Stack,
|
5
|
|
- TextField,CircularProgress
|
|
4
|
+ FormControlLabel, Checkbox, Stack,
|
|
5
|
+ TextField, CircularProgress, Divider, Typography
|
6
|
6
|
} from '@mui/material'
|
7
|
7
|
|
8
|
8
|
import { AddCircle } from '@mui/icons-material/';
|
|
@@ -23,7 +23,7 @@ import { DesktopDatePicker } from '@mui/x-date-pickers/DesktopDatePicker';
|
23
|
23
|
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
|
24
|
24
|
|
25
|
25
|
|
26
|
|
-function Candidatos(props){
|
|
26
|
+function Candidatos(props) {
|
27
|
27
|
|
28
|
28
|
const CandidatoSchema = Yup.object().shape({
|
29
|
29
|
nombres:
|
|
@@ -38,10 +38,8 @@ function Candidatos(props){
|
38
|
38
|
.email("Correo no valido")
|
39
|
39
|
});
|
40
|
40
|
|
41
|
|
- let [password, setPassword] = React.useState([]);
|
42
|
41
|
|
43
|
|
- let { candidatos } = props
|
44
|
|
- console.log('operation props candidatos', candidatos)
|
|
42
|
+ let { candidatos, add , remove } = props
|
45
|
43
|
|
46
|
44
|
const formik = useFormik({
|
47
|
45
|
initialValues: {
|
|
@@ -50,24 +48,20 @@ function Candidatos(props){
|
50
|
48
|
mail: "",
|
51
|
49
|
},
|
52
|
50
|
onSubmit: () => {
|
53
|
|
- if(password.length <= 0){
|
54
|
|
- toast.error("Seleciona almenos un destino")
|
55
|
|
- return;
|
56
|
|
- }
|
57
|
51
|
console.log('submited')
|
58
|
52
|
},
|
59
|
53
|
validationSchema: CandidatoSchema,
|
60
|
54
|
});
|
61
|
55
|
|
62
|
|
- const { errors, touched, handleSubmit, getFieldProps, values, resetForm,isValid } = formik;
|
|
56
|
+ var { errors, touched, handleSubmit, getFieldProps, values, resetForm, isValid } = formik;
|
63
|
57
|
|
64
|
58
|
const addToList = () => {
|
65
|
59
|
|
66
|
|
- if(!values.nombres || !values.apellidos || !values.mail){
|
|
60
|
+ if (!values.nombres || !values.apellidos || !values.mail) {
|
67
|
61
|
return toast.error("Completa la informacion del candidato")
|
68
|
62
|
}
|
69
|
63
|
|
70
|
|
- if(!isValid) {
|
|
64
|
+ if (!isValid) {
|
71
|
65
|
return toast.error("Completa la informacion del candidato")
|
72
|
66
|
}
|
73
|
67
|
|
|
@@ -76,23 +70,18 @@ function Candidatos(props){
|
76
|
70
|
'apellidos': values.apellidos,
|
77
|
71
|
'mail': values.mail,
|
78
|
72
|
}
|
79
|
|
- let new_users = [...password.candidatos, user ]
|
80
|
|
-
|
81
|
|
- setPassword({...candidatos, candidatos: new_users })
|
|
73
|
+ add(user)
|
82
|
74
|
resetForm();
|
83
|
75
|
|
84
|
76
|
}
|
85
|
77
|
|
86
|
|
- const removeFromList = (umail) => {
|
87
|
|
- let without = password.candidatos.filter( user => user.mail !== umail )
|
88
|
|
- setPassword({...password, candidatos: without })
|
89
|
|
- }
|
90
|
|
-
|
91
|
78
|
return (
|
92
|
79
|
<FormikProvider style={{ padding: 25 }} value={formik}>
|
|
80
|
+ <Typography style={{ padding: 5, marginBottom: 15 }}>Ingresa la informacion del candidato</Typography>
|
|
81
|
+ <Divider />
|
93
|
82
|
<Form autoComplete="off" noValidate onSubmit={handleSubmit}>
|
94
|
83
|
<Stack spacing={3}>
|
95
|
|
- <Stack style={{paddingTop: 15}} direction={{ xs: 'column', sm: 'row' }} spacing={2}>
|
|
84
|
+ <Stack style={{ paddingTop: 15 }} direction={{ xs: 'column', sm: 'row' }} spacing={2}>
|
96
|
85
|
<TextField
|
97
|
86
|
label="Nombre"
|
98
|
87
|
fullWidth
|
|
@@ -121,35 +110,15 @@ function Candidatos(props){
|
121
|
110
|
/>
|
122
|
111
|
|
123
|
112
|
<Button onClick={addToList}>
|
124
|
|
- <AddCircle style={{color:'var(--main)'}}/>
|
|
113
|
+ <AddCircle style={{ color: 'var(--main)' }} />
|
125
|
114
|
</Button>
|
126
|
115
|
|
127
|
116
|
</Stack>
|
128
|
117
|
|
129
|
|
- <MailTable
|
130
|
|
- remove={removeFromList}
|
|
118
|
+ <MailTable
|
|
119
|
+ remove={remove}
|
131
|
120
|
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>
|
|
121
|
+ />
|
153
|
122
|
|
154
|
123
|
</Stack>
|
155
|
124
|
<Toaster position="top-right" />
|
|
@@ -160,6 +129,10 @@ function Candidatos(props){
|
160
|
129
|
|
161
|
130
|
export function ModalEdit(props) {
|
162
|
131
|
|
|
132
|
+ //TODO:
|
|
133
|
+ //se debe crear un objeto de estado que almacena los nuevos cambios de la password
|
|
134
|
+ //enviar por props las utilizades de edicion y eliminar
|
|
135
|
+
|
163
|
136
|
const auth = useSelector((state) => state.token)
|
164
|
137
|
let [data, setData] = React.useState(null)
|
165
|
138
|
let { password, open, handleOpen } = props
|
|
@@ -167,14 +140,11 @@ export function ModalEdit(props) {
|
167
|
140
|
|
168
|
141
|
React.useEffect(() => {
|
169
|
142
|
|
170
|
|
- const getPassword = async () => {
|
171
|
|
- let rest = new Service(`/contrasenia/${btoa(pwd)}/${plz}`)
|
172
|
|
- return await rest.getQuery(auth.token)
|
173
|
|
- }
|
174
|
|
-
|
175
|
|
- getPassword()
|
|
143
|
+ let rest = new Service(`/contrasenia/${btoa(pwd)}/${plz}`)
|
|
144
|
+ rest.getQuery(auth.token)
|
176
|
145
|
.then(resp => setData(resp.data))
|
177
|
146
|
.catch(error => console.log(error))
|
|
147
|
+
|
178
|
148
|
}, [auth.token, pwd, plz])
|
179
|
149
|
|
180
|
150
|
return (
|
|
@@ -208,6 +178,7 @@ function Loading() {
|
208
|
178
|
|
209
|
179
|
function ModalForm(props) {
|
210
|
180
|
|
|
181
|
+ let [candidatos,setCandidatos] = React.useState(null);
|
211
|
182
|
const pwdSchema = Yup.object().shape({
|
212
|
183
|
id: Yup.number(),
|
213
|
184
|
pwd: Yup.string().required("Escoge un nombre valido"),
|
|
@@ -218,12 +189,24 @@ function ModalForm(props) {
|
218
|
189
|
|
219
|
190
|
const queryClient = useQueryClient();
|
220
|
191
|
let { password } = props
|
221
|
|
- console.log("227 PWD: ", password)
|
222
|
192
|
|
223
|
|
- let candidatos = password.candidatospwds.map( pwd => {
|
224
|
|
- let { apellidos, nombre,mail} = pwd.candi
|
225
|
|
- return { nombres: nombre, apellidos, mail }
|
226
|
|
- })
|
|
193
|
+ React.useEffect(() => {
|
|
194
|
+ let mapCandi = password.candidatospwds.map(pwd => {
|
|
195
|
+ let { apellidos, nombre, mail } = pwd.candi
|
|
196
|
+ return { nombres: nombre, apellidos, mail }
|
|
197
|
+ })
|
|
198
|
+ setCandidatos(mapCandi)
|
|
199
|
+ },[password.candidatospwds])
|
|
200
|
+
|
|
201
|
+ function removeCandidato (umail) {
|
|
202
|
+ console.log('remove:', umail)
|
|
203
|
+ let without = candidatos.filter( user => user.mail !== umail )
|
|
204
|
+ setCandidatos(without)
|
|
205
|
+ }
|
|
206
|
+
|
|
207
|
+ function addCandidato (candidato) {
|
|
208
|
+ setCandidatos([...candidatos, candidato ])
|
|
209
|
+ }
|
227
|
210
|
|
228
|
211
|
const formik = useFormik({
|
229
|
212
|
initialValues: {
|
|
@@ -246,7 +229,6 @@ function ModalForm(props) {
|
246
|
229
|
rest.put(fields, props.token)
|
247
|
230
|
.then(result => {
|
248
|
231
|
queryClient.invalidateQueries('passwords')
|
249
|
|
- console.log(result)
|
250
|
232
|
setTimeout(() => {
|
251
|
233
|
props.handleOpen(false)
|
252
|
234
|
}, 1000)
|
|
@@ -264,6 +246,7 @@ function ModalForm(props) {
|
264
|
246
|
|
265
|
247
|
return (
|
266
|
248
|
<Row>
|
|
249
|
+
|
267
|
250
|
<Col>
|
268
|
251
|
<FormikProvider value={formik}>
|
269
|
252
|
<Form style={{ padding: 20, maxWidth: 950 }} autoComplete="off" noValidate onSubmit={handleSubmit}>
|
|
@@ -347,18 +330,7 @@ function ModalForm(props) {
|
347
|
330
|
/>}
|
348
|
331
|
/>
|
349
|
332
|
</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>
|
|
333
|
+
|
362
|
334
|
|
363
|
335
|
</Stack>
|
364
|
336
|
</Form>
|
|
@@ -366,8 +338,25 @@ function ModalForm(props) {
|
366
|
338
|
</FormikProvider >
|
367
|
339
|
</Col>
|
368
|
340
|
<Col>
|
369
|
|
- <Candidatos candidatos={candidatos} />
|
|
341
|
+ <Candidatos
|
|
342
|
+ add={addCandidato}
|
|
343
|
+ remove={removeCandidato}
|
|
344
|
+ candidatos={candidatos}
|
|
345
|
+ />
|
370
|
346
|
</Col>
|
|
347
|
+
|
|
348
|
+ <DialogActions>
|
|
349
|
+ <Button onClick={() => props.handleOpen(false)}>
|
|
350
|
+ Cerrar
|
|
351
|
+ </Button>
|
|
352
|
+ <Button
|
|
353
|
+ type="submit"
|
|
354
|
+ className="registerBtn"
|
|
355
|
+ style={{ color: 'white' }}
|
|
356
|
+ >
|
|
357
|
+ Guardar
|
|
358
|
+ </Button>
|
|
359
|
+ </DialogActions>
|
371
|
360
|
</Row>
|
372
|
361
|
)
|
373
|
362
|
}
|