OSDN Git Service

fixes https://github.com/Bytom/bytom/issues/917
authorZhiting Lin <zlin035@uottawa.ca>
Tue, 9 Oct 2018 02:40:59 +0000 (10:40 +0800)
committerZhiting Lin <zlin035@uottawa.ca>
Tue, 9 Oct 2018 02:40:59 +0000 (10:40 +0800)
src/features/accessControl/actions.js
src/features/accessControl/components/NewToken.jsx

index 1af66ca..1f09fe5 100644 (file)
@@ -60,12 +60,16 @@ export default {
       return chainClient().accessTokens.create({
         id: body.guardData.id,
       }).then(tokenResp =>{
-        dispatch({ type: 'CREATED_TOKEN_WITH_GRANT', tokenResp })
-        dispatch(push({
-          pathname: '/access-control',
-          search: '?type=token',
-          state: {preserveFlash: true},
-        }))
+        if(tokenResp.status === 'success'){
+          dispatch({ type: 'CREATED_TOKEN_WITH_GRANT', tokenResp })
+          dispatch(push({
+            pathname: '/access-control',
+            search: '?type=token',
+            state: {preserveFlash: true},
+          }))
+        }else{
+          throw new Error(tokenResp.errorDetail)
+        }
       }
       ).catch(err => { throw {_error: err} })
     }
index 873ef76..9296398 100644 (file)
@@ -5,9 +5,22 @@ import { reduxForm } from 'redux-form'
 import actions from 'features/accessControl/actions'
 
 class NewToken extends React.Component {
+  constructor(props) {
+    super(props)
+    this.submitWithErrors = this.submitWithErrors.bind(this)
+  }
+
+  submitWithErrors(data) {
+    return new Promise((resolve, reject) => {
+      this.props.submitForm(data)
+        .catch((err) => reject(err))
+    })
+  }
+
+
   render() {
     const {
-      fields: { guardData, policies },
+      fields: { guardData },
       error,
       handleSubmit,
       submitting
@@ -18,24 +31,13 @@ class NewToken extends React.Component {
       <FormContainer
         error={error}
         label={ lang === 'zh' ? '新建访问令牌' : 'New access token' }
-        onSubmit={handleSubmit(this.props.submitForm)}
+        onSubmit={handleSubmit(this.submitWithErrors)}
         submitting={submitting}
         lang={lang}>
 
         <FormSection title={ lang === 'zh' ? '令牌信息' : 'Token information' }>
           <TextField title={ lang === 'zh' ? '令牌名称' : 'Token Name'} fieldProps={guardData.id} autoFocus={true} />
         </FormSection>
-        {/*<FormSection title='Policy'>*/}
-          {/*{policyOptions.map(option => {*/}
-            {/*if (option.hidden) return*/}
-
-            {/*return <CheckboxField key={option.label}*/}
-              {/*title={option.label}*/}
-              {/*hint={option.hint}*/}
-              {/*fieldProps={policies[option.value]} />*/}
-          {/*})}*/}
-        {/*</FormSection>*/}
-
       </FormContainer>
     )
   }