password.jsx 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. import React from 'react'
  2. import * as Yup from 'yup';
  3. import { useFormik, Form, FormikProvider } from 'formik';
  4. import {
  5. Box, Button,
  6. Stack, TextField,
  7. } from '@mui/material';
  8. import DateFnsUtils from '@date-io/date-fns';
  9. import { DesktopDatePicker, LocalizationProvider } from '@mui/lab';
  10. export function Password(props) {
  11. const [uid,setUID] = React.useState(null);
  12. const PasswordSchema = Yup.object().shape({
  13. pwd:
  14. Yup
  15. .string()
  16. .required('Ingresa un identificador válido')
  17. .min(5,"Ingresa un identificador válido")
  18. .max(50,"identificador demasiado largo"),
  19. deadpwd: Yup.date("Ingresa una fecha válida"),
  20. dateToActived: Yup.date("Ingresa una fecha válida"),
  21. });
  22. let { handleNext, handleBack, password, setPassword } = props
  23. const formik = useFormik({
  24. initialValues: {
  25. pwd: password.pwd ,
  26. deadpwd: password.deadpwd,
  27. dateToActived: password.dateToActived,
  28. },
  29. onSubmit: (fields) => {
  30. fields['deadpwd'] = new Date(fields.deadpwd).toISOString();
  31. fields['dateToActived'] = new Date(fields.dateToActived).toISOString();
  32. setPassword({
  33. ...password,
  34. ...fields
  35. })
  36. handleNext()
  37. },
  38. validationSchema: PasswordSchema,
  39. });
  40. const {errors, touched, handleSubmit, getFieldProps, values,setValues } = formik;
  41. return (
  42. <FormikProvider style={{ padding : 25, paddingTop : 5 }} value={formik}>
  43. <Form autoComplete="off" noValidate onSubmit={handleSubmit}>
  44. <Stack spacing={3}>
  45. <TextField
  46. fullWidth
  47. type="text"
  48. label="Nombre o identificador"
  49. {...getFieldProps('pwd')}
  50. onChange={(event)=>{
  51. let value = event.target.value
  52. setUID(btoa(value));
  53. setValues({
  54. ...values,
  55. pwd:value
  56. })
  57. }}
  58. error={Boolean(touched.pwd && errors.pwd)}
  59. helperText={touched.pwd && errors.pwd}
  60. />
  61. <TextField
  62. value={uid? uid: btoa(values.pwd)}
  63. disabled
  64. fullWidth
  65. type="text"
  66. label="Identificador Codificado"
  67. variant="filled"
  68. />
  69. <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
  70. <LocalizationProvider
  71. dateAdapter={DateFnsUtils}>
  72. <DesktopDatePicker
  73. label="Fecha de Activación"
  74. fullWidth
  75. inputFormat="dd/MM/yyyy"
  76. {...getFieldProps('dateToActived')}
  77. value={values.dateToActived}
  78. onChange={(val) => setValues({ ...values, dateToActived: new Date(val) })
  79. }
  80. renderInput={(params) =>
  81. <TextField
  82. error={Boolean(touched.dateToActived && errors.dateToActived)}
  83. helperText={touched.dateToActived && errors.dateToActived}
  84. disabled={true}
  85. label="Fecha de Activación"
  86. fullWidth
  87. {...params}
  88. />}
  89. />
  90. </LocalizationProvider>
  91. <LocalizationProvider
  92. dateAdapter={DateFnsUtils}>
  93. <DesktopDatePicker
  94. label="Fecha de Caducidad"
  95. fullWidth
  96. inputFormat="dd/MM/yyyy"
  97. {...getFieldProps('deadpwd')}
  98. value={values.deadpwd}
  99. onChange={(val) => setValues({ ...values, deadpwd: new Date(val) }) }
  100. renderInput={(params) =>
  101. <TextField
  102. error={Boolean(touched.deadpwd && errors.deadpwd)}
  103. helperText={touched.deadpwd && errors.deadpwd}
  104. disabled={true}
  105. label="Fecha de Caducidad"
  106. fullWidth
  107. {...params}
  108. />}
  109. />
  110. </LocalizationProvider>
  111. </Stack>
  112. <Box sx={{ mb: 2 }}>
  113. <div style={{ paddingTop : 15}}>
  114. <Button
  115. type="submit"
  116. className="registerBtn"
  117. variant="contained"
  118. sx={{ mt: 1, mr: 1 }}
  119. >
  120. {'Siguiente'}
  121. </Button>
  122. <Button
  123. disabled={false}
  124. onClick={handleBack}
  125. sx={{ mt: 1, mr: 1 }}
  126. >
  127. Regresar
  128. </Button>
  129. </div>
  130. </Box>
  131. </Stack>
  132. </Form>
  133. </FormikProvider>
  134. );
  135. }