Browse Source

fixed popin fixed, timeline and textareaapp

Skylsmoi 6 years ago
parent
commit
369f045029

+ 23 - 3
src/component/Input/TextAreaApp/TextAreaApp.jsx View File

1
 import React from 'react'
1
 import React from 'react'
2
-// import classnames from 'classnames'
2
+import PropTypes from 'prop-types'
3
 
3
 
4
 require('./TextAreaApp.styl')
4
 require('./TextAreaApp.styl')
5
 
5
 
6
 export const TextAreaApp = props =>
6
 export const TextAreaApp = props =>
7
   <form className={`${props.customClass} editionmode`}>
7
   <form className={`${props.customClass} editionmode`}>
8
-    <textarea className={`${props.customClass}__text editionmode__text`} />
8
+    <textarea
9
+      className={`${props.customClass}__text editionmode__text`}
10
+      value={props.text}
11
+      onChange={props.onChangeText}
12
+    />
13
+
9
     <div className={`${props.customClass}__button editionmode__button`}>
14
     <div className={`${props.customClass}__button editionmode__button`}>
10
       <button
15
       <button
11
         type='button'
16
         type='button'
14
       >
19
       >
15
         Annuler
20
         Annuler
16
       </button>
21
       </button>
17
-      <button type='submit' className={`${props.customClass}__submit editionmode__button__submit btn btn-outline-primary`}>Valider</button>
22
+
23
+      <button
24
+        type='button'
25
+        className={`${props.customClass}__submit editionmode__button__submit btn btn-outline-primary`}
26
+        onClick={props.onClickValidateBtn}
27
+      >
28
+        Valider
29
+      </button>
18
     </div>
30
     </div>
19
   </form>
31
   </form>
20
 
32
 
21
 export default TextAreaApp
33
 export default TextAreaApp
34
+
35
+TextAreaApp.propTypes = {
36
+  text: PropTypes.string.isRequired,
37
+  onChangeText: PropTypes.func.isRequired,
38
+  onClickCancelBtn: PropTypes.func.isRequired,
39
+  onClickValidateBtn: PropTypes.func.isRequired,
40
+  customClass: PropTypes.string
41
+}

+ 26 - 18
src/component/PopinFixed/PopinFixedHeader.jsx View File

6
   constructor (props) {
6
   constructor (props) {
7
     super(props)
7
     super(props)
8
     this.state = {
8
     this.state = {
9
-      editTitle: false
9
+      editTitle: false,
10
+      editTitleValue: ''
10
     }
11
     }
11
   }
12
   }
12
 
13
 
13
-  handleClickChangeTitleBtn = () => this.setState(prevState => ({
14
-    editTitle: !prevState.editTitle
15
-  }))
14
+  componentDidUpdate (prevProps) {
15
+    if (prevProps.title !== this.props.title) this.setState({editTitleValue: this.props.title})
16
+  }
17
+
18
+  onChangeTitle = e => {
19
+    const newTitle = e.target.value
20
+    this.setState({editTitleValue: newTitle})
21
+  }
22
+
23
+  handleClickChangeTitleBtn = () => {
24
+    if (this.state.editTitle) this.props.onValidateChangeTitle(this.state.editTitleValue)
25
+
26
+    this.setState(prevState => ({editTitle: !prevState.editTitle}))
27
+  }
16
 
28
 
17
   render () {
29
   render () {
18
-    const { customClass, icon, name, onChangeTitle, onClickCloseBtn } = this.props
30
+    const { customClass, faIcon, title, onClickCloseBtn } = this.props
19
 
31
 
20
     return (
32
     return (
21
       <div className={classnames('wsContentGeneric__header', `${customClass}__header`)}>
33
       <div className={classnames('wsContentGeneric__header', `${customClass}__header`)}>
22
         <div className={classnames('wsContentGeneric__header__icon', `${customClass}__header__icon`)}>
34
         <div className={classnames('wsContentGeneric__header__icon', `${customClass}__header__icon`)}>
23
-          <i className={`fa fa-${icon}`} />
35
+          <i className={`fa fa-${faIcon}`} />
24
         </div>
36
         </div>
25
 
37
 
26
         <div className={classnames('wsContentGeneric__header__title mr-auto', `${customClass}__header__title`)}>
38
         <div className={classnames('wsContentGeneric__header__title mr-auto', `${customClass}__header__title`)}>
27
-          {this.state.editTitle === false &&
28
-            <div>
29
-              {name}
30
-            </div>
31
-          }
32
-          {this.state.editTitle === true &&
33
-            <input onChange={onChangeTitle} />
39
+          {this.state.editTitle
40
+            ? <input value={this.state.editTitleValue} onChange={this.onChangeTitle} />
41
+            : <div>{title}</div>
34
           }
42
           }
35
         </div>
43
         </div>
36
 
44
 
38
           className={classnames('wsContentGeneric__header__edittitle', `${customClass}__header__changetitle`)}
46
           className={classnames('wsContentGeneric__header__edittitle', `${customClass}__header__changetitle`)}
39
           onClick={this.handleClickChangeTitleBtn}
47
           onClick={this.handleClickChangeTitleBtn}
40
         >
48
         >
41
-          <i className='fa fa-pencil' />
49
+          {this.state.editTitle ? <i className='fa fa-check' /> : <i className='fa fa-pencil' />}
42
         </div>
50
         </div>
43
 
51
 
44
         <div
52
         <div
55
 export default PopinFixedHeader
63
 export default PopinFixedHeader
56
 
64
 
57
 PopinFixedHeader.propTypes = {
65
 PopinFixedHeader.propTypes = {
58
-  icon: PropTypes.string.isRequired,
66
+  faIcon: PropTypes.string.isRequired,
59
   onClickCloseBtn: PropTypes.func.isRequired,
67
   onClickCloseBtn: PropTypes.func.isRequired,
60
   customClass: PropTypes.string,
68
   customClass: PropTypes.string,
61
-  name: PropTypes.string,
62
-  onChangeTitle: PropTypes.func
69
+  title: PropTypes.string,
70
+  onValidateChangeTitle: PropTypes.func
63
 }
71
 }
64
 
72
 
65
 PopinFixedHeader.defaultProps = {
73
 PopinFixedHeader.defaultProps = {
66
   customClass: '',
74
   customClass: '',
67
-  name: '',
75
+  title: '',
68
   onChangeTitle: () => {}
76
   onChangeTitle: () => {}
69
 }
77
 }

+ 45 - 31
src/component/Timeline/Timeline.jsx View File

4
 
4
 
5
 require('./Timeline.styl')
5
 require('./Timeline.styl')
6
 
6
 
7
-const Message = props => (
8
-  <li className={classnames(
9
-    `${props.customClass}__messagelist__item`,
10
-    'timeline__messagelist__item',
11
-    {
12
-      'sended': props.fromMe,
13
-      'received': !props.fromMe
14
-    }
15
-  )}>
7
+const Comment = props => (
8
+  <li
9
+    className={classnames(
10
+      `${props.customClass}__messagelist__item`,
11
+      'timeline__messagelist__item', {
12
+        'sended': props.fromMe,
13
+        'received': !props.fromMe
14
+      }
15
+    )}
16
+  >
16
     <div className={classnames(`${props.customClass}__messagelist__item__avatar`, 'timeline__messagelist__item__avatar')}>
17
     <div className={classnames(`${props.customClass}__messagelist__item__avatar`, 'timeline__messagelist__item__avatar')}>
17
-      <img src={props.avatar} alt='avatar' />
18
+      {props.avatar ? <img src={props.avatar} /> : ''}
18
     </div>
19
     </div>
19
     <div
20
     <div
20
       className={classnames(`${props.customClass}__messagelist__item__createhour`, 'timeline__messagelist__item__createhour')}>
21
       className={classnames(`${props.customClass}__messagelist__item__createhour`, 'timeline__messagelist__item__createhour')}>
21
-      {props.createdAt.day} à {props.createdAt.hour}
22
+      {props.createdAt}
22
     </div>
23
     </div>
23
     <div
24
     <div
24
       className={classnames(`${props.customClass}__messagelist__item__content`, 'timeline__messagelist__item__content')}>
25
       className={classnames(`${props.customClass}__messagelist__item__content`, 'timeline__messagelist__item__content')}>
27
   </li>
28
   </li>
28
 )
29
 )
29
 
30
 
30
-const Version = props => (
31
-  <li className={classnames(`${props.customClass}__messagelist__version`, 'timeline__messagelist__version')}>
31
+const Revision = props => (
32
+  <li className={classnames(`${props.customClass}__messagelist__version`, 'timeline__messagelist__version')} >
32
     <div className={classnames(`${props.customClass}__messagelist__version__btn`, 'timeline__messagelist__version__btn btn')}>
33
     <div className={classnames(`${props.customClass}__messagelist__version__btn`, 'timeline__messagelist__version__btn btn')}>
33
       <i className='fa fa-code-fork' />
34
       <i className='fa fa-code-fork' />
34
       version {props.number}
35
       version {props.number}
35
     </div>
36
     </div>
36
     <div className={classnames(`${props.customClass}__messagelist__version__date`, 'timeline__messagelist__version__date')}>
37
     <div className={classnames(`${props.customClass}__messagelist__version__date`, 'timeline__messagelist__version__date')}>
37
-      Créer le {props.createdAt.day}
38
+      Créer le {props.createdAt}
38
     </div>
39
     </div>
39
   </li>
40
   </li>
40
 )
41
 )
41
 
42
 
42
 const Timeline = props => {
43
 const Timeline = props => {
44
+  if (!Array.isArray(props.timelineData)) {
45
+    console.log('Error in Timeline.jsx, props.timelineData is not an array. timelineData: ', props.timelineData)
46
+    return null
47
+  }
48
+
43
   return (
49
   return (
44
     <div className='timeline'>
50
     <div className='timeline'>
45
       <div className={classnames(`${props.customClass}__header`, 'timeline__header')}>
51
       <div className={classnames(`${props.customClass}__header`, 'timeline__header')}>
48
 
54
 
49
       <ul className={classnames(`${props.customClass}__messagelist`, 'timeline__messagelist')}>
55
       <ul className={classnames(`${props.customClass}__messagelist`, 'timeline__messagelist')}>
50
         { props.timelineData.map(content => {
56
         { props.timelineData.map(content => {
51
-          switch (content.type) {
52
-            case 'message':
53
-              return <Message
57
+          switch (content.timelineType) {
58
+            case 'comment':
59
+              return <Comment
54
                 customClass={props.customClass}
60
                 customClass={props.customClass}
55
-                avatar={content.author.avatar}
56
-                createdAt={content.createdAt}
57
-                text={content.text}
58
-                fromMe={props.loggedUser.id === content.author.id}
59
-                key={content.id}
61
+                avatar={content.author.avatar_url}
62
+                createdAt={content.created}
63
+                text={content.raw_content}
64
+                fromMe={props.loggedUser.user_id === content.author.user_id}
65
+                key={`comment_${content.content_id}`}
60
               />
66
               />
61
 
67
 
62
-            case 'version':
63
-              return <Version
68
+            case 'revision':
69
+              return <Revision
64
                 customClass={props.customClass}
70
                 customClass={props.customClass}
65
-                createdAt={content.createdAt}
66
-                number={content.number}
67
-                key={content.id}
71
+                createdAt={content.created}
72
+                number={content.revision_id}
73
+                key={`revision_${content.revision_id}`}
68
               />
74
               />
69
           }
75
           }
70
         })}
76
         })}
73
       <form className={classnames(`${props.customClass}__texteditor`, 'timeline__texteditor d-flex align-items-center justify-content-between flex-wrap')}>
79
       <form className={classnames(`${props.customClass}__texteditor`, 'timeline__texteditor d-flex align-items-center justify-content-between flex-wrap')}>
74
 
80
 
75
         <div className={classnames(`${props.customClass}__texteditor__textinput`, 'timeline__texteditor__textinput')}>
81
         <div className={classnames(`${props.customClass}__texteditor__textinput`, 'timeline__texteditor__textinput')}>
76
-          <textarea placeholder='Taper votre message ici' />
82
+          <textarea
83
+            placeholder='Taper votre message ici'
84
+            value={props.newComment}
85
+            onChange={props.onChangeNewComment}
86
+          />
77
         </div>
87
         </div>
78
 
88
 
79
         <div className={classnames(`${props.customClass}__texteditor__wrapper`, 'timeline__texteditor__wrapper')}>
89
         <div className={classnames(`${props.customClass}__texteditor__wrapper`, 'timeline__texteditor__wrapper')}>
86
 
96
 
87
           <div className={classnames(`${props.customClass}__texteditor__submit`, 'timeline__texteditor__submit mb-2')}>
97
           <div className={classnames(`${props.customClass}__texteditor__submit`, 'timeline__texteditor__submit mb-2')}>
88
             <button
98
             <button
89
-              type='submit'
99
+              type='button'
90
               className={classnames(`${props.customClass}__texteditor__submit__btn`, 'timeline__texteditor__submit__btn btn')}
100
               className={classnames(`${props.customClass}__texteditor__submit__btn`, 'timeline__texteditor__submit__btn btn')}
101
+              onClick={props.onClickValidateNewCommentBtn}
91
             >
102
             >
92
               Envoyer
103
               Envoyer
93
               <div className={classnames(`${props.customClass}__texteditor__submit__btn__icon`, 'timeline__texteditor__submit__btn__icon')}>
104
               <div className={classnames(`${props.customClass}__texteditor__submit__btn__icon`, 'timeline__texteditor__submit__btn__icon')}>
105
 export default Timeline
116
 export default Timeline
106
 
117
 
107
 Timeline.propTypes = {
118
 Timeline.propTypes = {
119
+  timelineData: PropTypes.array.isRequired,
120
+  newComment: PropTypes.string.isRequired,
121
+  onChangeNewComment: PropTypes.func.isRequired,
122
+  onClickValidateNewCommentBtn: PropTypes.func.isRequired,
108
   customClass: PropTypes.string,
123
   customClass: PropTypes.string,
109
-  loggedUser: PropTypes.object,
110
-  timelineData: PropTypes.array
124
+  loggedUser: PropTypes.object
111
 }
125
 }
112
 
126
 
113
 Timeline.defaultProps = {
127
 Timeline.defaultProps = {

+ 6 - 2
src/helper.js View File

1
-export const libHandleFetchResult = fetchResult => {
1
+export const libHandleFetchResult = async fetchResult => {
2
   switch (fetchResult.status) {
2
   switch (fetchResult.status) {
3
     case 200:
3
     case 200:
4
     case 304:
4
     case 304:
5
-      return fetchResult.json()
5
+      const resultJson = await fetchResult.clone().json()
6
+      return new Promise((resolve, reject) => resolve({
7
+        apiResponse: fetchResult,
8
+        body: resultJson
9
+      }))
6
     case 204:
10
     case 204:
7
     case 400:
11
     case 400:
8
     case 404:
12
     case 404:

+ 2 - 11
src/index.dev.js View File

19
 
19
 
20
 ReactDOM.render(
20
 ReactDOM.render(
21
   <div>
21
   <div>
22
-    <PopinFixed customClass={`${'randomClass'}`} style={{display: 'none'}}>
22
+    <PopinFixed customClass={`${'randomClass'}`}>
23
       <PopinFixedHeader
23
       <PopinFixedHeader
24
         customClass={`${'randomClass'}`}
24
         customClass={`${'randomClass'}`}
25
         icon={'fa fa-file-word-o'}
25
         icon={'fa fa-file-word-o'}
34
           <Delimiter />
34
           <Delimiter />
35
           <span>Here will be the app content. Style is handled by the app (obviously)</span>
35
           <span>Here will be the app content. Style is handled by the app (obviously)</span>
36
           <BtnSwitch />
36
           <BtnSwitch />
37
-          <TextAreaApp customClass={'randomClass'} />
37
+          <TextAreaApp customClass={'randomClass'} text={'woot'} />
38
         </div>
38
         </div>
39
 
39
 
40
         <Timeline
40
         <Timeline
48
         />
48
         />
49
       </PopinFixedContent>
49
       </PopinFixedContent>
50
     </PopinFixed>
50
     </PopinFixed>
51
-
52
-    <CardPopupCreateContent
53
-      onClose={() => {}}
54
-      icon='fa-file-word-o'
55
-      color='#3f52e3'
56
-      title='Exemple of popup create content'
57
-      inputPlaceHolder='Exemple placeholder'
58
-      btnValidateLabel='Valider et créer'
59
-    />
60
   </div>
51
   </div>
61
   , document.getElementById('content')
52
   , document.getElementById('content')
62
 )
53
 )