Bläddra i källkod

Merge branch 'dev' of gitlab.a-level.com.ua:Entony/F_A_8_Test_app into Sveta

Svetlana 5 år sedan
förälder
incheckning
baeabd9d80

+ 0 - 34
src/components/common/input-form.js

@@ -1,34 +0,0 @@
-import React, { Component } from "react";
-import { connect } from "react-redux";
-import { reduxForm, Field, FieldArray } from "redux-form";
-
-const renderField = ({ input, meta: { touched, error }, label, type }) => (
-	<div className="form__input-box">
-		<label className="form__input-lable" htmlFor="origin">
-			{label}
-			<input type={type} {...input} />
-		</label>
-		{touched && error && <span>{error}</span>}
-	</div>
-);
-
-class LoadForm extends Component {
-	
-	render() {
-		const { handleSubmit, title, pristine, submitting } = this.props;
-
-		return (
-			<form onSubmit={handleSubmit(this.submit)} className="form">
-				
-			</form>
-		);
-	}
-}
-
-const mapStateToProps = (state, props) => ({
-});
-
-const component = reduxForm({ })(LoadForm);
-
-export default connect(mapStateToProps)(component);
-

+ 27 - 10
src/components/common/protectedRoute/index.js

@@ -1,34 +1,51 @@
 import React from 'react';
 import { Route, Redirect } from 'react-router-dom';
 
+import token from '../../../utils/token'
+
 import * as routes from './../../../constants/routes';
 import PermissionDenied from './../../public-components/permissionDenied';
 
-export default ({ component: Component, user: {data}, access, ...rest  }) => (
+export default ({ component: Component, user: { data }, tokenAuth, access, ...rest }) => (
     <Route
         {...rest}
         render={props => {
+            let checkedData;
+
+            if (data) {
+                checkedData = data;
+            }
+            else {
+                const storagedUser = JSON.parse(localStorage.getItem(token));
+                if (storagedUser) {
+                    checkedData = storagedUser;
+                    tokenAuth(storagedUser);
+                } 
+                else {
+                    checkedData = null;
+                }
+            }
 
             if (access === 'public') {
                 return <Component {...props} />
             }
-            
-            if ( (access === 'user-only' || access === 'admin-only') && !data ) {
-                return <Redirect to={routes.SIGN_IN}/>
+
+            if ((access === 'user-only' || access === 'admin-only') && !checkedData) {
+                return <Redirect to={routes.SIGN_IN} />
             }
-            
-            if (access === 'user-only' && data) {
+
+            if (access === 'user-only' && checkedData) {
                 return <Component {...props} />
-            }        
+            }
 
             if (access === 'admin-only') {
-                if (data.is_admin) {
+                if (checkedData.is_admin) {
                     return <Component {...props} />
-                } 
+                }
 
                 return <PermissionDenied />
             }
-            
+
         }}
     />
 )

+ 0 - 6
src/components/common/protectedRoute/validate/index.js

@@ -1,6 +0,0 @@
-export default function validate(values) {
-    const {} = values;
-    const errors = {}
-
-    return errors;
-}

+ 3 - 0
src/components/public-components/auth/signUpForm/index.js

@@ -30,6 +30,9 @@ class Form extends React.Component {
                 </div>
 
                 <button className="sign-form__link--with-margin link--btn link--btn6s0" disabled={invalid}>Create Account</button>
+
+                <hr className="sign-form__divider" />
+
                 <p className="sign-form__agreement">By clicking this button you actually would donate us your flat !</p>
             </form>
         )

+ 24 - 22
src/components/public-components/header/index.js

@@ -2,13 +2,16 @@ import React, { Component } from 'react';
 import { Link } from "react-router-dom";
 
 import * as routes from './../../../constants/routes';
-import { UserContext } from './../../../containers/header';
 import token from './../../../utils/token';
 
 export default class header extends Component {
 
     state = {
-        togglerClosed: true,
+        togglerClosed: true
+    }
+
+    handleClick = () => {
+        this.setState({ togglerClosed: true })
     }
 
     handleToggle = event => {
@@ -28,54 +31,53 @@ export default class header extends Component {
 
         return (
             <header className="header">
-                <Link to={routes.LANDING}>
+                <Link onClick={this.handleClick} to={routes.LANDING}>
                     <h1 className="header__logo">Test.<span className="header__logo--i-letter">i</span>o</h1>
                 </Link>
                 <hr className="header__logo--divider" />
-                {/* <span className="header__toggle-trigger" onClick={this.handleToggle} >
+                <span className="header__toggle-trigger" onClick={this.handleToggle} >
                     <span />
-                </span> */}
-                <button style={{ position: "absolute", top: '85px', left: 0 }} onClick={this.handleToggle}>HEADER TOGGLE</button>
+                </span>
                 <div className="header__flex-wrapper">
                     <nav className={`header__nav ${toggleStatus}`}>
                         <ul className="header__nav nav__list"  >
                             <li>
-                                <Link className="header__nav nav__list-item" to={routes.HOME}>
+                                <Link onClick={this.handleClick} className="header__nav nav__list-item" to={routes.HOME}>
                                     Home
-                </Link>
+                                </Link>
                             </li>
                             <li>
-                                <Link className="header__nav nav__list-item" to={routes.PROFILE}>
+                                <Link onClick={this.handleClick} className="header__nav nav__list-item" to={routes.PROFILE}>
                                     Profile
-                </Link>
+                                </Link>
                             </li>
                             <li>
-                                <Link className="header__nav nav__list-item" to={routes.TESTS}>
+                                <Link onClick={this.handleClick} className="header__nav nav__list-item" to={routes.TESTS}>
                                     Test
-                </Link>
+                                </Link>
                             </li>
                             <li>
-                                <Link className="header__nav nav__list-item" to={routes.CATEGORIES}>
+                                <Link onClick={this.handleClick} className="header__nav nav__list-item" to={routes.CATEGORIES}>
                                     Categories
-                </Link>
+                                </Link>
                             </li>
                             {
                                 data && data.is_admin && (
                                     <React.Fragment>
                                         <li>
-                                            <Link className="header__nav nav__list-item--admin-only" to={routes.CREATE_TEST}>
+                                            <Link onClick={this.handleClick} className="header__nav nav__list-item--admin-only" to={routes.CREATE_TEST}>
                                                 Create test
-                            </Link>
+                                            </Link>
                                         </li>
                                         <li>
-                                            <Link className="header__nav nav__list-item--admin-only" to={routes.CREATE_CATEGORY}>
+                                            <Link onClick={this.handleClick} className="header__nav nav__list-item--admin-only" to={routes.CREATE_CATEGORY}>
                                                 Create category
-                            </Link>
+                                            </Link>
                                         </li>
                                         <li>
-                                            <Link className="header__nav nav__list-item--admin-only" to={routes.DELETE_USER}>
+                                            <Link onClick={this.handleClick} className="header__nav nav__list-item--admin-only" to={routes.DELETE_USER}>
                                                 Delete data
-                            </Link>
+                                            </Link>
                                         </li>
                                     </React.Fragment>
                                 )
@@ -88,8 +90,8 @@ export default class header extends Component {
                             !data
                                 ? (
                                     <React.Fragment>
-                                        <Link className="header__links--sign-in link--btn link--btn25" to={routes.SIGN_IN}>Sign in</Link>
-                                        <Link className="header__links--sign-up link--btn link--btn25" to={routes.SIGN_UP}>Sign up</Link>
+                                        <Link onClick={this.handleClick} className="header__links--sign-in link--btn link--btn25" to={routes.SIGN_IN}>Sign in</Link>
+                                        <Link onClick={this.handleClick} className="header__links--sign-up link--btn link--btn25" to={routes.SIGN_UP}>Sign up</Link>
                                     </React.Fragment>
                                 )
                                 : (

+ 12 - 22
src/router.js

@@ -16,35 +16,25 @@ import fakeToken from './utils/token'
 import { bindActionCreators } from "redux";
 
 class Router extends React.Component {
-
-    componentDidMount() {
-        const storagedUser = localStorage.getItem(fakeToken);
-        const { tokenAuth } = this.props;
-
-
-        storagedUser && tokenAuth(JSON.parse(storagedUser));
-    }
-
     render() {
-        const { user } = this.props;
-        
-        //map located here because of switch-bag
-        const Router = config.map(route =>
-            <ProtectedRoute
-                path={route.path}
-                component={route.component}
-                access={route.access}
-                user={user}
-                exact
-            />
-        )
+        const { user, tokenAuth } = this.props;
 
         return (
             <div className="app">
                 <Header />
                 <Suspense fallback={<Spinner />}>
                     <Switch>
-                        {Router}
+                        {config.map(route =>
+                            <ProtectedRoute
+                                path={route.path}
+                                component={route.component}
+                                access={route.access}
+                                user={user}
+                                key={route}
+                                tokenAuth={tokenAuth}
+                                exact
+                            />
+                        )}
                     </Switch>
                 </Suspense>
                 <Footer />

+ 13 - 13
src/saga/auth/signIn/index.js

@@ -7,18 +7,18 @@ import token from '../../../utils/token'
 // worker-saga for signing in
 
 export default function* ({ payload: { login, password } }) {
-  try {
-    const payload = yield call(() =>
-      axios.get(`${SIGN_IN_URL}login=${login}&password=${password}`)
-        .then(({ data: [payload] }) => payload)
-    );
+    try {
+        const payload = yield call(() =>
+            axios.get(`${SIGN_IN_URL}login=${login}&password=${password}`)
+                .then(({ data: [payload] }) => payload)
+        );
 
-    yield call(() => { if (!payload) throw (new Error("No such email or password")) });
-    yield put(actions.signInRequestSucces(payload));
-    yield call(() => localStorage.setItem(token, JSON.stringify(payload)));
-  }
-  catch ({ message }) {
-    yield put(actions.signInRequestFailure(message));
-    yield call(() => localStorage.removeItem(token));
-  }
+        yield call(() => { if (!payload) throw (new Error("No such email or password")) });
+        yield put(actions.signInRequestSucces(payload));
+        yield call(() => localStorage.setItem(token, JSON.stringify(payload)));
+    }
+    catch ({ message }) {
+        yield put(actions.signInRequestFailure(message));
+        yield call(() => localStorage.removeItem(token));
+    }
 }

+ 1 - 0
src/styles/components/_button.scss

@@ -1,5 +1,6 @@
 .link {
     &--btn {
+        display: inline-block !important;
         text-transform: uppercase;
         font-family: 'Poiret One', cursive;
         font-weight: bold;

+ 2 - 2
src/styles/components/_header.scss

@@ -76,7 +76,7 @@
         }
         &__toggle-trigger {
             position: absolute;
-            top: 70%;
+            top: 65%;
             cursor: pointer;
             left: 0;
             margin-left: 1em;
@@ -145,12 +145,12 @@
         .header__links {
             display: flex;
             justify-content: center;
-
             &--sign-in {
                 margin-right: 1.5vw;
             }
             &--sign-up {
                 margin-left: 1.5vw;
+                margin-right: 0;
             }
         }
     }

+ 8 - 3
src/styles/components/_landingPage.scss

@@ -32,22 +32,27 @@
         justify-content: space-between;
         width: 25%;
         padding: 9vh;
+        @media screen and (max-width: 1125px) {
+            padding: 4vh 7vh;
+        }
     }
     // not correct spelling -> have to ask && change
     &__links {
         border: none;
         box-shadow: 0 0 10px grey;
         background: rgba(232,230, 230, 0.9);
-        padding: 3vh 0;
-        margin: 5px;
         text-transform: uppercase;
+        margin: 5px;
+        padding: 3vh 0;
         font-family: 'Cormorant Infant', serif;
         font-weight: bold;
         font-size: 16px;
         text-align: center;
         width: 20vh;
-            @media screen and (max-width: 1125px) {
+        @media screen and (max-width: 1125px) {
                 width: 100%;
+                margin: 10px 0;
+                padding: 2.5vh 0;
             }
         transition: all 0.6s ease-in-out;
     }

+ 1 - 1
src/styles/components/_signPage.scss

@@ -22,7 +22,7 @@
             margin: 0 0 35px 0;
         }
         &__password-container {
-            margin: 50px 0;
+            margin: 50px 0 20px 0;
         }
         &__input {
             display: block;