{gradeIds
.slice(0)
.reverse()
@@ -305,6 +313,7 @@ const Result = ({ candidates, numGrades, title, pid, err, finish }) => {
);
})}
+ */}
@@ -326,4 +335,5 @@ const Result = ({ candidates, numGrades, title, pid, err, finish }) => {
);
};
-export default Result;
+
+export default Results;
diff --git a/pages/vote/[pid]/[[...tid]].tsx b/pages/vote/[pid]/[[...tid]].tsx
index 6b40e30..fc0b32d 100644
--- a/pages/vote/[pid]/[[...tid]].tsx
+++ b/pages/vote/[pid]/[[...tid]].tsx
@@ -1,8 +1,8 @@
-import { useState, useCallback, useEffect } from 'react';
+import {useState, useCallback, useEffect} from 'react';
import Head from 'next/head';
-import { useRouter } from 'next/router';
-import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
-import { useTranslation } from 'next-i18next';
+import {useRouter} from 'next/router';
+import {serverSideTranslations} from 'next-i18next/serverSideTranslations';
+import {useTranslation} from 'next-i18next';
import {
Button,
Col,
@@ -14,11 +14,10 @@ import {
} from 'reactstrap';
import Link from 'next/link';
// import {toast, ToastContainer} from "react-toastify";
-import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
-import { faCheck } from '@fortawesome/free-solid-svg-icons';
-import { getDetails, castBallot, apiErrors } from '@services/api';
-import Error from '@components/Error';
-import { translateGrades } from '@services/grades';
+import {FontAwesomeIcon} from '@fortawesome/react-fontawesome';
+import {faCheck} from '@fortawesome/free-solid-svg-icons';
+import {getElection, castBallot, apiErrors, ElectionPayload} from '@services/api';
+import ErrorMessage from '@components/Error';
import Footer from '@components/layouts/Footer';
import useEmblaCarousel from 'embla-carousel-react';
import {
@@ -27,21 +26,22 @@ import {
NextButton,
} from '@components/admin/EmblaCarouselButtons';
import VoteButtonWithConfirm from '@components/admin/VoteButtonWithConfirm';
+import {getGradeColor} from '@services/grades';
const shuffle = (array) => array.sort(() => Math.random() - 0.5);
-export async function getServerSideProps({ query: { pid, tid }, locale }) {
+export async function getServerSideProps({query: {pid, tid}, locale}) {
const [details, translations] = await Promise.all([
- getDetails(pid),
+ getElection(pid),
serverSideTranslations(locale, ['resource']),
]);
if (typeof details === 'string' || details instanceof String) {
- return { props: { err: details, ...translations } };
+ return {props: {err: details, ...translations}};
}
if (!details.candidates || !Array.isArray(details.candidates)) {
- return { props: { err: 'Unknown error', ...translations } };
+ return {props: {err: 'Unknown error', ...translations}};
}
shuffle(details.candidates);
@@ -53,7 +53,7 @@ export async function getServerSideProps({ query: { pid, tid }, locale }) {
restrictResults: details.restrict_results,
candidates: details.candidates.map((name, i, infos) => ({
id: i,
- label: name,
+ name: name,
description: infos,
})),
title: details.title,
@@ -64,13 +64,20 @@ export async function getServerSideProps({ query: { pid, tid }, locale }) {
};
}
-const VoteBallot = ({ candidates, title, numGrades, pid, err, token }) => {
- const { t } = useTranslation();
+interface VoteInterface {
+ election: ElectionPayload;
+ err: string;
+ token?: string;
+}
+
+const VoteBallot = ({election, err, token}: VoteInterface) => {
+ const {t} = useTranslation();
if (err) {
- return
;
+ return
;
}
+ const numGrades = election.grades.length;
const [judgments, setJudgments] = useState([]);
const colSizeCandidateLg = 4;
const colSizeCandidateMd = 6;
@@ -81,11 +88,6 @@ const VoteBallot = ({ candidates, title, numGrades, pid, err, token }) => {
const router = useRouter();
- const allGrades = translateGrades(t);
- const grades = allGrades.filter(
- (grade) => grade.value >= allGrades.length - numGrades
- );
-
const handleGradeClick = (event) => {
let data = {
id: parseInt(event.currentTarget.getAttribute('data-id')),
@@ -115,8 +117,8 @@ const VoteBallot = ({ candidates, title, numGrades, pid, err, token }) => {
gradesByCandidate.push(gradesById[id]);
});
- castBallot(gradesByCandidate, pid, token, () => {
- router.push(`/vote/${pid}/confirm`);
+ castBallot(gradesByCandidate, election.id.toString(), token, () => {
+ router.push(`/vote/${election.id}/confirm`);
});
};
const toggle = () => setVisibility(!visibled);
@@ -126,7 +128,7 @@ const VoteBallot = ({ candidates, title, numGrades, pid, err, token }) => {
const toggleDesktop = () => setVisibilityDesktop(!visibledDesktop);
const [visibledDesktop, setVisibilityDesktop] = useState(false);
- const [viewportRef, embla] = useEmblaCarousel({ skipSnaps: false });
+ const [viewportRef, embla] = useEmblaCarousel({skipSnaps: false});
const [prevBtnEnabled, setPrevBtnEnabled] = useState(false);
const [nextBtnEnabled, setNextBtnEnabled] = useState(false);
const [selectedIndex, setSelectedIndex] = useState(0);
@@ -156,10 +158,9 @@ const VoteBallot = ({ candidates, title, numGrades, pid, err, token }) => {
return (
- {title}
+ {election.name}
- {title}
-
+
{
className="modalVote voteDesktop"
>
-
{title}
+
{election.name}