1
1
import React , { Component } from 'react' ;
2
+ import { toastr } from 'react-redux-toastr' ;
2
3
import { connect } from 'react-redux' ;
3
4
import { withStyles } from '@material-ui/core' ;
4
5
import { withTranslation } from 'react-i18next' ;
@@ -13,6 +14,7 @@ import StudentForm from './StudentForm';
13
14
import LoadSpaceSelectors from '../space/load/LoadSpaceSelectors' ;
14
15
import { isSpaceDifferent as isSpaceDifferentFunc } from '../../utils/syncSpace' ;
15
16
import { IMPORT_DATA_CLASSROOM_VALIDATE_BUTTON_ID } from '../../config/selectors' ;
17
+ import { ERROR_MESSAGE_HEADER } from '../../config/messages' ;
16
18
17
19
const styles = theme => ( {
18
20
...Styles ( theme ) ,
@@ -109,11 +111,12 @@ class ImportDataAssignUserForm extends Component {
109
111
const { space, actions, appInstanceResources } = this . state ;
110
112
const selection = [ space , actions , appInstanceResources ] ;
111
113
112
- // disable submit if no username is specified and if nothing is checked
114
+ // disable submit if (no username is specified and there are resources/actions) and if nothing is checked
115
+ const importResourcesOrActions = actions || appInstanceResources ;
113
116
disabled =
114
117
! selection . includes ( true ) ||
115
- ! usernameOption ||
116
- ! usernameOption . value . length ;
118
+ ( importResourcesOrActions &&
119
+ ( ! usernameOption || ! usernameOption . value . length ) ) ;
117
120
}
118
121
119
122
return (
@@ -137,24 +140,29 @@ class ImportDataAssignUserForm extends Component {
137
140
classroom,
138
141
dispatchLoadSpaceInClassroom,
139
142
} = this . props ;
140
- const {
141
- space,
142
- appInstanceResources,
143
- actions,
144
- usernameOption : { value : username } ,
145
- } = this . state ;
143
+ const { space, appInstanceResources, actions, usernameOption } = this . state ;
146
144
147
- dispatchLoadSpaceInClassroom ( {
148
- extractPath,
149
- classroomId : classroom . get ( 'id' ) ,
150
- elements : elements . toJS ( ) ,
151
- username,
152
- selection : {
153
- space,
154
- appInstanceResources,
155
- actions,
156
- } ,
157
- } ) ;
145
+ let username = null ;
146
+ if ( usernameOption ) {
147
+ ( { value : username } = usernameOption ) ;
148
+ }
149
+
150
+ // username cannot be null if actions or resources are imported
151
+ if ( ! username && ( appInstanceResources || actions ) ) {
152
+ toastr . error ( ERROR_MESSAGE_HEADER , 'A user need to be specified' ) ;
153
+ } else {
154
+ dispatchLoadSpaceInClassroom ( {
155
+ extractPath,
156
+ classroomId : classroom . get ( 'id' ) ,
157
+ elements : elements . toJS ( ) ,
158
+ username,
159
+ selection : {
160
+ space,
161
+ appInstanceResources,
162
+ actions,
163
+ } ,
164
+ } ) ;
165
+ }
158
166
} ;
159
167
160
168
renderBackButton = ( ) => {
0 commit comments