fix: solve ballot error

pull/100/head
Pierre-Louis Guhur 1 year ago
parent d9198e0490
commit c8c62696f0

@ -18,8 +18,7 @@ const BallotDesktop = ({hasVoted}) => {
const [candidate, setCandidate] = useState<CandidatePayload | null>(null);
return (
<div className="w-100 h-100 d-none d-md-block">
<TitleBar election={ballot.election} />
<div className="w-100 h-100 d-none d-md-flex justify-content-between">
<Container
className="w-100 h-100 d-flex flex-column justify-content-center align-items-center"
style={{maxWidth: '1050px'}}

@ -15,14 +15,13 @@ const TitleBar = ({election}: TitleBarInterface) => {
const router = useRouter();
const locale = getLocaleShort(router);
const dateEnd = new Date(election.date_end);
const farAway = new Date();
farAway.setFullYear(farAway.getFullYear() + 1);
const isFarAway = +dateEnd > +farAway;
if (!election.date_end) {
return null;
}
if (!isFarAway) {
return (
<div className="w-100 bg-light p-2 text-black justify-content-center d-flex ">
<div className="w-100 bg-light p-2 text-black justify-content-center d-md-flex d-none ">
<div className="me-2">
<FontAwesomeIcon icon={faCalendarDays} />
</div>
@ -31,9 +30,6 @@ const TitleBar = ({election}: TitleBarInterface) => {
</div>
</div>
)
} else {
return null;
}
};
export default TitleBar

@ -26,6 +26,7 @@ import {getLocaleShort, isEnded} from '@services/utils';
import WaitingBallot from '@components/WaitingBallot';
import PatternedBackground from '@components/PatternedBackground';
import {useRouter} from 'next/router';
import TitleBar from '@components/ballot/TitleBar';
const shuffle = (array) => array.sort(() => Math.random() - 0.5);
@ -74,7 +75,7 @@ export async function getServerSideProps({query: {pid, tid}, locale}) {
...translations,
election,
token: tid || null,
previousBallot: ballot || null,
previousBallot: ballot && ballot.status != 404 ? ballot : null,
},
};
}
@ -117,6 +118,8 @@ const VoteBallot = ({election, token, previousBallot}: VoteInterface) => {
const [payload, setPayload] = useState<BallotPayload | null>(null);
const [error, setError] = useState<ErrorPayload | null>(null);
console.log("previous ballot", previousBallot)
useEffect(() => {
dispatch({
type: BallotTypes.ELECTION,
@ -163,11 +166,8 @@ const VoteBallot = ({election, token, previousBallot}: VoteInterface) => {
}
return (
<form
className="w-100 flex-fill d-flex align-items-center"
onSubmit={handleSubmit}
autoComplete="off"
>
<><TitleBar election={ballot.election} />
<Head>
<title>{election.name}</title>
@ -178,6 +178,11 @@ const VoteBallot = ({election, token, previousBallot}: VoteInterface) => {
content={t('common.application')}
/>
</Head>
<form
className="w-100 flex-fill d-flex align-items-center"
onSubmit={handleSubmit}
autoComplete="off"
>
<Blur />
<div className="w-100 h-100 d-flex flex-column justify-content-center">
@ -186,6 +191,7 @@ const VoteBallot = ({election, token, previousBallot}: VoteInterface) => {
<ButtonSubmit />
</div>
</form>
</>
);
};

@ -42,6 +42,7 @@ export interface HTTPPayload {
export interface ElectionPayload {
name: string;
status?: number;
description: string;
ref: string;
date_start: string;
@ -62,7 +63,6 @@ export interface ElectionCreatedPayload extends ElectionPayload {
export interface ElectionUpdatedPayload extends ElectionPayload {
invites: Array<string>;
num_voters: number;
status?: number;
}
export interface ResultsPayload extends ElectionPayload {

Loading…
Cancel
Save