fix: error message hide-result election

pull/100/head
Pierre-Louis Guhur 1 year ago
parent e3f7e8a574
commit 64b295f0fc

@ -1,10 +1,10 @@
import { useTranslation } from 'next-i18next';
import { ElectionTypes, useElection } from '@services/ElectionContext';
import { Container } from 'reactstrap';
import {useTranslation} from 'next-i18next';
import {ElectionTypes, useElection} from '@services/ElectionContext';
import {Container} from 'reactstrap';
import Switch from '@components/Switch';
const AccessResults = () => {
const { t } = useTranslation();
const {t} = useTranslation();
const [election, dispatch] = useElection();
const toggle = () => {
@ -17,13 +17,13 @@ const AccessResults = () => {
return (
<Container className="bg-white p-3 p-md-4">
<div className="d-flex">
<div className="me-auto d-flex flex-row justify-content-center">
<div className="d-flex gap-3">
<div className="me-auto d-flex flex-column justify-content-center">
<h5 className="mb-0 text-dark d-flex align-items-center">
{t('admin.access-results')}
</h5>
{election.hideResults ? (
<p className="text-muted d-none d-md-block">
<p className="text-muted">
{t('admin.access-results-desc')}
</p>
) : null}

@ -1,12 +1,12 @@
import { useState } from 'react';
import { useTranslation } from 'next-i18next';
import { Container, Row, Col } from 'reactstrap';
import {useState} from 'react';
import {useTranslation} from 'next-i18next';
import {Container, Row, Col} from 'reactstrap';
import DatePicker from '@components/DatePicker';
import Switch from '@components/Switch';
import { ElectionTypes, useElection } from '@services/ElectionContext';
import {ElectionTypes, useElection} from '@services/ElectionContext';
const LimitDate = () => {
const { t } = useTranslation();
const {t} = useTranslation();
const defaultEndDate = new Date();
defaultEndDate.setUTCDate(defaultEndDate.getUTCDate() + 15);
const [endDate, setEndDate] = useState(defaultEndDate);
@ -30,8 +30,8 @@ const LimitDate = () => {
return (
<Container className="bg-white p-3 p-md-4 mt-1">
<div className="d-flex">
<div className="me-auto d-flex flex-row justify-content-center">
<h5 className="mb-0 text-dark d-flex align-items-center">
<div className="me-auto d-flex align-items-start justify-content-center">
<h5 className="mb-0 text-dark gap-2 flex-column flex-md-row d-flex align-items-start">
{t('admin.limit-duration')}
{hasDate ? (
<>

@ -44,8 +44,8 @@ export async function getServerSideProps({query, locale}) {
serverSideTranslations(locale, ['resource']),
]);
if ('msg' in payload) {
return {props: {err: {message: payload.msg}, electionRef, ...translations}};
if ('message' in payload) {
return {props: {err: payload, electionRef, ...translations}};
}
const numGrades = payload.grades.length;
@ -458,6 +458,7 @@ const Podium = ({candidates}: PodiumInterface) => {
interface ErrorInterface {
message: string;
details?: string;
}
interface ResultPageInterface {
result?: ResultInterface;
@ -483,9 +484,34 @@ const ResultPage = ({
<>
<p>{t('result.no-votes')}</p>
<Link href={urlVote}>
<Button color="primary" icon={faArrowRight} position="right">
{t('result.go-to-vote')}
</Button>
<div className="d-md-flex d-grid">
<Button
className="d-md-flex d-grid"
color="primary" icon={faArrowRight} position="right">
{t('result.go-to-vote')}
</Button>
</div>
</Link>
</>
}
</ErrorMessage>
);
}
console.log(err)
if (err && err.details.startsWith('The election is not closed')) {
const urlVote = getUrl(RouteTypes.VOTE, router, electionRef, token);
return (
<ErrorMessage>
{
<>
<p>{t('result.hide-results')}</p>
<Link href={urlVote}>
<div className="d-md-flex d-grid">
<Button color="primary" icon={faArrowRight} position="right">
{t('result.go-to-vote')}
</Button>
</div>
</Link>
</>
}

@ -172,10 +172,11 @@
"admin.error": "Unable to load the election.",
"result.download": "Download results",
"result.go-to-admin": "Manage the election",
"result.go-to-vote": "Would you go to the voting page?",
"result.go-to-vote": "Do you want to go to the voting page?",
"result.no-votes": "No vote has been recorded yet.",
"result.merit-profile": "Merit profile of the candidate",
"result.has-closed": "Closed since",
"result.hide-results": "Results are hidden until the election is closed",
"result.opened": "The election is opened",
"result.closed": "The election is closed",
"result.result": "Results of the election",

@ -176,6 +176,7 @@
"result.go-to-vote": "Souhaitez-vous accéder au vote ?",
"result.no-votes": "Aucun vote n'a encore été enregistré.",
"result.has-closed": "Terminée depuis",
"result.hide-results": "Les résults sont masqués jusqu'à la fermeture de l'élection.",
"result.closed": "L'élection est terminée",
"result.opened": "L'élection est en cours",
"result.result": "Résultat du vote",

@ -37,7 +37,7 @@ export interface ErrorPayload {
export interface HTTPPayload {
status: number;
msg: string;
message: string;
}
export interface ElectionPayload {
@ -186,22 +186,22 @@ export const updateElection = async (
});
if (!req.ok || req.status !== 200) {
const payload = await req.json();
return {status: req.status, msg: payload};
return {status: req.status, ...payload};
}
const payload = await req.json();
return {status: 200, ...payload};
} catch (e) {
console.error(e);
return {status: 400, msg: `Unknown API error: ${e}`};
return {status: 400, message: `Unknown API error: ${e}`};
}
};
/**
* Fetch results from external API
*/
export const getResults = async (
pid: string
): Promise<ResultsPayload | HTTPPayload> => {
/**
* Fetch results from external API
*/
const endpoint = new URL(
api.routesServer.getResults.replace(new RegExp(':slug', 'g'), pid),
@ -212,13 +212,14 @@ export const getResults = async (
const response = await fetch(endpoint.href);
if (response.status != 200) {
const payload = await response.json();
return {status: response.status, msg: payload};
console.log("PAYLOAD", payload)
return {status: response.status, ...payload};
}
const payload = await response.json();
return {...payload, status: response.status};
} catch (error) {
console.error(error);
return {status: 400, msg: `Unknown API error: ${error}`};
return {status: 400, message: `Unknown API error: ${error}`};
}
};
@ -239,12 +240,12 @@ export const getElection = async (
if (response.status != 200) {
const payload = await response.json();
return {status: response.status, msg: payload};
return {status: response.status, message: payload};
}
const payload = await response.json();
return {...payload, status: response.status};
} catch (error) {
return {status: 400, msg: 'Unknown API error'};
return {status: 400, message: 'Unknown API error'};
}
};
@ -270,7 +271,6 @@ export const getBallot = async (
});
if (response.status != 200) {
console.log("STATUS", await response.text())
return null;
}
@ -278,7 +278,7 @@ export const getBallot = async (
return {...payload, status: response.status};
} catch (error) {
return {status: 400, msg: 'Unknown API error'};
return {status: 400, message: 'Unknown API error'};
}
};

Loading…
Cancel
Save