Reac front end for psicometric app

tree.js 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import React from 'react'
  2. import * as Yup from 'yup';
  3. // import { useState, useEffect } from 'react';
  4. import { useFormik, Form, FormikProvider } from 'formik';
  5. import {
  6. Box, Button, Stack, Checkbox,
  7. TextField, Autocomplete,
  8. } from '@mui/material';
  9. import {
  10. CheckBox as CheckBoxIcon,
  11. CheckBoxOutlineBlank as CheckBoxOutlineBlankIcon
  12. } from '@mui/icons-material';
  13. const icon = <CheckBoxOutlineBlankIcon fontSize="small" />;
  14. const checkedIcon = <CheckBoxIcon fontSize="small" />;
  15. export function StepTree(props) {
  16. const PlazaScheme = Yup.object().shape({
  17. puesto: Yup.object().required('Escoge un puesto valido')
  18. });
  19. let { handleNext, handleBack } = props
  20. const formik = useFormik({
  21. initialValues: {
  22. puesto: {}
  23. },
  24. onSubmit: (fields) => {
  25. console.log('SUBMIT > ',fields)
  26. handleNext()
  27. },
  28. validationSchema: PlazaScheme,
  29. });
  30. const {errors, touched, handleSubmit, getFieldProps, setValues } = formik;
  31. return (
  32. <FormikProvider style={{ padding : 25 }} value={formik}>
  33. <Form autoComplete="off" noValidate onSubmit={handleSubmit}>
  34. <Stack spacing={2}>
  35. <Autocomplete
  36. multiple
  37. id="checkboxes-tags-demo"
  38. options={top100Films}
  39. disableCloseOnSelect
  40. getOptionLabel={(option) => option.label}
  41. onChange={(a,b,c) => {
  42. setValues({
  43. puesto : b[0]
  44. })
  45. }}
  46. renderOption={(props, option, { selected }) => (
  47. <li {...props}>
  48. <Checkbox
  49. icon={icon}
  50. checkedIcon={checkedIcon}
  51. // style={{ marginRight: 8 }}
  52. checked={selected}
  53. />
  54. {option.label}
  55. </li>
  56. )}
  57. renderInput={(params) => (
  58. <TextField
  59. {...getFieldProps('puesto')}
  60. error={Boolean(touched.puesto && errors.puesto)}
  61. helperText={touched.puesto && errors.puesto}
  62. {...params}
  63. label="Escribe el nombre de la prueba"
  64. placeholder="Prueba"
  65. />
  66. )}
  67. />
  68. <Box sx={{ mb: 2 }}>
  69. <div style={{ paddingTop : 15}}>
  70. <Button
  71. type="submit"
  72. className="registerBtn"
  73. variant="contained"
  74. sx={{ mt: 1, mr: 1 }}
  75. >
  76. {'Siguiente'}
  77. </Button>
  78. <Button
  79. disabled={false}
  80. onClick={handleBack}
  81. sx={{ mt: 1, mr: 1 }}
  82. >
  83. Regresar
  84. </Button>
  85. </div>
  86. </Box>
  87. </Stack>
  88. </Form>
  89. </FormikProvider>
  90. );
  91. }
  92. const top100Films = [
  93. { label: 'City of God', year: 2002 },
  94. { label: 'Se7en', year: 1995 },
  95. { label: 'The Silence of the Lambs', year: 1991 },
  96. { label: "It's a Wonderful Life", year: 1946 },
  97. { label: 'Life Is Beautiful', year: 1997 },
  98. { label: 'The Usual Suspects', year: 1995 },
  99. { label: 'Grave of the Fireflies', year: 1988 },
  100. { label: 'Paths of Glory', year: 1957 },
  101. { label: 'Django Unchained', year: 2012 },
  102. { label: 'The Shining', year: 1980 },
  103. { label: 'WALL·E', year: 2008 },
  104. { label: 'American Beauty', year: 1999 },
  105. { label: 'The Dark Knight Rises', year: 2012 },
  106. ];