diff --git a/package.json b/package.json
index 664a824..4ee7fe4 100644
--- a/package.json
+++ b/package.json
@@ -56,6 +56,7 @@
"react-app-polyfill": "^1.0.1",
"react-dev-utils": "^9.0.1",
"react-dom": "^16.8.6",
+ "react-multi-email": "^0.5.3",
"react-router-dom": "^5.0.0",
"react-sortable-hoc": "^1.9.1",
"react-toastify": "^5.2.1",
diff --git a/src/components/views/CreateElection.jsx b/src/components/views/CreateElection.jsx
index c5023e0..491e4db 100644
--- a/src/components/views/CreateElection.jsx
+++ b/src/components/views/CreateElection.jsx
@@ -23,6 +23,8 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import {faPlus, faTrashAlt, faCheck, faCogs } from '@fortawesome/free-solid-svg-icons';
import { grades } from '../../Util';
+import { ReactMultiEmail, isEmail } from 'react-multi-email';
+import 'react-multi-email/style.css';
const DragHandle = sortableHandle(({children}) => {children});
@@ -73,6 +75,12 @@ class CreateElection extends Component {
constructor(props) {
super(props);
+ //default value : start now
+ const startedAt = new Date();
+ const startedHour= startedAt.getHours();
+ //default value : finish in one week
+ const finishedAt = new Date(startedAt.getTime() + 7 * 24 * 60 * 60 * 1000);
+
this.state = {
candidates:[{label:""},{label:""}],
numCandidatesWithLabel:0,
@@ -81,7 +89,12 @@ class CreateElection extends Component {
numGrades:7,
successCreate: false,
redirectTo: null,
- isAdvancedOptionsOpen:false
+ isAdvancedOptionsOpen:false,
+ startedDayAt:startedAt.toISOString().substring(0, 10),
+ finishedDayAt:finishedAt.toISOString().substring(0, 10),
+ startedTimeAt:(Math.floor(startedHour/2)*2)+":00:00",
+ finishedTimeAt:"23:59:59",
+ electorEmails:[]
};
this.candidateInputs = [];
this.focusInput= React.createRef();
@@ -183,9 +196,12 @@ class CreateElection extends Component {
body: JSON.stringify({
title: title,
candidates: candidates.map(c => c.label),
- on_invitation_only: false,
+ on_invitation_only: (this.state.electorEmails.length>0),
num_grades: numGrades,
- elector_emails: []
+ elector_emails: this.state.electorEmails,
+ started_at:this.state.startedDayAt+" "+this.state.startedTimeAt,
+ finished_at:this.state.finishedDayAt+" "+this.state.finishedTimeAt,
+ time_offset:new Date().getTimezoneOffset()
})
})
.then(response => response.json())
@@ -202,10 +218,41 @@ class CreateElection extends Component {
});
};
+ formatDate = (dateIsoStr,timeIsoStr) => {
+ let date= new Date(dateIsoStr+"T"+timeIsoStr);
+ let day = date.getDate();
+ let month = date.getMonth() + 1; //Months are zero based
+ let year = date.getFullYear();
+ let hours = date.getHours();
+ let minutes = date.getMinutes();
+
+ if(month<10){
+ month="0"+month;
+ }
+ if(day<10){
+ day="0"+day;
+ }
+ if(hours<10){
+ hours="0"+hours;
+ }
+ if(minutes<10){
+ minutes="0"+minutes;
+ }
+ let hoursString=hours+"h"+minutes;
+ if(hoursString==="23h59"){
+ hoursString="minuit";
+ }
+
+ return day+"/"+month+"/"+year+" à "+hoursString;
+ };
+
render(){
const { successCreate, redirectTo } = this.state;
+ const { electorEmails } = this.state;
const params = new URLSearchParams(this.props.location.search);
+
+
if (successCreate) return
Le vote se déroulera du {this.formatDate(this.state.startedDayAt,this.state.startedTimeAt)} au {this.formatDate(this.state.finishedDayAt,this.state.finishedTimeAt)}
+Aucune adresse e-mail précisée.
Le vote sera ouvert à tous les utilisateurs ayant le lien du vote