From be07a76b041bb5154b2f51579e96225317894977 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Guhur Date: Sun, 6 Nov 2022 08:55:13 +0100 Subject: [PATCH] wip: confirm --- components/ListInput.tsx | 94 ++++--- components/admin/CandidateField.tsx | 2 +- components/admin/ConfirmField.tsx | 71 +++++ components/admin/ConfirmModal.tsx | 401 ---------------------------- components/admin/ParamsField.tsx | 2 +- package.json | 7 + pages/admin/new.tsx | 23 +- public/locales/en/resource.json | 4 +- public/locales/fr/resource.json | 4 +- 9 files changed, 140 insertions(+), 468 deletions(-) create mode 100644 components/admin/ConfirmField.tsx delete mode 100644 components/admin/ConfirmModal.tsx diff --git a/components/ListInput.tsx b/components/ListInput.tsx index 04e00bf..280edd0 100644 --- a/components/ListInput.tsx +++ b/components/ListInput.tsx @@ -1,68 +1,64 @@ -import {useTranslation} from "next-i18next"; -import {faXmark} from "@fortawesome/free-solid-svg-icons"; -import {FontAwesomeIcon} from "@fortawesome/react-fontawesome" -import {Row, Col} from "reactstrap" -import {useState} from "react"; -import Button from "@components/Button" +import { useTranslation } from 'next-i18next'; +import { faXmark } from '@fortawesome/free-solid-svg-icons'; +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import { Row, Col } from 'reactstrap'; +import { useState } from 'react'; +import Button from '@components/Button'; +const InputField = ({ value, onDelete }) => { + return ( + + ); +}; -const InputField = ({value, onDelete}) => { - return -} +const ListInput = ({ onEdit, inputs, validator }) => { + const [state, setState] = useState(''); - -const ListInput = ({onEdit, inputs, validator}) => { - - const [state, setState] = useState(""); - - const {t} = useTranslation(); + const { t } = useTranslation(); const handleDelete = (position: number) => { - onEdit({...inputs}.splice(position)) - } + onEdit({ ...inputs }.splice(position)); + }; const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === 'Enter') { if (validator(state)) { - setState(""); - onEdit([...inputs, state]) + setState(''); + onEdit([...inputs, state]); } } - } + }; const handleChange = (e: React.ChangeEvent) => { setState(e.target.value); - } + }; - return - {inputs.map((item, i) => - - handleDelete(i)} + return ( + + {inputs.map((item, i) => ( + + handleDelete(i)} /> + + ))} + + - ) - } - - - - -} + + ); +}; export default ListInput; diff --git a/components/admin/CandidateField.tsx b/components/admin/CandidateField.tsx index ade728f..92c4cfb 100644 --- a/components/admin/CandidateField.tsx +++ b/components/admin/CandidateField.tsx @@ -16,7 +16,7 @@ import CandidateModalSet from './CandidateModalSet'; import CandidateModalDel from './CandidateModalDel'; -const CandidateField = ({position, className, ...inputProps}) => { +const CandidateField = ({position, className = '', ...inputProps}) => { const {t} = useTranslation(); const election = useElection(); diff --git a/components/admin/ConfirmField.tsx b/components/admin/ConfirmField.tsx new file mode 100644 index 0000000..e18466e --- /dev/null +++ b/components/admin/ConfirmField.tsx @@ -0,0 +1,71 @@ +import {useTranslation} from "next-i18next"; +import Footer from "@components/layouts/Footer"; +import TrashButton from "./TrashButton"; +import { + faExclamationTriangle, + faCheck, + faArrowLeft, + faPen, +} from "@fortawesome/free-solid-svg-icons"; +import {Button, Modal, ModalHeader, ModalBody, ModalFooter, Row, Col, Label, Container} from "reactstrap"; +import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"; +import {useElection} from "./ElectionContext"; +import CandidateField from "./CandidateField"; + + +const TitleField = () => { + const {t} = useTranslation(); + const election = useElection(); + return + + +

{t('admin.access-results')}

+ +
+

+ {election.title} +

+
+} + + +const CandidatesField = () => { + const {t} = useTranslation(); + const election = useElection(); + return + + +

{t('admin.access-results')}

+ + + + +
+ {election.candidates.map((_, i) => + + )} +
+} + + +const ConfirmField = ({onSubmit, goToCandidates, goToParams}) => { + const {t} = useTranslation(); + const election = useElection(); + + return ( + + + +

{t('common.the-vote')}

+ + + + + + +
+
+ ) +} + +export default ConfirmField diff --git a/components/admin/ConfirmModal.tsx b/components/admin/ConfirmModal.tsx deleted file mode 100644 index 924ed82..0000000 --- a/components/admin/ConfirmModal.tsx +++ /dev/null @@ -1,401 +0,0 @@ -import {useTranslation} from "next-i18next"; -import {useState} from "react"; -import Footer from "@components/layouts/Footer"; -import TrashButton from "./TrashButton"; -import { - faExclamationTriangle, - faCheck, - faArrowLeft, - faTrashAlt -} from "@fortawesome/free-solid-svg-icons"; -import {Button, Modal, ModalHeader, ModalBody, ModalFooter, Row, Col, Label, Input} from "reactstrap"; -import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"; - -const ConfirmModal = ({CreateElection, handleRestrictResultCheck, handleIsTimeLimited, tabIndex, title, candidates, grades, isTimeLimited, start, finish, emails, restrictResult, className, confirmCallback, onSubmit}) => { - const [visibled, setVisibility] = useState(false); - const {t} = useTranslation(); - const toggle = () => setVisibility(!visibled) - - const isValidDate = (date) => date instanceof Date && !isNaN(date); - const getOnlyValidDate = (date) => (isValidDate(date) ? date : new Date()); - - // Convert a Date object into YYYY-MM-DD - const dateToISO = (date) => - getOnlyValidDate(date).toISOString().substring(0, 10); - - - // Retrieve the current hour, minute, sec, ms, time into a timestamp - const hours = (date) => getOnlyValidDate(date).getHours() * 3600 * 1000; - const minutes = (date) => getOnlyValidDate(date).getMinutes() * 60 * 1000; - const seconds = (date) => getOnlyValidDate(date).getSeconds() * 1000; - const ms = (date) => getOnlyValidDate(date).getMilliseconds(); - const time = (date) => - hours(getOnlyValidDate(date)) + - minutes(getOnlyValidDate(date)) + - seconds(getOnlyValidDate(date)) + - ms(getOnlyValidDate(date)); - - // Retrieve the time part from a timestamp and remove the day. Return a int. - const timeMinusDate = (date) => time(getOnlyValidDate(date)); - - // Retrieve the day and remove the time. Return a Date - const dateMinusTime = (date) => - new Date(getOnlyValidDate(date).getTime() - time(getOnlyValidDate(date))); - - const displayClockOptions = () => - Array(24) - .fill(1) - .map((x, i) => ( - - )); - - - return ( -
- - - - - -
Retour aux paramètres
- - - - -

Les candidats

- - - -

Paramètres du vote

- - - -

Confirmation

- -
-
-
- - - -
{t("Le vote")}
-
{t("Confirmation du vote")}
-
- - -
- {t("Question of the election")} -
-
- -
{title}
- -
- -
- - -
- {t("Candidates/Proposals")} -
-
- -
-
    - {candidates.map((candidate, i) => { - if (candidate.label !== "") { - return ( -
  • -
    -
    - -
    - {candidate.label} -
    - -
  • - ); - } else { - return
  • ; - } - })} -
-
-
- -
- - -
{t("Les paramètres")}
-
- - - - - - - -
- -
- -
- {/*
-
- {t("Dates")} -
-
- {t("The election will take place from")}{" "} - - {start.toLocaleDateString()}, {t("at")}{" "} - {start.toLocaleTimeString()} - {" "} - {t("to")}{" "} - - {finish.toLocaleDateString()}, {t("at")}{" "} - {finish.toLocaleTimeString()} - -
-
*/} -
- - - - - - - - - -
- -
- - -
-
- - - - {t("Starting date")} - - - { - setStart( - new Date( - timeMinusDate(start) + - new Date(e.target.valueAsNumber).getTime() - ) - ); - }} - /> - - - - - - - - - - { - setFinish( - new Date( - timeMinusDate(finish) + - new Date(e.target.valueAsNumber).getTime() - ) - ); - }} - /> - - - - - -
-
- - - -
- {t("Grades")} -
-
- {grades.map((mention, i) => { - return i < grades.length ? ( - - {mention.label} - - ) : ( - - ); - })} -
-
- -
-
- {t("Voters' list")} -
-
- {emails.length > 0 ? ( - emails.join(", ") - ) : ( -

- {t("The form contains no address.")} -
- - {t( - "The election will be opened to anyone with the link" - )} - -

- )} -
-
- {restrictResult ? ( -
-
-
- {t("Results available at any time")} -
-
-
- - ) : ( -
-
-
- - {t("Results available at the close of the vote")} -
-

- - {t( - "The results page will not be accessible until the end date is reached." - )}{" "} - ({finish.toLocaleDateString()} {t("at")}{" "} - {finish.toLocaleTimeString()}) - -

-
-
- )} -
- - -
-
- - - - -
- -
- ) -} - -export default ConfirmModal diff --git a/components/admin/ParamsField.tsx b/components/admin/ParamsField.tsx index ab04537..b911c5b 100644 --- a/components/admin/ParamsField.tsx +++ b/components/admin/ParamsField.tsx @@ -20,7 +20,7 @@ const ParamsField = ({onSubmit}) => { -
+