Form.jsx 3.0 KB

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