From 5c6512b8ea6c7e55fac6949fe2ccc2657b2a0b8f Mon Sep 17 00:00:00 2001 From: Pierre-Louis Guhur Date: Tue, 7 Apr 2020 11:13:59 +0200 Subject: [PATCH] [CREATE] fix timestamp bug --- package.json | 1 + src/components/views/CreateElection.jsx | 337 +- yarn.lock | 6284 +++++++++++------------ 3 files changed, 3201 insertions(+), 3421 deletions(-) diff --git a/package.json b/package.json index 869719c..796310b 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,7 @@ "postcss-normalize": "7.0.1", "postcss-preset-env": "6.6.0", "postcss-safe-parser": "4.0.1", + "query-string": "^6.12.0", "querystringify": "^2.0.0", "react": "^16.8.6", "react-app-polyfill": "^1.0.1", diff --git a/src/components/views/CreateElection.jsx b/src/components/views/CreateElection.jsx index 64a8c37..b1c3023 100644 --- a/src/components/views/CreateElection.jsx +++ b/src/components/views/CreateElection.jsx @@ -1,5 +1,5 @@ -import React, { Component } from "react"; -import { Redirect } from "react-router-dom"; +import React, {Component} from 'react'; +import {Redirect, withRouter} from 'react-router-dom'; import { Collapse, Container, @@ -11,41 +11,58 @@ import { InputGroupAddon, Button, Card, - CardBody -} from "reactstrap"; + CardBody, +} from 'reactstrap'; -import { toast, ToastContainer } from "react-toastify"; -import "react-toastify/dist/ReactToastify.css"; -import { resolve } from "url"; -import HelpButton from "../form/HelpButton"; +import {toast, ToastContainer} from 'react-toastify'; +import 'react-toastify/dist/ReactToastify.css'; +import {resolve} from 'url'; +import queryString from 'query-string'; +import HelpButton from '../form/HelpButton'; import { arrayMove, sortableContainer, sortableElement, - sortableHandle -} from "react-sortable-hoc"; -import ButtonWithConfirm from "../form/ButtonWithConfirm"; + sortableHandle, +} from 'react-sortable-hoc'; +import ButtonWithConfirm from '../form/ButtonWithConfirm'; -import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; +import {FontAwesomeIcon} from '@fortawesome/react-fontawesome'; import { faPlus, faTrashAlt, faCheck, - faCogs -} from "@fortawesome/free-solid-svg-icons"; + faCogs, +} from '@fortawesome/free-solid-svg-icons'; -import { grades } from "../../Util"; -import { ReactMultiEmail, isEmail } from "react-multi-email"; -import "react-multi-email/style.css"; -import { AppContext } from "../../AppContext"; +import {grades} from '../../Util'; +import {ReactMultiEmail, isEmail} from 'react-multi-email'; +import 'react-multi-email/style.css'; +import {AppContext} from '../../AppContext'; -const DragHandle = sortableHandle(({ children }) => ( +// Convert a Date object into YYYY-MM-DD +const dateToISO = date => date.toISOString().substring(0, 10); + +// Retrieve the current hour, minute, sec, ms, time into a timestamp +const hours = date => date.getHours() * 3600 * 1000; +const minutes = date => date.getMinutes() * 60 * 1000; +const seconds = date => date.getSeconds() * 1000; +const ms = date => date.getMilliseconds() * 1000; +const time = date => hours(date) + minutes(date) + seconds(date) + ms(date); + +// Retrieve the time part from a timestamp and remove the day. Return a int. +const timeMinusDate = date => time(date); + +// Retrieve the day and remove the time. Return a Date +const dateMinusTime = date => new Date(date.getTime() - time(date)); + +const DragHandle = sortableHandle(({children}) => ( {children} )); -const SortableCandidate = sortableElement(({ candidate, sortIndex, form }) => ( +const SortableCandidate = sortableElement(({candidate, sortIndex, form}) => (
  • - + @@ -71,18 +88,17 @@ const SortableCandidate = sortableElement(({ candidate, sortIndex, form }) => (
    Suppression ?
    - Êtes-vous sûr de vouloir supprimer{" "} - {candidate.label !== "" ? ( + Êtes-vous sûr de vouloir supprimer{' '} + {candidate.label !== '' ? ( "{candidate.label}" ) : ( la ligne {sortIndex + 1} - )}{" "} + )}{' '} ?
    form.removeCandidate(sortIndex)} - > + onClick={() => form.removeCandidate(sortIndex)}> Oui
    Non
    @@ -99,7 +115,7 @@ const SortableCandidate = sortableElement(({ candidate, sortIndex, form }) => (
  • )); -const SortableCandidatesContainer = sortableContainer(({ items, form }) => { +const SortableCandidatesContainer = sortableContainer(({items, form}) => { return (