Quellcode durchsuchen

fix for frontend to work with api that now handles lang

Skylsmoi vor 6 Jahren
Ursprung
Commit
82b7d93557

+ 23 - 1
frontend/src/action-creator.async.js Datei anzeigen

@@ -7,6 +7,7 @@ import {
7 7
   USER_NAME,
8 8
   USER_EMAIL,
9 9
   USER_PASSWORD,
10
+  USER_LANG,
10 11
   WORKSPACE,
11 12
   WORKSPACE_LIST,
12 13
   WORKSPACE_DETAIL,
@@ -153,7 +154,8 @@ export const putUserName = (user, newName) => dispatch => {
153 154
       method: 'PUT',
154 155
       body: JSON.stringify({
155 156
         public_name: newName,
156
-        timezone: user.timezone
157
+        timezone: user.timezone,
158
+        lang: user.lang
157 159
       })
158 160
     },
159 161
     actionName: USER_NAME,
@@ -200,6 +202,26 @@ export const putUserPassword = (user, oldPassword, newPassword, newPassword2) =>
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 225
 export const putUserWorkspaceRead = (user, idWorkspace) => dispatch => {
204 226
   return fetchWrapper({
205 227
     url: `${FETCH_CONFIG.apiUrl}/users/${user.user_id}/workspaces/${idWorkspace}/read`,

+ 1 - 1
frontend/src/component/Workspace/ContentItem.jsx Datei anzeigen

@@ -29,7 +29,7 @@ const ContentItem = props => {
29 29
       }
30 30
 
31 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 33
           {status.label}
34 34
           <i className={`fa fa-fw fa-${status.faIcon}`} />
35 35
         </div>

+ 16 - 6
frontend/src/container/Header.jsx Datei anzeigen

@@ -21,7 +21,8 @@ import {
21 21
   setUserDisconnected
22 22
 } from '../action-creator.sync.js'
23 23
 import {
24
-  postUserLogout
24
+  postUserLogout,
25
+  putUserLang
25 26
 } from '../action-creator.async.js'
26 27
 import { COOKIE, PAGE, PROFILE } from '../helper.js'
27 28
 
@@ -35,10 +36,19 @@ class Header extends React.Component {
35 36
   handleChangeInput = e => this.setState({inputSearchValue: e.target.value})
36 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 54
   handleClickHelp = () => {}
@@ -93,7 +103,7 @@ class Header extends React.Component {
93 103
 
94 104
               <MenuActionListItemDropdownLang
95 105
                 langList={lang}
96
-                idLangActive={user.lang}
106
+                idLangActive={user.lang ? user.lang : 'en'}
97 107
                 onChangeLang={this.handleChangeLang}
98 108
               />
99 109
 

+ 4 - 4
frontend/src/container/Sidebar.jsx Datei anzeigen

@@ -25,10 +25,10 @@ class Sidebar extends React.Component {
25 25
   }
26 26
 
27 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 34
   componentDidUpdate (prevProps, prevState) {

+ 2 - 1
frontend/src/reducer/user.js Datei anzeigen

@@ -24,7 +24,7 @@ const defaultUser = {
24 24
   avatar_url: null,
25 25
   created: '',
26 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 30
 export default function user (state = defaultUser, action) {
@@ -33,6 +33,7 @@ export default function user (state = defaultUser, action) {
33 33
       return {
34 34
         ...state,
35 35
         ...action.user,
36
+        lang: action.user.lang ? action.user.lang : 'en',
36 37
         avatar_url: action.user.avatar_url
37 38
           ? action.user.avatar_url
38 39
           : action.user.public_name ? generateAvatarFromPublicName(action.user.public_name) : ''