Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.20 KB | None | 0 0
  1. import React, { Component, Suspense, lazy } from 'react'
  2. import { Route, Switch, Redirect, withRouter } from 'react-router-dom'
  3. import config from 'src/settings/formsConfig'
  4.  
  5. // Components
  6. import Header from 'src/components/Navigation/Header'
  7. import Info from 'src/components/Auth/InfoWrap'
  8. import Loader from 'src/components/shared/Loader'
  9.  
  10. // Styles
  11. import { AuthRoutesContainer, AuthWrapper } from '../Layout/style'
  12.  
  13. // LAZY LOADING COMPONENTS (On my opinion this isn't good)
  14. const Login = lazy(() =>
  15. import(/* webpackChunkName: "Login" */ '../../components/Auth/Login/Login'),
  16. )
  17. const SignUp = lazy(() =>
  18. import(/* webpackChunkName: "SignUp" */ '../../components/Auth/Registration'),
  19. )
  20. const ForgotPassword = lazy(() =>
  21. import(/* webpackChunkName: "ForgotPassword" */ '../../components/Auth/ForgotPassword'),
  22. )
  23. const RegistrationSuccess = lazy(() =>
  24. import(/* webpackChunkName: "RegistrationSuccess" */ '../../components/Auth/Registration/Success'),
  25. )
  26. const ForgotPasswordSuccess = lazy(() =>
  27. import(/* webpackChunkName: "ForgotPasswordSuccess" */ '../../components/Auth/ForgotPassword/Success'),
  28. )
  29. const WrongPassword3Times = lazy(() =>
  30. import(/* webpackChunkName: "WrongPassword3Times" */ '../../components/Auth/Login/WrongPassword3Times'),
  31. )
  32. const BlockUser = lazy(() =>
  33. import(/* webpackChunkName: "WrongPassword3Times" */ '../../components/Auth/BlockUser'),
  34. )
  35. const Sprite = lazy(() => import(/* webpackChunkName: "Sprite" */ 'src/components/Auth/sprite.js'))
  36.  
  37. class AuthLayout extends Component {
  38. state = {
  39. isWideStyle: false,
  40. isAttentionShowed: false,
  41. login: ''
  42. }
  43.  
  44. // Remove this and modify width inside Info component's styles
  45. static getDerivedStateFromProps(nextProps) {
  46. const { pathname } = nextProps.location
  47. if (pathname === '/forgot-password' || pathname === '/block-user') {
  48. return { isWideStyle: true }
  49. }
  50. return { isWideStyle: false }
  51. }
  52.  
  53. // Attention toggle
  54. showAttention = () => this.setState({ isAttentionShowed: true })
  55.  
  56. hideAttention = () => this.setState({ isAttentionShowed: false })
  57.  
  58. loginChangeHandler = (value) => this.setState({login: value})
  59.  
  60. render() {
  61. // Destructuring values
  62. const { isWideStyle, isAttentionShowed, login } = this.state
  63. console.log(this.state)
  64. return (
  65. <AuthWrapper className="flex AuthWrapper">
  66. <AuthRoutesContainer isWideStyle={isWideStyle} className="flex">
  67. <Header />
  68. <Suspense fallback={<Loader message="Loading..." />}>
  69. <Sprite />
  70. <Switch>
  71. <Route
  72. path="/login"
  73. component={props => (
  74. <Login
  75. config={config.auth.login}
  76. isAttentionShowed={isAttentionShowed}
  77. showAttention={this.showAttention}
  78. hideAttention={this.hideAttention}
  79. loginChangeHandler={this.loginChangeHandler}
  80. login={login}
  81. {...props}
  82. />
  83. )}
  84. />
  85. <Route
  86. path="/sign-up"
  87. component={props => <SignUp config={config.auth.register} {...props} />}
  88. />
  89. <Route
  90. path="/forgot-password"
  91. component={props => (
  92. <ForgotPassword config={config.auth.forgotPassword} {...props} />
  93. )}
  94. />
  95. <Route
  96. path="/forgot-password-success"
  97. component={props => <ForgotPasswordSuccess {...props} />}
  98. />
  99. <Route
  100. path="/wrong-password"
  101. component={props => <WrongPassword3Times {...props} />}
  102. />
  103. <Route
  104. path="/registration-success"
  105. component={props => <RegistrationSuccess {...props} />}
  106. />
  107. <Route
  108. path="/block-user"
  109. component={props => <BlockUser {...props} config={config.auth.blockUser} />}
  110. />
  111. <Redirect path="*" to="/login" />
  112. </Switch>
  113. </Suspense>
  114. </AuthRoutesContainer>
  115. <Info isWideStyle={isWideStyle} />
  116. </AuthWrapper>
  117. )
  118. }
  119. }
  120.  
  121. export default withRouter(AuthLayout)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement