MyAccountPage.jsx 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. import Header from "../components/Header";
  2. import Footer from "../components/Footer";
  3. import Breadcrumb from "../components/Breadcrumbs";
  4. import {
  5. Box,
  6. Button,
  7. Container,
  8. FormControl,
  9. OutlinedInput,
  10. TextField,
  11. Typography,
  12. useMediaQuery
  13. } from "@mui/material";
  14. import UnstyledButtonCustom from "../components/MainButton";
  15. import ArrowForwardIosIcon from '@mui/icons-material/ArrowForwardIos';
  16. import {useState} from "react";
  17. import Link from "react-router-dom/es/Link";
  18. import {connect} from 'react-redux';
  19. import {actionFullLogin, actionFullRegister} from "../actions/ActionLogin";
  20. import Redirect from "react-router-dom/es/Redirect";
  21. const MyAccountPage = ({auth, promise, onLogin, onRegister}) => {
  22. const matches = useMediaQuery('(max-width:899px)')
  23. const [status, setStatus] = useState('login')
  24. const Login = ({onLogin}) => {
  25. const [valueLogin, setValueLogin] = useState('')
  26. const [valuePassword, setValuePassword] = useState('')
  27. const [flagLogin, setFlagLog] = useState(false)
  28. const [flagPassword, setFlagPass] = useState(false)
  29. return (
  30. <Box
  31. sx={{
  32. backgroundColor: "#fff",
  33. display: "flex",
  34. flexDirection: "column",
  35. justifyContent: "center",
  36. alignItems: "center",
  37. padding: "40px 60px"
  38. }}
  39. >
  40. <Typography
  41. variant='h4'
  42. letterSpacing='10px'
  43. marginBottom='30px'
  44. >
  45. LOGIN
  46. </Typography>
  47. <TextField
  48. id="login"
  49. label="Login"
  50. variant="standard"
  51. type="text"
  52. required
  53. fullWidth
  54. value={valueLogin}
  55. onChange={e => {setValueLogin(e.target.value); setFlagLog(true)}}
  56. error={flagLogin && (valueLogin.length <= 3 || valueLogin.length > 20)}
  57. sx={{marginBottom: '20px'}}
  58. />
  59. <TextField
  60. id="password"
  61. label="Password"
  62. variant="standard"
  63. type="password"
  64. required
  65. fullWidth
  66. value={valuePassword}
  67. onChange={e => {setValuePassword(e.target.value); setFlagPass(true)}}
  68. error={flagPassword && (valuePassword.length <= 3 || valuePassword.length > 20)}
  69. sx={{marginBottom: '50px'}}
  70. />
  71. {promise?.login?.status === "RESOLVED" &&
  72. <Typography
  73. variant='body2'
  74. color='red'
  75. marginBottom='20px'
  76. >
  77. This user does not exist
  78. </Typography>
  79. }
  80. <UnstyledButtonCustom
  81. onClick={() => {
  82. if(valuePassword.length >= 3 && valuePassword.length <= 20 &&
  83. valueLogin.length >= 3 && valueLogin.length <= 20) {
  84. onLogin(valueLogin, valuePassword)
  85. }
  86. }}
  87. text={'LOGIN'}
  88. />
  89. <Box
  90. width='100%'
  91. display='flex'
  92. justifyContent='flex-end'
  93. marginTop='20px'
  94. >
  95. <Button
  96. onClick={() => setStatus('register')}
  97. >
  98. Register
  99. <ArrowForwardIosIcon/>
  100. </Button>
  101. </Box>
  102. </Box>
  103. )
  104. }
  105. const Register = ({onRegister}) => {
  106. const [valueLogin, setValueLogin] = useState('')
  107. const [valuePassword, setValuePassword] = useState('')
  108. const [flagLogin, setFlagLog] = useState(false)
  109. const [flagPassword, setFlagPass] = useState(false)
  110. return (
  111. <Box
  112. sx={{
  113. backgroundColor: "#fff",
  114. display: "flex",
  115. flexDirection: "column",
  116. justifyContent: "center",
  117. alignItems: "center",
  118. padding: "40px 60px"
  119. }}
  120. >
  121. <Typography
  122. variant='h4'
  123. letterSpacing='10px'
  124. marginBottom='30px'
  125. >
  126. REGISTER
  127. </Typography>
  128. <TextField
  129. id="login"
  130. label="Login"
  131. variant="standard"
  132. type="text"
  133. required
  134. fullWidth
  135. value={valueLogin}
  136. onChange={e => {setValueLogin(e.target.value); setFlagLog(true)}}
  137. error={flagLogin && (valueLogin.length <= 3 || valueLogin.length > 20)}
  138. sx={{marginBottom: '20px'}}
  139. />
  140. <TextField
  141. id="password"
  142. label="Password"
  143. variant="standard"
  144. type="password"
  145. required
  146. fullWidth
  147. value={valuePassword}
  148. onChange={e => {setValuePassword(e.target.value); setFlagPass(true)}}
  149. error={flagPassword && (valuePassword.length <= 3 || valuePassword.length > 20)}
  150. sx={{marginBottom: '50px'}}
  151. />
  152. <Typography
  153. variant='body2'
  154. color='#616161'
  155. textAlign='justify'
  156. marginBottom='40px'
  157. >
  158. Your personal data will be used to support your experience throughout this website, to manage access to your account, and for other purposes described in our
  159. <Link style={{textDecoration: 'none'}} to='/privacy-policy'> privacy policy</Link>
  160. .
  161. </Typography>
  162. {promise?.register?.status === "RESOLVED" &&
  163. <Typography
  164. variant='body2'
  165. color='red'
  166. marginBottom='20px'
  167. >
  168. Such user already exists
  169. </Typography>
  170. }
  171. <UnstyledButtonCustom
  172. onClick={() => {
  173. if(valuePassword.length >= 3 && valuePassword.length <= 20 &&
  174. valueLogin.length >= 3 && valueLogin.length <= 20){
  175. onRegister(valueLogin, valuePassword)
  176. }
  177. }}
  178. text={'REGISTER'}
  179. />
  180. <Box
  181. width='100%'
  182. display='flex'
  183. justifyContent='flex-end'
  184. marginTop='20px'
  185. >
  186. <Button
  187. onClick={() => setStatus('login')}
  188. >
  189. Login
  190. <ArrowForwardIosIcon/>
  191. </Button>
  192. </Box>
  193. </Box>
  194. )
  195. }
  196. return (
  197. <>
  198. <Header/>
  199. <Breadcrumb links={['my account']}/>
  200. <main style={{backgroundColor: "#f3f3f3", padding: matches ? "20px 0" : "50px 0"}}>
  201. <Container maxWidth="sm">
  202. {auth?.payload ? <Redirect to={'/profile'}/> :
  203. status === 'login' ? <Login onLogin={onLogin}/> : <Register onRegister={onRegister}/>
  204. }
  205. </Container>
  206. </main>
  207. <Footer/>
  208. </>
  209. )
  210. }
  211. const CLoginForm = connect(state => ({auth: state.auth, promise: state.promise}), {onLogin: actionFullLogin, onRegister: actionFullRegister})(MyAccountPage)
  212. export default CLoginForm