MyAccountPage.jsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import {Container, Typography, useMediaQuery} from "@mui/material";
  2. import {useState} from "react";
  3. import Breadcrumb from "../../components/Breadcrumbs";
  4. import Redirect from "react-router-dom/es/Redirect";
  5. import Link from "react-router-dom/es/Link";
  6. import {connect} from "react-redux";
  7. import {actionFullLogin, actionFullRegister} from "../../actions/ActionLogin";
  8. import {actionClearPromise} from "../../reducers/PromiseReducer";
  9. import {Form} from "./Form";
  10. const MyAccountPage = ({auth, promise, user, onLogin, onRegister, onClear}) => {
  11. const matches = useMediaQuery('(max-width:899px)')
  12. const [status, setStatus] = useState('login')
  13. if (auth?.payload && Object.keys(user).length !== 0){
  14. onClear('login');
  15. onClear('register');
  16. }
  17. return (
  18. <>
  19. <Breadcrumb links={['my account']}/>
  20. <main
  21. style={{
  22. backgroundColor: "#f3f3f3",
  23. padding: matches ? "20px 0" : "50px 0",
  24. minHeight:'300px'
  25. }}
  26. >
  27. <Container maxWidth="sm">
  28. {(auth?.payload && Object.keys(user).length !== 0) ?
  29. <Redirect to={'/profile'}/>
  30. :
  31. status === 'login' ?
  32. <Form
  33. title={'LOGIN'}
  34. target={'register'}
  35. onClickEvent={onLogin}
  36. setStatus={value => setStatus(value)}
  37. children={
  38. <>
  39. {promise?.login?.status === "RESOLVED" &&
  40. <Typography
  41. variant='body2'
  42. color='red'
  43. marginBottom='20px'
  44. >
  45. This user does not exist
  46. </Typography>
  47. }
  48. </>
  49. }
  50. />
  51. :
  52. <Form
  53. title={'REGISTER'}
  54. target={'login'}
  55. onClickEvent={onRegister}
  56. setStatus={value => setStatus(value)}
  57. children={
  58. <>
  59. <Typography
  60. variant='body2'
  61. color='#616161'
  62. textAlign='justify'
  63. marginBottom='40px'
  64. >
  65. Your personal data will be used to support your experience throughout
  66. this website, to manage access to your account, and for other purposes
  67. described in our
  68. <Link
  69. style={{textDecoration: 'none'}}
  70. to='/privacy-policy'
  71. >
  72. {' privacy policy'}
  73. </Link>
  74. .
  75. </Typography>
  76. {promise?.register?.status === "RESOLVED" &&
  77. <Typography
  78. variant='body2'
  79. color='red'
  80. marginBottom='20px'
  81. >
  82. Such user already exists
  83. </Typography>
  84. }
  85. </>
  86. }
  87. />
  88. }
  89. </Container>
  90. </main>
  91. </>
  92. )
  93. }
  94. const CLoginForm = connect(state => ({auth: state.auth, promise: state.promise, user: state.user}),
  95. {onLogin: actionFullLogin, onRegister: actionFullRegister,
  96. onClear: actionClearPromise})(MyAccountPage)
  97. export default CLoginForm