index.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import { makeStyles, Button, TextField, Typography } from '@material-ui/core'
  2. import {useState} from 'react';
  3. const useStyles = makeStyles({
  4. container: {
  5. display: 'flex',
  6. alignItems: 'center',
  7. alignContent:'center',
  8. flexDirection: 'column',
  9. width: 350,
  10. margin: '0 auto',
  11. paddingTop: 64,
  12. paddingBottom: 24,
  13. },
  14. title: {
  15. marginBottom:20
  16. },
  17. buttonNext: {
  18. marginTop: 20,
  19. height: 50,
  20. color: '#f8f8f8',
  21. backgroundColor:'#1d74c5',
  22. },
  23. textField: {
  24. marginBottom:20
  25. }
  26. })
  27. interface IRegistration {
  28. }
  29. const Registration = () => {
  30. const classes = useStyles()
  31. const [name, setName] = useState<string>('')
  32. const [lastName, setLastName] = useState<string>('')
  33. const format = (a: string) => a.split(' ').join('').trim()
  34. const isValidCredentials = () => {
  35. const validName = name.length
  36. const validLastName = lastName.length
  37. if (validName < 3 || validName > 30) return false
  38. if (validLastName < 3 || validLastName > 30) return false
  39. return true
  40. }
  41. const handleTextField = (e: React.ChangeEvent<HTMLInputElement>) => {
  42. const value = format(e.target.value)
  43. const name = e.target.name
  44. switch (name) {
  45. case 'name':
  46. setName(value)
  47. break;
  48. case 'lastName':
  49. setLastName(value)
  50. break;
  51. default:
  52. break;
  53. }
  54. }
  55. const handleUpdateUser = () => {
  56. console.log(name,lastName)
  57. }
  58. return (
  59. <div className={classes.container} >
  60. <Typography
  61. className={classes.title}
  62. variant="h5"
  63. color="initial">
  64. Fill registration form
  65. </Typography>
  66. <TextField
  67. id="name"
  68. name='name'
  69. label="Name"
  70. value={name}
  71. fullWidth
  72. variant='outlined'
  73. onChange={handleTextField}
  74. className={classes.textField}
  75. />
  76. <TextField
  77. id="lastName"
  78. name='lastName'
  79. label="LastName"
  80. value={lastName}
  81. fullWidth
  82. variant='outlined'
  83. onChange={handleTextField}
  84. className={classes.textField}
  85. />
  86. {isValidCredentials() &&
  87. <Button
  88. onClick={handleUpdateUser}
  89. className={classes.buttonNext}
  90. color='primary'
  91. variant="contained"
  92. fullWidth
  93. > NEXT
  94. </Button>}
  95. </div>
  96. );
  97. };
  98. export default Registration;