@ -11,7 +11,8 @@ import {
Button
} from 'reactstrap' ;
import { ToastContainer } from 'react-toastify' ;
import { toast , ToastContainer } from 'react-toastify' ;
import 'react-toastify/dist/ReactToastify.css' ;
import HelpButton from "../form/HelpButton" ;
import { arrayMove , sortableContainer , sortableElement , sortableHandle } from 'react-sortable-hoc' ;
import ButtonWithConfirm from "../form/ButtonWithConfirm" ;
@ -21,6 +22,10 @@ import {faPlus, faTrashAlt, faCheck } from '@fortawesome/free-solid-svg-icons';
//TOOD : 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 = [ "Excellent" , "Trés Bien" , "Bien" , "Assez Bien" , "Passable" , "Insuffisant" , "A Rejeter" ] ;
const DragHandle = sortableHandle ( ( { children } ) => < span className = "input-group-text indexNumber" > { children } < / s p a n > ) ;
const SortableCandidate = sortableElement ( ( { candidate , sortIndex , form } ) => < li className = "sortable" >
@ -71,8 +76,11 @@ class CreateElection extends Component {
super ( props ) ;
this . state = {
candidates : [ { label : "" } , { label : "" } ] ,
nbCandidatesWithLabel : 0 ,
title : null ,
isVisibleTipsDragAndDropCandidate : true
isVisibleTipsDragAndDropCandidate : true ,
nbMentions : 7
} ;
this . candidateInputs = [ ] ;
@ -109,8 +117,14 @@ class CreateElection extends Component {
editCandidateLabel = ( event , index ) => {
let candidates = this . state . candidates ;
let nbLabels = 0 ;
candidates [ index ] . label = event . currentTarget . value ;
this . setState ( { candidates : candidates } ) ;
candidates . map ( ( candidate , i ) => {
if ( candidate . label !== "" ) {
nbLabels ++ ;
}
} ) ;
this . setState ( { candidates : candidates , nbCandidatesWithLabel : nbLabels } ) ;
} ;
@ -137,14 +151,23 @@ class CreateElection extends Component {
event . preventDefault ( ) ;
} ;
handleChangeNbMentions = ( event ) => {
this . setState ( { nbMentions : event . target . value } ) ;
} ;
componentWillMount ( ) {
const params = new URLSearchParams ( this . props . location . search ) ;
this . setState ( { title : params . get ( "title" ) ? params . get ( "title" ) : "" } ) ;
}
} ;
render ( ) {
handleSendWithoutCandidate = ( ) => {
toast . error ( "Vous devez saisir au moins deux candidats !" , {
position : toast . POSITION . TOP _CENTER
} ) ;
} ;
render ( ) {
const params = new URLSearchParams ( this . props . location . search ) ;
return (
< Container >
@ -187,35 +210,64 @@ class CreateElection extends Component {
< / C o l >
< Col xs = "auto" / >
< / R o w >
< Row className = "mt-4 mb-4" >
< Col xs = "12" >
< Label for = "title" > Nombre de mentions : < / L a b e l >
< / C o l >
< Col xs = "" md = "2" >
< select className = "form-control" tabIndex = { this . state . candidates . length + 3 } onChange = { this . handleChangeNbMentions } >
< option selected = { this . state . nbMentions === 5 } > 5 < / o p t i o n >
< option selected = { this . state . nbMentions === 6 } > 6 < / o p t i o n >
< option selected = { this . state . nbMentions === 7 } > 7 < / o p t i o n >
< / s e l e c t >
< / C o l >
< Col xs = "auto" className = "align-self-center pl-0" >
< HelpButton >
Vous pouvez choisir ici le nombre de mentions pour votre vote
< br / > < u > Par exemple : < / u > < e m > 5 = E x c e l l e n t , T r è s b i e n , b i e n , a s s e z b i e n , p a s s a b l e < / e m >
< / H e l p B u t t o n >
< / C o l >
< Col xs = "12" md = "" >
{ mentions . map ( ( mention , i ) => {
return < span className = "badge badge-light mr-2 mt-2" style = { { opacity : ( i < this . state . nbMentions ) ? 1 : 0.3 } } > { mention } < / s p a n >
} )
}
< / C o l >
< / R o w >
< hr / >
< Row className = "mt-4 justify-content-md-center" >
< Col xs = "12" md = "3" >
< ButtonWithConfirm className = "btn btn-success float-right btn-block " >
{ this . state . nbCandidatesWithLabel >= 2 ? < ButtonWithConfirm className = "btn btn-success float-right btn-block " tabIndex = { this . state . candidates . length + 4 } >
< div key = "button" > < FontAwesomeIcon icon = { faCheck } className = "mr-2" / > Valider < / d i v >
< div key = "modal-title" > Confirmation < / d i v >
< div key = "modal-title" > Confirm ez votre vote < / d i v >
< div key = "modal-body" >
< div > Voici votre vote : < / d i v >
< div className = "border border-primary p-2 mt-4 mb-4" >
< h4 className = "m-0" > { this . state . title } < / h 4 >
< ul className = "m-0" >
< div className = "mt-1 mb-1" >
< div className = "text-white bg-primary p-1" > Question du vote : < / d i v >
< div className = "p-1 pl-3" > < em > { this . state . title } < / e m > < / d i v >
< div className = "text-white bg-primary p-1" > Candidats / Propositions : < / d i v >
< div className = "p-1 pl-0" > < ul className = "m-0 pl-4" >
{
this . state . candidates . map ( ( candidate , i ) => {
if ( candidate . label !== "" ) {
return < li key = { i } > { candidate . label } < / l i >
return < li key = { i } className = "m-0" > { candidate . label } < / l i >
} else {
return < li key = { i } className = "d-none" / >
}
} )
}
< / u l >
< / u l > < / d i v >
< div className = "text-white bg-primary p-1" > Mentions : < / d i v >
< div className = "p-1 pl-3" > { mentions . map ( ( mention , i ) => {
return ( i < this . state . nbMentions ) ? < span className = "badge badge-light mr-2 mt-2" > { mention } < /span>:<span/ >
} )
} < / d i v >
< / d i v >
< p > Une fois validé , vous ne pourrez plus le modifier , souhaitez - vous continuer ? < / p >
< / d i v >
< div key = "modal-confirm" onClick = { ( ) => { } } > Oui < / d i v >
< div key = "modal-cancel" > Non < / d i v >
< / B u t t o n W i t h C o n f i r m >
< div key = "modal-confirm" onClick = { ( ) => { } } > 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 >
< / R o w >
< / f o r m >