@@ -4,8 +4,10 @@ import { connect } from "react-redux"
44import { Preloader } from "react-materialize"
55import { ConfirmationModal , Card } from "../ui"
66import * as actions from "../../actions/respondentGroups"
7+ import * as surveysActions from "../../actions/surveys"
78import uniq from "lodash/uniq"
89import flatten from "lodash/flatten"
10+ import ImportSampleModal from "./ImportSampleModal"
911import { RespondentsList } from "./RespondentsList"
1012import { RespondentsDropzone } from "./RespondentsDropzone"
1113import { RespondentsContainer } from "./RespondentsContainer"
@@ -16,8 +18,10 @@ class SurveyWizardRespondentsStep extends Component {
1618 static propTypes = {
1719 t : PropTypes . func ,
1820 survey : PropTypes . object ,
21+ projectSurveys : PropTypes . object ,
1922 respondentGroups : PropTypes . object . isRequired ,
2023 respondentGroupsUploading : PropTypes . bool ,
24+ respondentGroupsImporting : PropTypes . bool ,
2125 respondentGroupsUploadingExisting : PropTypes . object ,
2226 invalidRespondents : PropTypes . object ,
2327 invalidGroup : PropTypes . bool ,
@@ -32,9 +36,16 @@ class SurveyWizardRespondentsStep extends Component {
3236 if ( files . length > 0 ) actions . uploadRespondentGroup ( survey . projectId , survey . id , files )
3337 }
3438
35- importUnusedSample ( ) {
39+ showImportUnusedSampleModal ( e ) {
40+ e . preventDefault ( )
41+ let { projectId, surveysActions} = this . props
42+ surveysActions . fetchSurveys ( projectId )
43+ $ ( '#importUnusedSampleModal' ) . modal ( "open" )
44+ }
45+
46+ importUnusedSample ( sourceSurveyId ) {
3647 const { survey, actions } = this . props
37- actions . importUnusedSampleFromSurvey ( survey . projectId , survey . id , 1 ) // FIXME: actually pick the source survey ID
48+ actions . importUnusedSampleFromSurvey ( survey . projectId , survey . id , sourceSurveyId )
3849 }
3950
4051 addMoreRespondents ( groupId , file ) {
@@ -329,9 +340,11 @@ class SurveyWizardRespondentsStep extends Component {
329340 render ( ) {
330341 let {
331342 survey,
343+ projectSurveys,
332344 channels,
333345 respondentGroups,
334346 respondentGroupsUploading,
347+ respondentGroupsImporting,
335348 respondentGroupsUploadingExisting,
336349 invalidRespondents,
337350 readOnly,
@@ -348,18 +361,25 @@ class SurveyWizardRespondentsStep extends Component {
348361
349362 let importUnusedSampleButton = < div className = "row" >
350363 < div className = "col s12" >
351- < a key = "y" href = "#" onClick = { ( ) => this . importUnusedSample ( ) } className = "btn-flat btn-flat-link" >
352- { t ( "Import uncontacted respondents from other survey " ) }
364+ < a key = "y" href = "#" onClick = { this . showImportUnusedSampleModal . bind ( this ) } className = "btn-flat btn-flat-link" >
365+ { t ( "Import unused respondents" ) }
353366 </ a >
354367 </ div >
355368 </ div >
356369
370+ let importUnusedSampleModal = < ImportSampleModal
371+ projectSurveys = { projectSurveys }
372+ onConfirm = { this . importUnusedSample . bind ( this ) }
373+ modalId = "importUnusedSampleModal"
374+ />
375+
357376 let respondentsDropzone = null
358377 if ( ! readOnly && ! surveyStarted ) {
359378 respondentsDropzone = (
360379 < RespondentsDropzone
361380 survey = { survey }
362381 uploading = { respondentGroupsUploading }
382+ importing = { respondentGroupsImporting }
363383 onDrop = { ( file ) => this . handleSubmit ( file ) }
364384 onDropRejected = { ( ) => $ ( "#invalidTypeFile" ) . modal ( "open" ) }
365385 />
@@ -400,13 +420,15 @@ class SurveyWizardRespondentsStep extends Component {
400420 />
401421 { invalidRespondentsCard || respondentsDropzone }
402422 { importUnusedSampleButton }
423+ { importUnusedSampleModal }
403424 </ RespondentsContainer >
404425 )
405426 }
406427}
407428
408429const mapDispatchToProps = ( dispatch ) => ( {
409430 actions : bindActionCreators ( actions , dispatch ) ,
431+ surveysActions : bindActionCreators ( surveysActions , dispatch )
410432} )
411433
412434export default translate ( ) ( connect ( null , mapDispatchToProps ) ( SurveyWizardRespondentsStep ) )
0 commit comments