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

@ -15,25 +15,21 @@ const TitleBar = ({election}: TitleBarInterface) => {
const router = useRouter(); const router = useRouter();
const locale = getLocaleShort(router); const locale = getLocaleShort(router);
const dateEnd = new Date(election.date_end); if (!election.date_end) {
const farAway = new Date();
farAway.setFullYear(farAway.getFullYear() + 1);
const isFarAway = +dateEnd > +farAway;
if (!isFarAway) {
return (
<div className="w-100 bg-light p-2 text-black justify-content-center d-flex ">
<div className="me-2">
<FontAwesomeIcon icon={faCalendarDays} />
</div>
<div>
{` ${t("vote.open-until")} ${new Date(election.date_end).toLocaleDateString(locale, {dateStyle: "long"})}`}
</div>
</div>
)
} else {
return null; return null;
} }
return (
<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>
<div>
{` ${t("vote.open-until")} ${new Date(election.date_end).toLocaleDateString(locale, {dateStyle: "long"})}`}
</div>
</div>
)
}; };
export default TitleBar export default TitleBar

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

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

Loading…
Cancel
Save