MyAccountPage.jsx 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import Breadcrumb from "../components/Breadcrumbs";
  2. import {
  3. Box,
  4. Button,
  5. Container,
  6. TextField,
  7. Typography,
  8. useMediaQuery
  9. } from "@mui/material";
  10. import UnstyledButtonCustom from "../components/MainButton";
  11. import ArrowForwardIosIcon from '@mui/icons-material/ArrowForwardIos';
  12. import {useState} from "react";
  13. import Link from "react-router-dom/es/Link";
  14. import {connect} from 'react-redux';
  15. import {actionFullLogin, actionFullRegister} from "../actions/ActionLogin";
  16. import Redirect from "react-router-dom/es/Redirect";
  17. const MyAccountPage = ({auth, promise, user, onLogin, onRegister}) => {
  18. const matches = useMediaQuery('(max-width:899px)')
  19. const [status, setStatus] = useState('login')
  20. const Form = ({title, target, onClickEvent, children}) => {
  21. const matches2 = useMediaQuery('(max-width:450px)')
  22. const [valueLogin, setValueLogin] = useState('')
  23. const [valuePassword, setValuePassword] = useState('')
  24. const [flagLogin, setFlagLog] = useState(false)
  25. const [flagPassword, setFlagPass] = useState(false)
  26. return (
  27. <Box
  28. sx={{
  29. backgroundColor: "#fff",
  30. display: "flex",
  31. flexDirection: "column",
  32. justifyContent: "center",
  33. alignItems: "center",
  34. padding: matches2 ? "30px 20px" : "40px 60px"
  35. }}
  36. >
  37. <Typography
  38. variant='h4'
  39. letterSpacing='10px'
  40. marginBottom='30px'
  41. >
  42. {title}
  43. </Typography>
  44. <TextField
  45. id="login"
  46. label="Login"
  47. variant="standard"
  48. type="text"
  49. required
  50. fullWidth
  51. value={valueLogin}
  52. onChange={e => {setValueLogin(e.target.value); setFlagLog(true)}}
  53. error={flagLogin && (valueLogin.length < 3 || valueLogin.length > 20)}
  54. sx={{marginBottom: '20px'}}
  55. />
  56. <TextField
  57. id="password"
  58. label="Password"
  59. variant="standard"
  60. type="password"
  61. required
  62. fullWidth
  63. value={valuePassword}
  64. onChange={e => {setValuePassword(e.target.value); setFlagPass(true)}}
  65. error={flagPassword && (valuePassword.length < 3 || valuePassword.length > 20)}
  66. sx={{marginBottom: '30px'}}
  67. />
  68. {children}
  69. <UnstyledButtonCustom
  70. onClick={() => {
  71. if(valuePassword.length >= 3 && valuePassword.length <= 20 &&
  72. valueLogin.length >= 3 && valueLogin.length <= 20) {
  73. onClickEvent(valueLogin, valuePassword)
  74. }
  75. }}
  76. text={title}
  77. />
  78. <Box
  79. width='100%'
  80. display='flex'
  81. justifyContent='flex-end'
  82. marginTop='20px'
  83. >
  84. <Button
  85. onClick={() => setStatus(target)}
  86. >
  87. {target}
  88. <ArrowForwardIosIcon/>
  89. </Button>
  90. </Box>
  91. </Box>
  92. )
  93. }
  94. return (
  95. <>
  96. <Breadcrumb links={['my account']}/>
  97. <main style={{backgroundColor: "#f3f3f3", padding: matches ? "20px 0" : "50px 0"}}>
  98. <Container maxWidth="sm">
  99. {(auth?.payload && Object.keys(user).length !== 0) ? <Redirect to={'/profile'}/>:
  100. status === 'login' ?
  101. <Form title={'LOGIN'} target={'register'} onClickEvent={onLogin} children={
  102. <>
  103. {promise?.login?.status === "RESOLVED" &&
  104. <Typography
  105. variant='body2'
  106. color='red'
  107. marginBottom='20px'
  108. >
  109. This user does not exist
  110. </Typography>
  111. }
  112. </>
  113. }/> :
  114. <Form title={'REGISTER'} target={'login'} onClickEvent={onRegister} children={
  115. <>
  116. <Typography
  117. variant='body2'
  118. color='#616161'
  119. textAlign='justify'
  120. marginBottom='40px'
  121. >
  122. 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
  123. <Link style={{textDecoration: 'none'}} to='/privacy-policy'> privacy policy</Link>
  124. .
  125. </Typography>
  126. {promise?.register?.status === "RESOLVED" &&
  127. <Typography
  128. variant='body2'
  129. color='red'
  130. marginBottom='20px'
  131. >
  132. Such user already exists
  133. </Typography>
  134. }
  135. </>
  136. }/>
  137. }
  138. </Container>
  139. </main>
  140. </>
  141. )
  142. }
  143. const CLoginForm = connect(state => ({auth: state.auth, promise: state.promise, user: state.user}), {onLogin: actionFullLogin, onRegister: actionFullRegister})(MyAccountPage)
  144. export default CLoginForm