Browse Source

cookies name are now in a constant

Skylsmoi 5 years ago
parent
commit
c698a1d9d8
5 changed files with 18 additions and 14 deletions
  1. 4 4
      src/container/Header.jsx
  2. 4 5
      src/container/Login.jsx
  3. 1 1
      src/container/PrivateRoute.jsx
  4. 4 4
      src/container/Tracim.jsx
  5. 5 0
      src/helper.js

+ 4 - 4
src/container/Header.jsx View File

@@ -2,10 +2,10 @@ import React from 'react'
2 2
 import { connect } from 'react-redux'
3 3
 import i18n from '../i18n.js'
4 4
 import { translate } from 'react-i18next'
5
+import Cookies from 'js-cookie'
5 6
 import Logo from '../component/Header/Logo.jsx'
6 7
 import NavbarToggler from '../component/Header/NavbarToggler.jsx'
7 8
 import MenuLinkList from '../component/Header/MenuLinkList.jsx'
8
-// import MenuActionList from '../component/Header/MenuActionList.jsx'
9 9
 import MenuActionListItemSearch from '../component/Header/MenuActionListItem/Search.jsx'
10 10
 import MenuActionListItemDropdownLang from '../component/Header/MenuActionListItem/DropdownLang.jsx'
11 11
 import MenuActionListItemHelp from '../component/Header/MenuActionListItem/Help.jsx'
@@ -20,7 +20,7 @@ import {
20 20
 import {
21 21
   postUserLogout
22 22
 } from '../action-creator.async.js'
23
-import Cookies from 'js-cookie'
23
+import { COOKIE } from '../helper.js'
24 24
 
25 25
 class Header extends React.Component {
26 26
   handleClickLogo = () => {}
@@ -44,8 +44,8 @@ class Header extends React.Component {
44 44
 
45 45
     const fetchPostUserLogout = await dispatch(postUserLogout())
46 46
     if (fetchPostUserLogout.status === 204) {
47
-      Cookies.remove('user_login')
48
-      Cookies.remove('user_auth')
47
+      Cookies.remove(COOKIE.USER_LOGIN)
48
+      Cookies.remove(COOKIE.USER_AUTH)
49 49
 
50 50
       dispatch(setUserDisconnected())
51 51
     } else {

+ 4 - 5
src/container/Login.jsx View File

@@ -2,6 +2,7 @@ import React from 'react'
2 2
 import { connect } from 'react-redux'
3 3
 import { Redirect } from 'react-router'
4 4
 import { translate } from 'react-i18next'
5
+import Cookies from 'js-cookie'
5 6
 import LoginLogo from '../component/Login/LoginLogo.jsx'
6 7
 import LoginLogoImg from '../img/logoTracimWhite.svg'
7 8
 import { postUserLogin } from '../action-creator.async.js'
@@ -9,15 +10,13 @@ import Card from '../component/common/Card/Card.jsx'
9 10
 import CardHeader from '../component/common/Card/CardHeader.jsx'
10 11
 import CardBody from '../component/common/Card/CardBody.jsx'
11 12
 import InputGroupText from '../component/common/Input/InputGroupText.jsx'
12
-// import InputCheckbox from '../component/common/Input/InputCheckbox.jsx'
13 13
 import Button from '../component/common/Input/Button.jsx'
14 14
 import LoginBtnForgotPw from '../component/Login/LoginBtnForgotPw.jsx'
15 15
 import {
16 16
   newFlashMessage,
17 17
   setUserConnected
18 18
 } from '../action-creator.sync.js'
19
-import { PAGE } from '../helper.js'
20
-import Cookies from 'js-cookie'
19
+import { COOKIE, PAGE } from '../helper.js'
21 20
 
22 21
 class Login extends React.Component {
23 22
   constructor (props) {
@@ -53,8 +52,8 @@ class Login extends React.Component {
53 52
         logged: true
54 53
       }))
55 54
 
56
-      Cookies.set('user_login', inputLogin.value)
57
-      Cookies.set('user_auth', userAuth)
55
+      Cookies.set(COOKIE.USER_LOGIN, inputLogin.value)
56
+      Cookies.set(COOKIE.USER_AUTH, userAuth)
58 57
 
59 58
       history.push(PAGE.HOME)
60 59
     } else if (fetchPostUserLogin.status === 400) {

+ 1 - 1
src/container/PrivateRoute.jsx View File

@@ -9,7 +9,7 @@ import { Route, Redirect, withRouter } from 'react-router-dom'
9 9
 // "You should not use <Route component> and <Route render> in the same route; <Route render> will be ignored
10 10
 const PrivateRoute = ({ component: Component, ...rest }) => (
11 11
   <Route {...rest} render={props => rest.user.logged
12
-    ? <Component {...props} /> // user logged, return composant
12
+    ? <Component {...props} /> // user logged, return component
13 13
     : rest.user.logged === null
14 14
       ? <div /> // dont know if user logged yet (waiting for api to respond), do nothing @TODO display loader
15 15
       : <Redirect to={{pathname: '/login', state: {from: props.location}}} /> // // user not logged, redirect to login page

+ 4 - 4
src/container/Tracim.jsx View File

@@ -13,7 +13,7 @@ import {
13 13
   Route, withRouter, Switch
14 14
 } from 'react-router-dom'
15 15
 import PrivateRoute from './PrivateRoute.jsx'
16
-import { PAGE } from '../helper.js'
16
+import { COOKIE, PAGE } from '../helper.js'
17 17
 import {
18 18
   getUserIsConnected
19 19
 } from '../action-creator.async.js'
@@ -28,8 +28,8 @@ class Tracim extends React.Component {
28 28
     const { dispatch } = this.props
29 29
 
30 30
     const userFromCookies = {
31
-      email: Cookies.get('user_login'),
32
-      auth: Cookies.get('user_auth')
31
+      email: Cookies.get(COOKIE.USER_LOGIN),
32
+      auth: Cookies.get(COOKIE.USER_AUTH)
33 33
     }
34 34
 
35 35
     const fetchGetUserIsConnected = await dispatch(getUserIsConnected(userFromCookies))
@@ -51,7 +51,7 @@ class Tracim extends React.Component {
51 51
   handleRemoveFlashMessage = msg => this.props.dispatch(removeFlashMessage(msg))
52 52
 
53 53
   render () {
54
-    const { flashMessage, user, t } = this.props
54
+    const { flashMessage, t } = this.props
55 55
 
56 56
     return (
57 57
       <div className='tracim'>

+ 5 - 0
src/helper.js View File

@@ -7,6 +7,11 @@ export const FETCH_CONFIG = {
7 7
   mockApiUrl: 'http://localhost:3001'
8 8
 }
9 9
 
10
+export const COOKIE = {
11
+  USER_LOGIN: 'user_login',
12
+  USER_AUTH: 'user_auth'
13
+}
14
+
10 15
 export const PAGE = {
11 16
   HOME: '/',
12 17
   WORKSPACE: {