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} })
}
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
<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>
)
}