Browse Source

fixed merge conflict + fixed missing varaible name refactor

Skylsmoi 7 years ago
parent
commit
331873c0d7

+ 3 - 0
jsonserver/server.js View File

@@ -24,6 +24,9 @@ server.post('/user/login', (req, res) => {
24 24
   if (req.body.login !== '' && req.body.password !== '') return res.jsonp(jsonDb.user_logged)
25 25
   else return res.jsonp('error')
26 26
 })
27
+
28
+server.get('/user/is_logged_in', (req, res) => res.jsonp(jsonDb.user_logged))
29
+
27 30
 server.get('/workspace/:id', (req, res) => res.jsonp(jsonDb.workspace_detail))
28 31
 
29 32
 server.use(router)

+ 8 - 6
jsonserver/static_db.json View File

@@ -1,11 +1,13 @@
1 1
 {
2
-  "login": true,
3 2
   "user_logged": {
4
-    "id": 5,
5
-    "username": "Smoi",
6
-    "firstname": "Côme",
7
-    "lastname": "Stoilenom",
8
-    "email": "osef@algoo.fr"
3
+    "logged": true,
4
+    "user": {
5
+      "id": 5,
6
+      "username": "Smoi",
7
+      "firstname": "Côme",
8
+      "lastname": "Stoilenom",
9
+      "email": "osef@algoo.fr"
10
+    }
9 11
   },
10 12
   "workspace_detail": {
11 13
     "id": 1,

+ 1 - 1
package.json View File

@@ -7,7 +7,7 @@
7 7
     "mockapi": "node jsonserver/server.js",
8 8
     "servdev": "NODE_ENV=development webpack-dev-server --watch --colors --inline --hot --progress",
9 9
     "servdevwindoz": "webpack-dev-server --watch --colors --inline --hot --progress",
10
-    "servdev-dashboard": "NODE_ENV=development webpack-dashboard -- webpack-dev-server --watch --colors --inline --hot --progress",
10
+    "servdev-dashboard": "NODE_ENV=development webpack-dashboard -m -- webpack-dev-server --watch --colors --inline --hot --progress",
11 11
     "build": "NODE_ENV=production webpack -p",
12 12
     "test": "echo \"Error: no test specified\" && exit 1"
13 13
   },

+ 2 - 2
src/action-creator.async.js View File

@@ -75,9 +75,9 @@ export const userLogin = (login, password, rememberMe) => async dispatch => {
75 75
   if (fetchUserLogin.status === 200) dispatch(updateUserConnected(fetchUserLogin.json))
76 76
 }
77 77
 
78
-export const getUserConnected = () => async dispatch => {
78
+export const getIsUserConnected = () => async dispatch => {
79 79
   const fetchUserLogged = await fetchWrapper({
80
-    url: 'http://localhost:3001/user_logged',
80
+    url: 'http://localhost:3001/user/is_logged_in',
81 81
     param: {...FETCH_CONFIG, method: 'GET'},
82 82
     actionName: USER_CONNECTED,
83 83
     dispatch

+ 0 - 7
src/component/common/Card/Card.jsx View File

@@ -14,13 +14,6 @@ const Card = props => {
14 14
 export default Card
15 15
 
16 16
 Card.propTypes = {
17
-  // check https://stackoverflow.com/questions/27366077/only-allow-children-of-a-specific-type-in-a-react-component
18
-  // children: PropTypes.arrayOf( // children is an array
19
-  //   PropTypes.shape({ // of objects
20
-  //     type: PropTypes.oneOf([CardHeader, CardBody]) // that as an attribute 'type' equals to CardHeader or CardBody
21
-  //   })
22
-  // ),
23
-
24 17
   // from http://www.mattzabriskie.com/blog/react-validating-children
25 18
   children: PropTypes.arrayOf((children, key, componentName /* , location, propFullName */) => {
26 19
     if (

+ 19 - 0
src/component/common/PopinFixed/PopinFixed.jsx View File

@@ -1,6 +1,9 @@
1 1
 import React from 'react'
2 2
 import classnames from 'classnames'
3 3
 import PropTypes from 'prop-types'
4
+import PopinFixedHeader from './PopinFixedHeader.jsx'
5
+import PopinFixedOption from './PopinFixedOption.jsx'
6
+import PopinFixedContent from './PopinFixedContent.jsx'
4 7
 
5 8
 const PopinFixed = props => {
6 9
   return (
@@ -17,6 +20,22 @@ PopinFixed.propTypes = {
17 20
   visible: PropTypes.bool
18 21
 }
19 22
 
23
+PopinFixed.propTypes = {
24
+  // from http://www.mattzabriskie.com/blog/react-validating-children
25
+  children: PropTypes.arrayOf((children, key, componentName /* , location, propFullName */) => {
26
+    if (
27
+      children.length > 3 ||
28
+      children[0].type !== PopinFixedHeader ||
29
+      children[1].type !== PopinFixedOption ||
30
+      children[2].type !== PopinFixedContent
31
+    ) {
32
+      return new Error(`PropType Error: childrens of ${componentName} must be: 1 PopinFixedHeader, 1 PopinFixedOption and 1 PopinFixedContent.`)
33
+    }
34
+  }).isRequired,
35
+  customClass: PropTypes.string,
36
+  visible: PropTypes.bool
37
+}
38
+
20 39
 PopinFixed.defaultProps = {
21 40
   customClass: '',
22 41
   visible: true

src/container/PageText.jsx → src/container/FileType/PageHtml.jsx View File

@@ -1,11 +1,11 @@
1 1
 import React, { Component } from 'react'
2
-import PopinFixed from '../component/common/PopinFixed/PopinFixed'
3
-import PopinFixedHeader from '../component/common/PopinFixed/PopinFixedHeader.jsx'
4
-import PopinFixedOption from '../component/common/PopinFixed/PopinFixedOption.jsx'
5
-import PopinFixedContent from '../component/common/PopinFixed/PopinFixedContent.jsx'
6
-import Timeline from '../component/Timeline.jsx'
2
+import PopinFixed from '../../component/common/PopinFixed/PopinFixed'
3
+import PopinFixedHeader from '../../component/common/PopinFixed/PopinFixedHeader.jsx'
4
+import PopinFixedOption from '../../component/common/PopinFixed/PopinFixedOption.jsx'
5
+import PopinFixedContent from '../../component/common/PopinFixed/PopinFixedContent.jsx'
6
+import Timeline from '../../component/Timeline.jsx'
7 7
 
8
-class PageText extends Component {
8
+class PageHtml extends Component {
9 9
   render () {
10 10
     return (
11 11
       <PopinFixed customClass={'wsFileText'}>
@@ -25,7 +25,7 @@ class PageText extends Component {
25 25
   }
26 26
 }
27 27
 
28
-export default PageText
28
+export default PageHtml
29 29
 
30 30
 /*
31 31
       <div className={classnames('wsFileText wsFileGeneric', {'visible': this.props.visible})}>

src/container/Thread.jsx → src/container/FileType/Thread.jsx View File

@@ -1,6 +1,6 @@
1 1
 import React, { Component } from 'react'
2 2
 import classnames from 'classnames'
3
-import imgProfil from '../img/imgProfil.png'
3
+import imgProfil from '../../img/imgProfil.png'
4 4
 
5 5
 class Thread extends Component {
6 6
   render () {

+ 73 - 69
src/container/Login.jsx View File

@@ -1,5 +1,6 @@
1 1
 import React from 'react'
2 2
 import { connect } from 'react-redux'
3
+import { Redirect } from 'react-router'
3 4
 import LoginLogo from '../component/Login/LoginLogo.jsx'
4 5
 import LoginLogoImg from '../img/logoTracimWhite.svg'
5 6
 import { userLogin } from '../action-creator.async.js'
@@ -25,85 +26,88 @@ class Login extends React.Component {
25 26
   handleChangePassword = e => this.setState({inputPassword: e.target.value})
26 27
   handleChangeRememberMe = () => this.setState(prev => ({inputRememberMe: !prev.inputRememberMe}))
27 28
 
28
-  handleClickSubmit = () => {
29
+  handleClickSubmit = async () => {
29 30
     const { history, dispatch } = this.props
30 31
     const { inputLogin, inputPassword, inputRememberMe } = this.state
31 32
 
32
-    dispatch(userLogin(inputLogin, inputPassword, inputRememberMe))
33
-    .then(() => history.push('/'))
33
+    await dispatch(userLogin(inputLogin, inputPassword, inputRememberMe))
34
+    history.push('/')
34 35
   }
35 36
 
36 37
   render () {
37
-    return (
38
-      <section className='loginpage'>
39
-        <div className='container-fluid'>
40
-
41
-          <LoginLogo customClass='loginpage__logo' logoSrc={LoginLogoImg} />
42
-
43
-          <div className='row justify-content-center'>
44
-            <div className='col-12 col-sm-11 col-md-8 col-lg-6 col-xl-5'>
45
-
46
-              <Card customClass='loginpage__connection'>
47
-                <CardHeader customClass='connection__header text-center'>{'Connexion'}</CardHeader>
48
-
49
-                <CardBody formClass='connection__form'>
50
-                  <InputGroupText
51
-                    parentClassName='connection__form__groupemail'
52
-                    customClass='mb-3 mt-4'
53
-                    icon='fa-envelope-open-o'
54
-                    type='email'
55
-                    placeHolder='Adresse Email'
56
-                    invalidMsg='Email invalide.'
57
-                    value={this.state.inputLogin}
58
-                    onChange={this.handleChangeLogin}
59
-                  />
60
-
61
-                  <InputGroupText
62
-                    parentClassName='connection__form__groupepw'
63
-                    customClass=''
64
-                    icon='fa-lock'
65
-                    type='password'
66
-                    placeHolder='Mot de passe'
67
-                    invalidMsg='Mot de passe invalide.'
68
-                    value={this.state.inputPassword}
69
-                    onChange={this.handleChangePassword}
70
-                  />
71
-
72
-                  <div className='row mt-4 mb-4'>
73
-                    <div className='col-12 col-sm-6 col-md-6 col-lg-6 col-xl-6'>
74
-                      <InputCheckbox
75
-                        parentClassName='connection__form__rememberme'
76
-                        customClass=''
77
-                        label='Se souvenir de moi'
78
-                        checked={this.state.inputRememberMe}
79
-                        onChange={this.handleChangeRememberMe}
80
-                      />
38
+    if (this.props.user.isLoggedIn) return <Redirect to={{pathname: '/'}} />
39
+    else {
40
+      return (
41
+        <section className='loginpage'>
42
+          <div className='container-fluid'>
43
+
44
+            <LoginLogo customClass='loginpage__logo' logoSrc={LoginLogoImg} />
45
+
46
+            <div className='row justify-content-center'>
47
+              <div className='col-12 col-sm-11 col-md-8 col-lg-6 col-xl-5'>
48
+
49
+                <Card customClass='loginpage__connection'>
50
+                  <CardHeader customClass='connection__header text-center'>{'Connexion'}</CardHeader>
51
+
52
+                  <CardBody formClass='connection__form'>
53
+                    <InputGroupText
54
+                      parentClassName='connection__form__groupemail'
55
+                      customClass='mb-3 mt-4'
56
+                      icon='fa-envelope-open-o'
57
+                      type='email'
58
+                      placeHolder='Adresse Email'
59
+                      invalidMsg='Email invalide.'
60
+                      value={this.state.inputLogin}
61
+                      onChange={this.handleChangeLogin}
62
+                    />
63
+
64
+                    <InputGroupText
65
+                      parentClassName='connection__form__groupepw'
66
+                      customClass=''
67
+                      icon='fa-lock'
68
+                      type='password'
69
+                      placeHolder='Mot de passe'
70
+                      invalidMsg='Mot de passe invalide.'
71
+                      value={this.state.inputPassword}
72
+                      onChange={this.handleChangePassword}
73
+                    />
74
+
75
+                    <div className='row mt-4 mb-4'>
76
+                      <div className='col-12 col-sm-6 col-md-6 col-lg-6 col-xl-6'>
77
+                        <InputCheckbox
78
+                          parentClassName='connection__form__rememberme'
79
+                          customClass=''
80
+                          label='Se souvenir de moi'
81
+                          checked={this.state.inputRememberMe}
82
+                          onChange={this.handleChangeRememberMe}
83
+                        />
84
+                      </div>
85
+
86
+                      <div className='col-12 col-sm-6 col-md-6 col-lg-6 col-xl-6 text-sm-right'>
87
+                        <LoginBtnForgotPw
88
+                          customClass='connection__form__pwforgot'
89
+                          label='Mot de passe oublié ?'
90
+                        />
91
+                      </div>
81 92
                     </div>
82 93
 
83
-                    <div className='col-12 col-sm-6 col-md-6 col-lg-6 col-xl-6 text-sm-right'>
84
-                      <LoginBtnForgotPw
85
-                        customClass='connection__form__pwforgot'
86
-                        label='Mot de passe oublié ?'
87
-                      />
88
-                    </div>
89
-                  </div>
90
-
91
-                  <Button
92
-                    htmlType='button'
93
-                    bootstrapType='primary'
94
-                    customClass='connection__form__btnsubmit'
95
-                    label='Connexion'
96
-                    onClick={this.handleClickSubmit}
97
-                  />
98
-                </CardBody>
99
-              </Card>
100
-
94
+                    <Button
95
+                      htmlType='button'
96
+                      bootstrapType='primary'
97
+                      customClass='connection__form__btnsubmit'
98
+                      label='Connexion'
99
+                      onClick={this.handleClickSubmit}
100
+                    />
101
+                  </CardBody>
102
+                </Card>
103
+
104
+              </div>
101 105
             </div>
102
-          </div>
103 106
 
104
-        </div>
105
-      </section>
106
-    )
107
+          </div>
108
+        </section>
109
+      )
110
+    }
107 111
   }
108 112
 }
109 113
 

+ 0 - 16
src/container/Page.jsx View File

@@ -1,16 +0,0 @@
1
-import React from 'react'
2
-import { connect } from 'react-redux'
3
-
4
-class Page extends React.Component {
5
-  render () {
6
-    const { user } = this.props
7
-    return (
8
-      <div>
9
-        Page ! user Logged in : {user.isLoggedIn.toString()}
10
-      </div>
11
-    )
12
-  }
13
-}
14
-
15
-const mapStateToProps = ({ user }) => ({ user })
16
-export default connect(mapStateToProps)(Page)

+ 6 - 8
src/container/PrivateRoute.jsx View File

@@ -7,14 +7,12 @@ import { Route, Redirect, withRouter } from 'react-router-dom'
7 7
 
8 8
 // /!\ you shall destruct props.component otherwise you get a warning:
9 9
 // "You should not use <Route component> and <Route render> in the same route; <Route render> will be ignored
10
-const PrivateRoute = ({ component: Component, ...rest }) => {
11
-  return (
12
-    <Route {...rest} render={props => rest.user.isLoggedIn
13
-      ? <Component {...props} />
14
-      : <Redirect to={{pathname: '/login', state: {from: props.location}}} />
15
-    } />
16
-  )
17
-}
10
+const PrivateRoute = ({ component: Component, ...rest }) => (
11
+  <Route {...rest} render={props => rest.user.isLoggedIn
12
+    ? <Component {...props} />
13
+    : <Redirect to={{pathname: '/login', state: {from: props.location}}} />
14
+  } />
15
+)
18 16
 
19 17
 const mapStateToProps = ({ user }) => ({ user })
20 18
 export default withRouter(connect(mapStateToProps)(PrivateRoute))

+ 31 - 20
src/container/Tracim.jsx View File

@@ -4,46 +4,57 @@ import Footer from '../component/Footer.jsx'
4 4
 import Header from './Header.jsx'
5 5
 import Sidebar from './Sidebar.jsx'
6 6
 import Login from './Login.jsx'
7
-import Page from './Page.jsx'
8 7
 import WorkspaceContent from './WorkspaceContent.jsx'
9 8
 import {
10 9
   Route,
11 10
   withRouter
12 11
 } from 'react-router-dom'
13 12
 import PrivateRoute from './PrivateRoute.jsx'
14
-
15
-const SidebarWrapper = props => {
16
-  if (props.locationPath !== '/login') {
17
-    return (
18
-      <div className='sidebarpagecontainer'>
19
-        <Sidebar />
20
-        {props.children}
21
-      </div>
22
-    )
23
-  } else return props.children
24
-}
13
+import { getIsUserConnected } from '../action-creator.async.js'
25 14
 
26 15
 class Tracim extends React.Component {
16
+  componentDidMount = () => {
17
+    this.props.dispatch(getIsUserConnected())
18
+  }
19
+
27 20
   render () {
28
-    const { location } = this.props
21
+    const { user, location } = this.props
22
+
23
+    const SidebarWrapper = props => {
24
+      if (props.locationPath !== '/login') {
25
+        return (
26
+          <div className='sidebarpagecontainer'>
27
+            <Sidebar />
28
+            {props.children}
29
+          </div>
30
+        )
31
+      } else return props.children
32
+    }
33
+
29 34
     return (
30 35
       <div>
31 36
         <Header />
32 37
 
33
-        <Route path='/login' component={Login} />
38
+        { user.isLoggedIn === undefined
39
+          ? (<div />) // while we dont know if user is connected, display nothing but the header @TODO show loader
40
+          : (
41
+            <div>
42
+              <Route path='/login' component={Login} />
34 43
 
35
-        <SidebarWrapper locationPath={location.pathname}>
44
+              <SidebarWrapper locationPath={location.pathname}>
36 45
 
37
-          <PrivateRoute exact path='/' component={WorkspaceContent} />
38
-          <PrivateRoute path='/page' component={Page} />
46
+                <PrivateRoute exact path='/' component={WorkspaceContent} />
39 47
 
40
-        </SidebarWrapper>
48
+              </SidebarWrapper>
41 49
 
42
-        <Footer />
50
+              <Footer />
51
+            </div>
52
+          )
53
+        }
43 54
       </div>
44 55
     )
45 56
   }
46 57
 }
47 58
 
48
-const mapStateToProps = () => ({})
59
+const mapStateToProps = ({ user }) => ({ user })
49 60
 export default withRouter(connect(mapStateToProps)(Tracim))

+ 13 - 11
src/container/WorkspaceContent.jsx View File

@@ -3,8 +3,8 @@ import { connect } from 'react-redux'
3 3
 import Folder from '../component/Workspace/Folder.jsx'
4 4
 import FileItem from '../component/Workspace/FileItem.jsx'
5 5
 import FileItemHeader from '../component/Workspace/FileItemHeader.jsx'
6
-import Thread from './Thread.jsx'
7
-// import PageText from './PageText.jsx'
6
+// import Thread from './FileType/Thread.jsx'
7
+import PageHtml from './FileType/PageHtml.jsx'
8 8
 import PageWrapper from '../component/common/layout/PageWrapper.jsx'
9 9
 import PageTitle from '../component/common/layout/PageTitle.jsx'
10 10
 import PageContent from '../component/common/layout/PageContent.jsx'
@@ -43,21 +43,23 @@ class WorkspaceContent extends React.Component {
43 43
 
44 44
             { workspace.content.map(c => c.type === 'folder'
45 45
               ? <Folder folderData={c} key={c.id} />
46
-              : <FileItem
47
-                name={c.title}
48
-                type={c.type}
49
-                status={c.status}
50
-                onClickItem={() => this.setState({activeFileType: 'thread'})}
51
-                key={c.id}
52
-              />
46
+              : (
47
+                <FileItem
48
+                  name={c.title}
49
+                  type={c.type}
50
+                  status={c.status}
51
+                  onClickItem={() => this.setState({activeFileType: 'file'})}
52
+                  key={c.id}
53
+                />
54
+              )
53 55
             )}
54 56
           </div>
55 57
 
56 58
           <DropdownCreateButton customClass='workspace__content__button mb-5' />
57 59
 
58
-          <Thread visible={this.state.activeFileType === 'thread'} />
60
+          <PageHtml visible={this.state.activeFileType === 'file'} />
59 61
           {/*
60
-          <PageText visible={this.state.activeFileType === 'file'} />
62
+          <Thread visible={this.state.activeFileType === 'chat'} />
61 63
           */}
62 64
         </PageContent>
63 65
 

+ 2 - 2
src/css/Header.styl View File

@@ -19,7 +19,7 @@
19 19
           color blue
20 20
           font-size 16px
21 21
           &:hover
22
-            color dark-blue
22
+            color darkBlue
23 23
     &__rightside
24 24
       display flex
25 25
       margin-top 15px
@@ -60,7 +60,7 @@
60 60
         &__btnquestion
61 61
           margin-right 30px
62 62
           .btnquestion__icon
63
-            color dark-grey
63
+            color darkGrey
64 64
       &__itemprofil
65 65
         &__profilgroup
66 66
           .profilgroup__name

src/css/PageText.styl → src/css/PageHtml.styl View File


+ 3 - 3
src/css/Variable.styl View File

@@ -22,7 +22,8 @@ darkBlue = #215e8e
22 22
 blue = #2571fe
23 23
 lightBlue = #569EDE
24 24
 
25
-btnCallAction = #28a745 // couleur des boutons call2action dans le contexte generale (tout contexte sauf celui d'un type de contenu particulier)
25
+// c2a btn color in general context ; meaning every context but specific one related to file type (file, pageHtml, issues, threads ...)
26
+btnCallAction = #28a745
26 27
 btnCallAction-hover = darken(btnCallAction, 15%)
27 28
 
28 29
 threadColor = #2674d3
@@ -41,13 +42,12 @@ issueColor = #a4835e
41 42
 // calendarColor =
42 43
 // dashboard =
43 44
 
44
-
45 45
 /*************************/
46 46
 /**** BOX SHADOW ****/
47 47
 shadow-bottom = 0px 0px 5px 1px #606060
48 48
 shadow-right = 2px 2px 5px 0px #404040
49 49
 shadow-all = 1px 1px 5px 2px #ababab
50
-shadow-all-side-blue = 0px 0px 1px 1px light-blue
50
+shadow-all-side-blue = 0px 0px 1px 1px lightBlue
51 51
 shadow-all-side-green = 0 0 1px 2px green
52 52
 
53 53
 /***********************/

+ 1 - 1
src/css/index.styl View File

@@ -18,5 +18,5 @@ html, body, #content, #content > div
18 18
 @import 'Folder'
19 19
 
20 20
 @import 'Thread'
21
-@import 'PageText'
21
+@import 'PageHtml'
22 22
 @import 'Timeline'

+ 12 - 2
src/reducer/user.js View File

@@ -3,8 +3,18 @@ import {
3 3
   USER_DATA
4 4
 } from '../action-creator.sync.js'
5 5
 
6
+const serializeUser = data => ({
7
+  id: data.user.id,
8
+  isLoggedIn: data.logged,
9
+  username: data.user.username,
10
+  firstname: data.user.firstname,
11
+  lastname: data.user.lastname,
12
+  email: data.user.email
13
+})
14
+
6 15
 export default function user (state = {
7
-  isLoggedIn: false,
16
+  id: 0,
17
+  isLoggedIn: undefined,
8 18
   username: '',
9 19
   firstname: '',
10 20
   lastname: '',
@@ -12,7 +22,7 @@ export default function user (state = {
12 22
 }, action) {
13 23
   switch (action.type) {
14 24
     case `Update/${USER_CONNECTED}`:
15
-      return {...state, isLoggedIn: true, ...action.user}
25
+      return serializeUser(action.user)
16 26
 
17 27
     case `Update/${USER_DATA}`:
18 28
       return {...state, ...action.data}