Skip to content

Commit f063418

Browse files
author
Bogdans Afonins
committed
console: Fix app collaborators error handling
1 parent 0b1d814 commit f063418

File tree

2 files changed

+10
-41
lines changed
  • pkg/webui/console/views

2 files changed

+10
-41
lines changed

pkg/webui/console/views/application-collaborator-add/index.js

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ import bind from 'autobind-decorator'
1818
import { connect } from 'react-redux'
1919
import { push } from 'connected-react-router'
2020

21-
import Spinner from '../../../components/spinner'
2221
import Breadcrumb from '../../../components/breadcrumbs/breadcrumb'
2322
import { withBreadcrumb } from '../../../components/breadcrumbs/context'
2423
import sharedMessages from '../../../lib/shared-messages'
2524
import CollaboratorForm from '../../components/collaborator-form'
2625
import Message from '../../../lib/components/message'
2726
import IntlHelmet from '../../../lib/components/intl-helmet'
27+
import withRequest from '../../../lib/components/with-request'
2828

2929
import { getApplicationsRightsList } from '../../store/actions/applications'
3030
import {
@@ -54,6 +54,10 @@ import api from '../../api'
5454
redirectToList: () => dispatchProps.redirectToList(stateProps.appId),
5555
getApplicationsRightsList: () => dispatchProps.getApplicationsRightsList(stateProps.appId),
5656
}))
57+
@withRequest(
58+
({ getApplicationsRightsList }) => getApplicationsRightsList(),
59+
({ fetching, rights }) => fetching || !Boolean(rights.length)
60+
)
5761
@withBreadcrumb('apps.single.collaborators.add', function (props) {
5862
const appId = props.appId
5963
return (
@@ -71,39 +75,19 @@ export default class ApplicationCollaboratorAdd extends React.Component {
7175
error: '',
7276
}
7377

74-
componentDidMount () {
75-
const { getApplicationsRightsList } = this.props
76-
77-
getApplicationsRightsList()
78-
}
79-
80-
componentDidUpdate (prevProps) {
81-
const { error } = this.props
82-
83-
if (Boolean(error) && prevProps.error !== error) {
84-
throw error
85-
}
86-
}
87-
8878
async handleSubmit (collaborator) {
8979
const { appId } = this.props
9080

9181
await api.application.collaborators.add(appId, collaborator)
92-
9382
}
9483

9584
render () {
9685
const {
9786
rights,
98-
fetching,
9987
universalRights,
10088
redirectToList,
10189
} = this.props
10290

103-
if (fetching && !rights.length) {
104-
return <Spinner center />
105-
}
106-
10791
return (
10892
<Container>
10993
<Row>

pkg/webui/console/views/application-collaborator-edit/index.js

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ import { withBreadcrumb } from '../../../components/breadcrumbs/context'
2222
import Breadcrumb from '../../../components/breadcrumbs/breadcrumb'
2323
import sharedMessages from '../../../lib/shared-messages'
2424
import CollaboratorForm from '../../components/collaborator-form'
25-
import Spinner from '../../../components/spinner'
2625
import Message from '../../../lib/components/message'
2726
import IntlHelmet from '../../../lib/components/intl-helmet'
2827
import toast from '../../../components/toast'
28+
import withRequest from '../../../lib/components/with-request'
2929

3030
import {
3131
getApplicationCollaborator,
@@ -84,6 +84,10 @@ import api from '../../api'
8484
redirectToList: () => dispatchProps.redirectToList(stateProps.appId),
8585
})
8686
)
87+
@withRequest(
88+
({ loadData }) => loadData(),
89+
({ fetching, collaborator }) => fetching || !Boolean(collaborator)
90+
)
8791
@withBreadcrumb('apps.single.collaborators.edit', function (props) {
8892
const { appId, collaboratorId, collaboratorType } = props
8993

@@ -102,20 +106,6 @@ export default class ApplicationCollaboratorEdit extends React.Component {
102106
error: '',
103107
}
104108

105-
componentDidMount () {
106-
const { loadData } = this.props
107-
108-
loadData()
109-
}
110-
111-
componentDidUpdate (prevProps) {
112-
const { error } = this.props
113-
114-
if (Boolean(error) && prevProps.error !== error) {
115-
throw error
116-
}
117-
}
118-
119109
async handleSubmit (updatedCollaborator) {
120110
const { appId } = this.props
121111

@@ -158,15 +148,10 @@ export default class ApplicationCollaboratorEdit extends React.Component {
158148
const {
159149
collaborator,
160150
rights,
161-
fetching,
162151
universalRights,
163152
redirectToList,
164153
} = this.props
165154

166-
if (fetching || !collaborator) {
167-
return <Spinner center />
168-
}
169-
170155
return (
171156
<Container>
172157
<Row>

0 commit comments

Comments
 (0)