Browse Source

fix for frontend to work with api that now handles lang

Skylsmoi 5 years ago
parent
commit
82b7d93557

+ 23 - 1
frontend/src/action-creator.async.js View File

7
   USER_NAME,
7
   USER_NAME,
8
   USER_EMAIL,
8
   USER_EMAIL,
9
   USER_PASSWORD,
9
   USER_PASSWORD,
10
+  USER_LANG,
10
   WORKSPACE,
11
   WORKSPACE,
11
   WORKSPACE_LIST,
12
   WORKSPACE_LIST,
12
   WORKSPACE_DETAIL,
13
   WORKSPACE_DETAIL,
153
       method: 'PUT',
154
       method: 'PUT',
154
       body: JSON.stringify({
155
       body: JSON.stringify({
155
         public_name: newName,
156
         public_name: newName,
156
-        timezone: user.timezone
157
+        timezone: user.timezone,
158
+        lang: user.lang
157
       })
159
       })
158
     },
160
     },
159
     actionName: USER_NAME,
161
     actionName: USER_NAME,
200
   })
202
   })
201
 }
203
 }
202
 
204
 
205
+export const putUserLang = (user, newLang) => dispatch => {
206
+  return fetchWrapper({
207
+    url: `${FETCH_CONFIG.apiUrl}/users/${user.user_id}`,
208
+    param: {
209
+      headers: {
210
+        ...FETCH_CONFIG.headers,
211
+        'Authorization': 'Basic ' + user.auth
212
+      },
213
+      method: 'PUT',
214
+      body: JSON.stringify({
215
+        public_name: user.public_name,
216
+        timezone: user.timezone,
217
+        lang: newLang
218
+      })
219
+    },
220
+    actionName: USER_LANG,
221
+    dispatch
222
+  })
223
+}
224
+
203
 export const putUserWorkspaceRead = (user, idWorkspace) => dispatch => {
225
 export const putUserWorkspaceRead = (user, idWorkspace) => dispatch => {
204
   return fetchWrapper({
226
   return fetchWrapper({
205
     url: `${FETCH_CONFIG.apiUrl}/users/${user.user_id}/workspaces/${idWorkspace}/read`,
227
     url: `${FETCH_CONFIG.apiUrl}/users/${user.user_id}/workspaces/${idWorkspace}/read`,

+ 1 - 1
frontend/src/component/Workspace/ContentItem.jsx View File

29
       }
29
       }
30
 
30
 
31
       <div className={classnames('content__status')} style={{color: status.hexcolor}}>
31
       <div className={classnames('content__status')} style={{color: status.hexcolor}}>
32
-        <div className='content__status__text d-none d-xl-flex align-items-center justify-content-between'>
32
+        <div className='content__status__text d-none d-xl-flex align-items-center justify-content-center'>
33
           {status.label}
33
           {status.label}
34
           <i className={`fa fa-fw fa-${status.faIcon}`} />
34
           <i className={`fa fa-fw fa-${status.faIcon}`} />
35
         </div>
35
         </div>

+ 16 - 6
frontend/src/container/Header.jsx View File

21
   setUserDisconnected
21
   setUserDisconnected
22
 } from '../action-creator.sync.js'
22
 } from '../action-creator.sync.js'
23
 import {
23
 import {
24
-  postUserLogout
24
+  postUserLogout,
25
+  putUserLang
25
 } from '../action-creator.async.js'
26
 } from '../action-creator.async.js'
26
 import { COOKIE, PAGE, PROFILE } from '../helper.js'
27
 import { COOKIE, PAGE, PROFILE } from '../helper.js'
27
 
28
 
35
   handleChangeInput = e => this.setState({inputSearchValue: e.target.value})
36
   handleChangeInput = e => this.setState({inputSearchValue: e.target.value})
36
   handleClickSubmit = () => {}
37
   handleClickSubmit = () => {}
37
 
38
 
38
-  handleChangeLang = idLang => {
39
-    this.props.dispatch(setUserLang(idLang))
40
-    i18n.changeLanguage(idLang)
41
-    this.props.dispatchCustomEvent('allApp_changeLang', idLang)
39
+  handleChangeLang = async idLang => {
40
+    const { props } = this
41
+
42
+    const fetchPutUserLang = await props.dispatch(putUserLang(props.user, idLang))
43
+    switch (fetchPutUserLang.status) {
44
+      case 200:
45
+        props.dispatch(setUserLang(idLang))
46
+        i18n.changeLanguage(idLang)
47
+        props.dispatchCustomEvent('allApp_changeLang', idLang)
48
+        break
49
+      default: props.dispatch(newFlashMessage(props.t('Error while saving new lang'))); break
50
+    }
51
+
42
   }
52
   }
43
 
53
 
44
   handleClickHelp = () => {}
54
   handleClickHelp = () => {}
93
 
103
 
94
               <MenuActionListItemDropdownLang
104
               <MenuActionListItemDropdownLang
95
                 langList={lang}
105
                 langList={lang}
96
-                idLangActive={user.lang}
106
+                idLangActive={user.lang ? user.lang : 'en'}
97
                 onChangeLang={this.handleChangeLang}
107
                 onChangeLang={this.handleChangeLang}
98
               />
108
               />
99
 
109
 

+ 4 - 4
frontend/src/container/Sidebar.jsx View File

25
   }
25
   }
26
 
26
 
27
   customEventReducer = async ({ detail: { type, data } }) => {
27
   customEventReducer = async ({ detail: { type, data } }) => {
28
-    switch (type) {
29
-      default:
30
-        return
31
-    }
28
+    // switch (type) {
29
+    //   default:
30
+    //     return
31
+    // }
32
   }
32
   }
33
 
33
 
34
   componentDidUpdate (prevProps, prevState) {
34
   componentDidUpdate (prevProps, prevState) {

+ 2 - 1
frontend/src/reducer/user.js View File

24
   avatar_url: null,
24
   avatar_url: null,
25
   created: '',
25
   created: '',
26
   public_name: '',
26
   public_name: '',
27
-  lang: 'en' // @FIXME Côme - 2018/07/30 - remove this line when api returns the lang (https://github.com/tracim/tracim/issues/734)
27
+  lang: ''
28
 }
28
 }
29
 
29
 
30
 export default function user (state = defaultUser, action) {
30
 export default function user (state = defaultUser, action) {
33
       return {
33
       return {
34
         ...state,
34
         ...state,
35
         ...action.user,
35
         ...action.user,
36
+        lang: action.user.lang ? action.user.lang : 'en',
36
         avatar_url: action.user.avatar_url
37
         avatar_url: action.user.avatar_url
37
           ? action.user.avatar_url
38
           ? action.user.avatar_url
38
           : action.user.public_name ? generateAvatarFromPublicName(action.user.public_name) : ''
39
           : action.user.public_name ? generateAvatarFromPublicName(action.user.public_name) : ''