diff --git a/components/ballot/BallotDesktop.tsx b/components/ballot/BallotDesktop.tsx index eb59472..dc82627 100644 --- a/components/ballot/BallotDesktop.tsx +++ b/components/ballot/BallotDesktop.tsx @@ -18,8 +18,7 @@ const BallotDesktop = ({hasVoted}) => { const [candidate, setCandidate] = useState(null); return ( -
- +
{ 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 (!isFarAway) { - return ( -
-
- -
-
- {` ${t("vote.open-until")} ${new Date(election.date_end).toLocaleDateString(locale, {dateStyle: "long"})}`} -
-
- ) - } else { + if (!election.date_end) { return null; } + + + return ( +
+
+ +
+
+ {` ${t("vote.open-until")} ${new Date(election.date_end).toLocaleDateString(locale, {dateStyle: "long"})}`} +
+
+ ) }; export default TitleBar diff --git a/pages/votes/[pid]/[[...tid]].tsx b/pages/votes/[pid]/[[...tid]].tsx index 53d143b..b65a6d0 100644 --- a/pages/votes/[pid]/[[...tid]].tsx +++ b/pages/votes/[pid]/[[...tid]].tsx @@ -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(null); const [error, setError] = useState(null); + console.log("previous ballot", previousBallot) + useEffect(() => { dispatch({ type: BallotTypes.ELECTION, @@ -163,11 +166,8 @@ const VoteBallot = ({election, token, previousBallot}: VoteInterface) => { } return ( -
+ <> + {election.name} @@ -178,14 +178,20 @@ const VoteBallot = ({election, token, previousBallot}: VoteInterface) => { content={t('common.application')} /> + - -
- - - -
- + +
+ + + +
+ + ); }; diff --git a/services/api.ts b/services/api.ts index 44928c7..7a2b3fc 100644 --- a/services/api.ts +++ b/services/api.ts @@ -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; num_voters: number; - status?: number; } export interface ResultsPayload extends ElectionPayload {