Form.jsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import {Box, Button, TextField, Typography, useMediaQuery} from "@mui/material";
  2. import {useState} from "react";
  3. import UnstyledButtonCustom from "../../components/MainButton";
  4. import ArrowForwardIosIcon from "@mui/icons-material/ArrowForwardIos";
  5. export const Form = ({title, target, onClickEvent, children, setStatus}) => {
  6. const matches2 = useMediaQuery('(max-width:450px)')
  7. const [valueLogin, setValueLogin] = useState('')
  8. const [valuePassword, setValuePassword] = useState('')
  9. const [flagLogin, setFlagLog] = useState(false)
  10. const [flagPassword, setFlagPass] = useState(false)
  11. return (
  12. <Box
  13. sx={{
  14. backgroundColor: "#fff",
  15. display: "flex",
  16. flexDirection: "column",
  17. justifyContent: "center",
  18. alignItems: "center",
  19. padding: matches2 ? "30px 20px" : "40px 60px"
  20. }}
  21. >
  22. <Typography
  23. variant='h4'
  24. letterSpacing='10px'
  25. marginBottom='30px'
  26. >
  27. { title || 'title' }
  28. </Typography>
  29. <TextField
  30. id="login"
  31. label="Login"
  32. variant="standard"
  33. type="text"
  34. required
  35. fullWidth
  36. value={valueLogin}
  37. onChange={e => {
  38. setValueLogin(e.target.value);
  39. setFlagLog(true)
  40. }}
  41. error={flagLogin && (valueLogin.length < 3 || valueLogin.length > 20)}
  42. sx={{marginBottom: '20px'}}
  43. />
  44. <TextField
  45. id="password"
  46. label="Password"
  47. variant="standard"
  48. type="password"
  49. required
  50. fullWidth
  51. value={valuePassword}
  52. onChange={e => {
  53. setValuePassword(e.target.value);
  54. setFlagPass(true)
  55. }}
  56. error={flagPassword && (valuePassword.length < 3 || valuePassword.length > 20)}
  57. sx={{marginBottom: '30px'}}
  58. />
  59. {children}
  60. <UnstyledButtonCustom
  61. onClick={() => {
  62. if(valuePassword.length >= 3 && valuePassword.length <= 20 &&
  63. valueLogin.length >= 3 && valueLogin.length <= 20) {
  64. onClickEvent(valueLogin, valuePassword)
  65. }
  66. }}
  67. text={title || 'title'}
  68. />
  69. <Box
  70. width='100%'
  71. display='flex'
  72. justifyContent='flex-end'
  73. marginTop='20px'
  74. >
  75. <Button
  76. onClick={() => setStatus(target)}
  77. >
  78. { target }
  79. <ArrowForwardIosIcon/>
  80. </Button>
  81. </Box>
  82. </Box>
  83. )
  84. }