|
@@ -1,8 +1,8 @@
|
|
|
import * as React from 'react';
|
|
import * as React from 'react';
|
|
|
import {
|
|
import {
|
|
|
Button, Dialog, DialogActions, DialogContent,
|
|
Button, Dialog, DialogActions, DialogContent,
|
|
|
- FormControlLabel, Checkbox, Box, Stack,
|
|
|
|
|
- TextField,CircularProgress
|
|
|
|
|
|
|
+ FormControlLabel, Checkbox, Stack,
|
|
|
|
|
+ TextField, CircularProgress, Divider, Typography
|
|
|
} from '@mui/material'
|
|
} from '@mui/material'
|
|
|
|
|
|
|
|
import { AddCircle } from '@mui/icons-material/';
|
|
import { AddCircle } from '@mui/icons-material/';
|
|
@@ -23,7 +23,7 @@ import { DesktopDatePicker } from '@mui/x-date-pickers/DesktopDatePicker';
|
|
|
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
|
|
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
|
|
|
|
|
|
|
|
|
|
|
|
|
-function Candidatos(props){
|
|
|
|
|
|
|
+function Candidatos(props) {
|
|
|
|
|
|
|
|
const CandidatoSchema = Yup.object().shape({
|
|
const CandidatoSchema = Yup.object().shape({
|
|
|
nombres:
|
|
nombres:
|
|
@@ -38,10 +38,8 @@ function Candidatos(props){
|
|
|
.email("Correo no valido")
|
|
.email("Correo no valido")
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- let [password, setPassword] = React.useState([]);
|
|
|
|
|
|
|
|
|
|
- let { candidatos } = props
|
|
|
|
|
- console.log('operation props candidatos', candidatos)
|
|
|
|
|
|
|
+ let { candidatos, add , remove } = props
|
|
|
|
|
|
|
|
const formik = useFormik({
|
|
const formik = useFormik({
|
|
|
initialValues: {
|
|
initialValues: {
|
|
@@ -50,24 +48,20 @@ function Candidatos(props){
|
|
|
mail: "",
|
|
mail: "",
|
|
|
},
|
|
},
|
|
|
onSubmit: () => {
|
|
onSubmit: () => {
|
|
|
- if(password.length <= 0){
|
|
|
|
|
- toast.error("Seleciona almenos un destino")
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
console.log('submited')
|
|
console.log('submited')
|
|
|
},
|
|
},
|
|
|
validationSchema: CandidatoSchema,
|
|
validationSchema: CandidatoSchema,
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- const { errors, touched, handleSubmit, getFieldProps, values, resetForm,isValid } = formik;
|
|
|
|
|
|
|
+ var { errors, touched, handleSubmit, getFieldProps, values, resetForm, isValid } = formik;
|
|
|
|
|
|
|
|
const addToList = () => {
|
|
const addToList = () => {
|
|
|
|
|
|
|
|
- if(!values.nombres || !values.apellidos || !values.mail){
|
|
|
|
|
|
|
+ if (!values.nombres || !values.apellidos || !values.mail) {
|
|
|
return toast.error("Completa la informacion del candidato")
|
|
return toast.error("Completa la informacion del candidato")
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if(!isValid) {
|
|
|
|
|
|
|
+ if (!isValid) {
|
|
|
return toast.error("Completa la informacion del candidato")
|
|
return toast.error("Completa la informacion del candidato")
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -76,23 +70,18 @@ function Candidatos(props){
|
|
|
'apellidos': values.apellidos,
|
|
'apellidos': values.apellidos,
|
|
|
'mail': values.mail,
|
|
'mail': values.mail,
|
|
|
}
|
|
}
|
|
|
- let new_users = [...password.candidatos, user ]
|
|
|
|
|
-
|
|
|
|
|
- setPassword({...candidatos, candidatos: new_users })
|
|
|
|
|
|
|
+ add(user)
|
|
|
resetForm();
|
|
resetForm();
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const removeFromList = (umail) => {
|
|
|
|
|
- let without = password.candidatos.filter( user => user.mail !== umail )
|
|
|
|
|
- setPassword({...password, candidatos: without })
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
return (
|
|
return (
|
|
|
<FormikProvider style={{ padding: 25 }} value={formik}>
|
|
<FormikProvider style={{ padding: 25 }} value={formik}>
|
|
|
|
|
+ <Typography style={{ padding: 5, marginBottom: 15 }}>Ingresa la informacion del candidato</Typography>
|
|
|
|
|
+ <Divider />
|
|
|
<Form autoComplete="off" noValidate onSubmit={handleSubmit}>
|
|
<Form autoComplete="off" noValidate onSubmit={handleSubmit}>
|
|
|
<Stack spacing={3}>
|
|
<Stack spacing={3}>
|
|
|
- <Stack style={{paddingTop: 15}} direction={{ xs: 'column', sm: 'row' }} spacing={2}>
|
|
|
|
|
|
|
+ <Stack style={{ paddingTop: 15 }} direction={{ xs: 'column', sm: 'row' }} spacing={2}>
|
|
|
<TextField
|
|
<TextField
|
|
|
label="Nombre"
|
|
label="Nombre"
|
|
|
fullWidth
|
|
fullWidth
|
|
@@ -121,35 +110,15 @@ function Candidatos(props){
|
|
|
/>
|
|
/>
|
|
|
|
|
|
|
|
<Button onClick={addToList}>
|
|
<Button onClick={addToList}>
|
|
|
- <AddCircle style={{color:'var(--main)'}}/>
|
|
|
|
|
|
|
+ <AddCircle style={{ color: 'var(--main)' }} />
|
|
|
</Button>
|
|
</Button>
|
|
|
|
|
|
|
|
</Stack>
|
|
</Stack>
|
|
|
|
|
|
|
|
- <MailTable
|
|
|
|
|
- remove={removeFromList}
|
|
|
|
|
|
|
+ <MailTable
|
|
|
|
|
+ remove={remove}
|
|
|
users={candidatos}
|
|
users={candidatos}
|
|
|
- />
|
|
|
|
|
-
|
|
|
|
|
- <Box sx={{ mb: 2 }}>
|
|
|
|
|
- <div style={{ paddingTop: 15 }}>
|
|
|
|
|
- <Button
|
|
|
|
|
- type="submit"
|
|
|
|
|
- className="registerBtn"
|
|
|
|
|
- variant="contained"
|
|
|
|
|
- sx={{ mt: 1, mr: 1 }}
|
|
|
|
|
- >
|
|
|
|
|
- {'Siguiente'}
|
|
|
|
|
- </Button>
|
|
|
|
|
- <Button
|
|
|
|
|
- disabled={false}
|
|
|
|
|
- onClick={() => console.log('regresar')}
|
|
|
|
|
- sx={{ mt: 1, mr: 1 }}
|
|
|
|
|
- >
|
|
|
|
|
- Regresar
|
|
|
|
|
- </Button>
|
|
|
|
|
- </div>
|
|
|
|
|
- </Box>
|
|
|
|
|
|
|
+ />
|
|
|
|
|
|
|
|
</Stack>
|
|
</Stack>
|
|
|
<Toaster position="top-right" />
|
|
<Toaster position="top-right" />
|
|
@@ -160,6 +129,10 @@ function Candidatos(props){
|
|
|
|
|
|
|
|
export function ModalEdit(props) {
|
|
export function ModalEdit(props) {
|
|
|
|
|
|
|
|
|
|
+ //TODO:
|
|
|
|
|
+ //se debe crear un objeto de estado que almacena los nuevos cambios de la password
|
|
|
|
|
+ //enviar por props las utilizades de edicion y eliminar
|
|
|
|
|
+
|
|
|
const auth = useSelector((state) => state.token)
|
|
const auth = useSelector((state) => state.token)
|
|
|
let [data, setData] = React.useState(null)
|
|
let [data, setData] = React.useState(null)
|
|
|
let { password, open, handleOpen } = props
|
|
let { password, open, handleOpen } = props
|
|
@@ -167,14 +140,11 @@ export function ModalEdit(props) {
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
React.useEffect(() => {
|
|
|
|
|
|
|
|
- const getPassword = async () => {
|
|
|
|
|
- let rest = new Service(`/contrasenia/${btoa(pwd)}/${plz}`)
|
|
|
|
|
- return await rest.getQuery(auth.token)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- getPassword()
|
|
|
|
|
|
|
+ let rest = new Service(`/contrasenia/${btoa(pwd)}/${plz}`)
|
|
|
|
|
+ rest.getQuery(auth.token)
|
|
|
.then(resp => setData(resp.data))
|
|
.then(resp => setData(resp.data))
|
|
|
.catch(error => console.log(error))
|
|
.catch(error => console.log(error))
|
|
|
|
|
+
|
|
|
}, [auth.token, pwd, plz])
|
|
}, [auth.token, pwd, plz])
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
@@ -208,6 +178,7 @@ function Loading() {
|
|
|
|
|
|
|
|
function ModalForm(props) {
|
|
function ModalForm(props) {
|
|
|
|
|
|
|
|
|
|
+ let [candidatos,setCandidatos] = React.useState(null);
|
|
|
const pwdSchema = Yup.object().shape({
|
|
const pwdSchema = Yup.object().shape({
|
|
|
id: Yup.number(),
|
|
id: Yup.number(),
|
|
|
pwd: Yup.string().required("Escoge un nombre valido"),
|
|
pwd: Yup.string().required("Escoge un nombre valido"),
|
|
@@ -218,12 +189,24 @@ function ModalForm(props) {
|
|
|
|
|
|
|
|
const queryClient = useQueryClient();
|
|
const queryClient = useQueryClient();
|
|
|
let { password } = props
|
|
let { password } = props
|
|
|
- console.log("227 PWD: ", password)
|
|
|
|
|
|
|
|
|
|
- let candidatos = password.candidatospwds.map( pwd => {
|
|
|
|
|
- let { apellidos, nombre,mail} = pwd.candi
|
|
|
|
|
- return { nombres: nombre, apellidos, mail }
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ React.useEffect(() => {
|
|
|
|
|
+ let mapCandi = password.candidatospwds.map(pwd => {
|
|
|
|
|
+ let { apellidos, nombre, mail } = pwd.candi
|
|
|
|
|
+ return { nombres: nombre, apellidos, mail }
|
|
|
|
|
+ })
|
|
|
|
|
+ setCandidatos(mapCandi)
|
|
|
|
|
+ },[password.candidatospwds])
|
|
|
|
|
+
|
|
|
|
|
+ function removeCandidato (umail) {
|
|
|
|
|
+ console.log('remove:', umail)
|
|
|
|
|
+ let without = candidatos.filter( user => user.mail !== umail )
|
|
|
|
|
+ setCandidatos(without)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function addCandidato (candidato) {
|
|
|
|
|
+ setCandidatos([...candidatos, candidato ])
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
const formik = useFormik({
|
|
const formik = useFormik({
|
|
|
initialValues: {
|
|
initialValues: {
|
|
@@ -246,7 +229,6 @@ function ModalForm(props) {
|
|
|
rest.put(fields, props.token)
|
|
rest.put(fields, props.token)
|
|
|
.then(result => {
|
|
.then(result => {
|
|
|
queryClient.invalidateQueries('passwords')
|
|
queryClient.invalidateQueries('passwords')
|
|
|
- console.log(result)
|
|
|
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
|
props.handleOpen(false)
|
|
props.handleOpen(false)
|
|
|
}, 1000)
|
|
}, 1000)
|
|
@@ -264,6 +246,7 @@ function ModalForm(props) {
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<Row>
|
|
<Row>
|
|
|
|
|
+
|
|
|
<Col>
|
|
<Col>
|
|
|
<FormikProvider value={formik}>
|
|
<FormikProvider value={formik}>
|
|
|
<Form style={{ padding: 20, maxWidth: 950 }} autoComplete="off" noValidate onSubmit={handleSubmit}>
|
|
<Form style={{ padding: 20, maxWidth: 950 }} autoComplete="off" noValidate onSubmit={handleSubmit}>
|
|
@@ -347,18 +330,7 @@ function ModalForm(props) {
|
|
|
/>}
|
|
/>}
|
|
|
/>
|
|
/>
|
|
|
</LocalizationProvider>
|
|
</LocalizationProvider>
|
|
|
- <DialogActions>
|
|
|
|
|
- <Button onClick={() => props.handleOpen(false)}>
|
|
|
|
|
- Cerrar
|
|
|
|
|
- </Button>
|
|
|
|
|
- <Button
|
|
|
|
|
- type="submit"
|
|
|
|
|
- className="registerBtn"
|
|
|
|
|
- style={{ color: 'white' }}
|
|
|
|
|
- >
|
|
|
|
|
- Guardar
|
|
|
|
|
- </Button>
|
|
|
|
|
- </DialogActions>
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
</Stack>
|
|
</Stack>
|
|
|
</Form>
|
|
</Form>
|
|
@@ -366,8 +338,25 @@ function ModalForm(props) {
|
|
|
</FormikProvider >
|
|
</FormikProvider >
|
|
|
</Col>
|
|
</Col>
|
|
|
<Col>
|
|
<Col>
|
|
|
- <Candidatos candidatos={candidatos} />
|
|
|
|
|
|
|
+ <Candidatos
|
|
|
|
|
+ add={addCandidato}
|
|
|
|
|
+ remove={removeCandidato}
|
|
|
|
|
+ candidatos={candidatos}
|
|
|
|
|
+ />
|
|
|
</Col>
|
|
</Col>
|
|
|
|
|
+
|
|
|
|
|
+ <DialogActions>
|
|
|
|
|
+ <Button onClick={() => props.handleOpen(false)}>
|
|
|
|
|
+ Cerrar
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ <Button
|
|
|
|
|
+ type="submit"
|
|
|
|
|
+ className="registerBtn"
|
|
|
|
|
+ style={{ color: 'white' }}
|
|
|
|
|
+ >
|
|
|
|
|
+ Guardar
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ </DialogActions>
|
|
|
</Row>
|
|
</Row>
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|