fix: admin link to vote

pull/100/head
Pierre-Louis Guhur 1 year ago
parent df69172655
commit de08bfa8ef

@ -1,16 +1,13 @@
import {useState, useEffect, useRef, KeyboardEvent, ChangeEvent} from 'react';
import {useState, useEffect, useRef, KeyboardEvent} from 'react';
import {Label, Modal, ModalBody, Form} from 'reactstrap';
import {faPlus, faArrowLeft} from '@fortawesome/free-solid-svg-icons';
import {useTranslation} from 'next-i18next';
import {ElectionTypes, useElection} from '@services/ElectionContext';
import Button from '@components/Button';
import {checkName} from '@services/ElectionContext';
import {AppTypes, useAppContext} from '@services/context';
import {useRouter} from 'next/router';
const TitleModal = ({isOpen, toggle}) => {
const {t} = useTranslation();
const router = useRouter();
const [election, dispatch] = useElection();
const [_, dispatchApp] = useAppContext();
const [name, setName] = useState(election.name);

@ -150,17 +150,16 @@ const HeaderRubbonDesktop = ({handleClosing, handleSubmit, waiting}) => {
<h5 className="mx-0">{t('admin.admin-title')}</h5>
<div className="d-flex">
<Link href={getUrl(RouteTypes.VOTE, router, election.ref)}>
<Button
icon={faFloppyDisk}
color="primary"
className="me-3"
style={{border: '2px solid rgba(255, 255, 255, 0.4)'}}
position="right"
>
{t('common.save')}
</Button>
</Link>
<Button
icon={faFloppyDisk}
color="primary"
className="me-3"
onClick={handleSubmit}
style={{border: '2px solid rgba(255, 255, 255, 0.4)'}}
position="right"
>
{t('common.save')}
</Button>
{!election.restricted && !isClosed(election) && (
<Link href={getUrl(RouteTypes.VOTE, router, election.ref)}>
<Button
@ -200,7 +199,7 @@ const HeaderRubbonDesktop = ({handleClosing, handleSubmit, waiting}) => {
</Button>
)}
</div>
</div>
</div >
);
};

@ -0,0 +1,48 @@
import {serverSideTranslations} from 'next-i18next/serverSideTranslations';
import {useTranslation} from 'next-i18next';
import {Container} from 'reactstrap';
import {faEnvelope} from '@fortawesome/free-solid-svg-icons';
import Button from '@components/Button';
import {CONTACT_MAIL} from '@services/constants';
export async function getServerSideProps({locale}) {
const translations = await serverSideTranslations(locale, ['resource'])
return {
props: {
...translations,
},
};
}
const RestrictedVote = () => {
const {t} = useTranslation();
return (
<div className="flex-fill d-flex align-items-center bg-secondary pt-3 pb-5">
<Container style={{maxWidth: '700px'}} className="mb-5 ">
<h4>{t('error.restricted-election-title')}</h4>
<p>{t('error.restricted-election-desc')}</p>
<a
href={`mailto:${CONTACT_MAIL}?subject=[HELP]`}
className="d-md-flex d-grid"
>
<Button
color="secondary"
outline={true}
className="text-white"
icon={faEnvelope}
>
{t('error.help')}
</Button>
</a>
</Container>
</div>
);
};
export default RestrictedVote;

@ -25,6 +25,7 @@ import {getUrl, RouteTypes} from '@services/routes';
import {isEnded} from '@services/utils';
import WaitingBallot from '@components/WaitingBallot';
import PatternedBackground from '@components/PatternedBackground';
import {useRouter} from 'next/router';
const shuffle = (array) => array.sort(() => Math.random() - 0.5);
@ -109,6 +110,7 @@ const VoteBallot = ({election, token, previousBallot}: VoteInterface) => {
const {t} = useTranslation();
const [ballot, dispatch] = useBallot();
const router = useRouter();
const [voting, setVoting] = useState(false);
const [payload, setPayload] = useState<BallotPayload | null>(null);
@ -145,6 +147,11 @@ const VoteBallot = ({election, token, previousBallot}: VoteInterface) => {
}
};
if (election.restricted) {
const url = getUrl(RouteTypes.RESTRICTED_VOTE, router)
router.push(url);
}
if (voting) {
return (
<PatternedBackground>

@ -64,6 +64,8 @@
"error.not-enough-grades": "Not enough grades",
"error.not-enough-candidates": "Not enough candidates",
"error.uncorrect-name": "The title is incorrect",
"error.restricted-election-title": "The election is restricted",
"error.restricted-election-desc": "You can only vote if you have been invited.",
"faq.title": "Frequently asked questions",
"faq.sec-1-title": "What is majority judgment?",
"faq.sec-1-desc": "A simple and intuitive principle, which changes everything: the voter votes by giving his/her opinion on all the candidates, by attributing to each one a mention on a scale of values (e.g. Very good, Good, Fair, Insufficient, To be rejected). The candidate with the highest majority rating wins the election (the one with \"the highest majority\" rating).",

@ -66,6 +66,8 @@
"error.uncorrect-name": "The title is incorrect",
"error.not-enough-grades": "Il manque des mentions",
"error.not-enough-candidates": "Il manque des candidats",
"error.restricted-election-title": "L'élection est restreinte",
"error.restricted-election-desc": "Vous ne pouvez accéder à cette élection que par une invitation.",
"faq.title": "Foire aux questions",
"faq.sec-1-title": "Qu'est-ce que le jugement majoritaire ?",
"faq.sec-1-desc": "Un principe simple et intuitif, qui change tout : lélecteur vote en donnant son avis sur tous les candidats, en leur attribuant à chacun une mention sur une échelle de valeurs (par exemple. Très bien, Bien, Assez bien, Passable, Insuffisant, À Rejeter). Le candidat le mieux évalué par une majorité remporte lélection (celui qui obtient la meilleure mention « majoritaire »).",

@ -1,8 +1,8 @@
/**
* This file provides the paths to the pages
*/
import { NextRouter } from 'next/router';
import { getWindowUrl, displayRef, getLocaleShort } from './utils';
import {NextRouter} from 'next/router';
import {getWindowUrl, displayRef, getLocaleShort} from './utils';
export enum RouteTypes {
ADMIN = 'admin',
@ -13,6 +13,7 @@ export enum RouteTypes {
HOME = '',
RESULTS = 'results',
VOTE = 'votes',
RESTRICTED_VOTE = 'errors/restricted',
}
export const getUrl = (

Loading…
Cancel
Save