@@ -18,13 +18,13 @@ import bind from 'autobind-decorator'
18
18
import { connect } from 'react-redux'
19
19
import { replace } from 'connected-react-router'
20
20
21
- import Spinner from '../../../components/spinner'
22
21
import Breadcrumb from '../../../components/breadcrumbs/breadcrumb'
23
22
import { withBreadcrumb } from '../../../components/breadcrumbs/context'
24
23
import sharedMessages from '../../../lib/shared-messages'
25
24
import Message from '../../../lib/components/message'
26
25
import IntlHelmet from '../../../lib/components/intl-helmet'
27
26
import { ApiKeyCreateForm } from '../../components/api-key-form'
27
+ import withRequest from '../../../lib/components/with-request'
28
28
29
29
import { getGatewaysRightsList } from '../../store/actions/gateways'
30
30
import {
@@ -43,7 +43,15 @@ import api from '../../api'
43
43
error : selectGatewayRightsError ( state ) ,
44
44
rights : selectGatewayRights ( state ) ,
45
45
universalRights : selectGatewayUniversalRights ( state ) ,
46
+ } ) ,
47
+ dispatch => ( {
48
+ getGatewaysRightsList : gtwId => dispatch ( getGatewaysRightsList ( gtwId ) ) ,
49
+ navigateToList : gtwId => dispatch ( replace ( `/console/gateways/${ gtwId } /api-keys` ) ) ,
46
50
} ) )
51
+ @withRequest (
52
+ ( { gtwId, getGatewaysRightsList } ) => getGatewaysRightsList ( gtwId ) ,
53
+ ( { fetching, rights } ) => fetching || ! Boolean ( rights . length )
54
+ )
47
55
@withBreadcrumb ( 'gtws.single.api-keys.add' , function ( props ) {
48
56
const gtwId = props . gtwId
49
57
@@ -64,28 +72,14 @@ export default class GatewayApiKeyAdd extends React.Component {
64
72
this . createGatewayKey = key => api . gateway . apiKeys . create ( props . gtwId , key )
65
73
}
66
74
67
- componentDidMount ( ) {
68
- const { dispatch, gtwId } = this . props
69
-
70
- dispatch ( getGatewaysRightsList ( gtwId ) )
71
- }
72
-
73
75
handleApprove ( ) {
74
- const { dispatch , gtwId } = this . props
76
+ const { navigateToList , gtwId } = this . props
75
77
76
- dispatch ( replace ( `/console/gateways/ ${ gtwId } /api-keys` ) )
78
+ navigateToList ( gtwId )
77
79
}
78
80
79
81
render ( ) {
80
- const { rights, fetching, error, universalRights } = this . props
81
-
82
- if ( error ) {
83
- throw error
84
- }
85
-
86
- if ( fetching || ! rights . length ) {
87
- return < Spinner center />
88
- }
82
+ const { rights, universalRights } = this . props
89
83
90
84
return (
91
85
< Container >
0 commit comments