@ -21,7 +21,6 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faPlus , faTrashAlt , faCheck } from '@fortawesome/free-solid-svg-icons' ;
//TODO : variable de config dans un fichier à part (avec les mentions, le min/max de mentions, le nombre max de candidats, les maxlength,l'url api, etc ...)
const mentions = [
{ label : "Excellent" , color : "#015411" } ,
@ -33,6 +32,8 @@ const mentions = [
{ label : "A Rejeter" , color : "#6f0214" } ,
] ;
const PATH _API = '/api/' ;
const PATH _CREATE _ELECTION = 'create' ;
const DragHandle = sortableHandle ( ( { children } ) => < span className = "input-group-text indexNumber" > { children } < / s p a n > ) ;
@ -88,11 +89,10 @@ class CreateElection extends Component {
title : null ,
isVisibleTipsDragAndDropCandidate : true ,
nbMentions : 7
} ;
this . candidateInputs = [ ] ;
this . focusInput = React . createRef ( ) ;
this . handleSubmit = this . handleSubmit . bind ( this ) ;
}
@ -156,10 +156,6 @@ class CreateElection extends Component {
this . setState ( { candidates : candidates } ) ;
} ;
handleSubmit = ( event ) => {
event . preventDefault ( ) ;
} ;
handleChangeNbMentions = ( event ) => {
this . setState ( { nbMentions : event . target . value } ) ;
} ;
@ -170,6 +166,32 @@ class CreateElection extends Component {
} ;
handleSubmit ( ) {
const {
candidates ,
nbCandidatesWithLabel ,
title ,
isVisibleTipsDragAndDropCandidate ,
nbMentions
} = this . state ;
fetch ( ` ${ PATH _API } ${ PATH _CREATE _ELECTION } ` , {
method : 'POST' ,
headers : {
'Content-Type' : 'application/json'
} ,
body : JSON . stringify ( {
title : title ,
candidates : candidates ,
on _invitation _only : false ,
num _grades : nbMentions ,
elector _emails : [ ]
} )
}
) . then ( response => response . json ( ) )
. then ( result => alert ( result ) )
. catch ( error => error ) ;
} ;
handleSendWithoutCandidate = ( ) => {
toast . error ( "Vous devez saisir au moins deux candidats !" , {
position : toast . POSITION . TOP _CENTER
@ -274,7 +296,7 @@ class CreateElection extends Component {
} < / d i v >
< / d i v >
< / d i v >
< div key = "modal-confirm" onClick = { ( ) => { } } > Lancer le vote < / d i v >
< div key = "modal-confirm" onClick = { this . handleSubmit } > Lancer le vote < / d i v >
< div key = "modal-cancel" > Annuler < / d i v >
< /ButtonWithConfirm>:<Button type="button" className="btn btn-dark float-right btn-block" onClick={this.handleSendWithoutCandidate}><FontAwesomeIcon icon={faCheck} className="mr-2" / > Valider < / B u t t o n > }
< / C o l >