MyAccountPage.jsx 4.7 KB

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