From fb57aa8c94b1cf0190489a840ab8d64468772163 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Guhur Date: Thu, 1 Dec 2022 07:50:03 +0100 Subject: [PATCH] fix: cleanup election ref --- components/WaitingBallot.tsx | 19 ++++++++++++------- components/WaitingElection.tsx | 8 ++++---- components/admin/AdminModalEmail.tsx | 6 +++--- components/admin/ConfirmField.tsx | 5 ++--- pages/vote/[pid]/[[...tid]].tsx | 12 ++++++------ services/routes.ts | 17 +++++++++-------- services/utils.ts | 7 +++++++ 7 files changed, 43 insertions(+), 31 deletions(-) diff --git a/components/WaitingBallot.tsx b/components/WaitingBallot.tsx index 2f384ab..7e22859 100644 --- a/components/WaitingBallot.tsx +++ b/components/WaitingBallot.tsx @@ -11,11 +11,14 @@ import ErrorMessage from '@components/Error'; import AdminModalEmail from '@components/admin/AdminModalEmail'; import {BallotPayload, ErrorPayload} from '@services/api'; import {useAppContext} from '@services/context'; -import {getUrlResults} from '@services/routes'; -import urne from '../public/urne.svg' -import star from '../public/star.svg' +import {displayRef} from '@services/utils'; +import {RESULTS} from '@services/routes'; import Logo from './Logo'; import {FORM_FEEDBACK} from '@services/constants'; +import urne from '../public/urne.svg' +import star from '../public/star.svg' +import logo from '../public/logo-red-blue.svg' +import Link from 'next/link'; export interface WaitingBallotInterface { @@ -32,9 +35,11 @@ const ButtonResults = ({election}) => { if (!election.hideResults || isEnded) { return ( - + + + ) } else { return null; @@ -66,7 +71,7 @@ const SupportBetterVote = () => {
{t('vote.support-better-vote')}
- +

{t('vote.support-desc')}

diff --git a/components/WaitingElection.tsx b/components/WaitingElection.tsx index a03130d..61470e2 100644 --- a/components/WaitingElection.tsx +++ b/components/WaitingElection.tsx @@ -34,8 +34,8 @@ const InfoElection = ({election, error, display}: InfoElectionInterface) => { if (!election) return null; - const urlVote = getUrlVote(election.id) - const urlResults = getUrlResults(election.id) + const urlVote = getUrlVote(election.ref) + const urlResults = getUrlResults(election.ref) return (
{ {error && error.detail ? : null} - {election && election.id ? + {election && election.ref ? <>

{t('admin.success-election')} @@ -83,7 +83,7 @@ const InfoElection = ({election, error, display}: InfoElectionInterface) => { : null} diff --git a/components/admin/AdminModalEmail.tsx b/components/admin/AdminModalEmail.tsx index 103256f..36697f8 100644 --- a/components/admin/AdminModalEmail.tsx +++ b/components/admin/AdminModalEmail.tsx @@ -12,16 +12,16 @@ import {useElection} from '@services/ElectionContext'; interface AdminModalEmailInterface { isOpen: boolean; toggle: () => void; - electionId: number | null; + electionRef: string | null; adminToken: string | null; } -const AdminModalEmail = ({isOpen, toggle, electionId, adminToken}: AdminModalEmailInterface) => { +const AdminModalEmail = ({isOpen, toggle, electionRef, adminToken}: AdminModalEmailInterface) => { const {t} = useTranslation(); const [email, setEmail] = useState(undefined); const election = useElection(); - const adminUrl = electionId && adminToken ? getUrlAdmin(electionId.toString(), adminToken) : null; + const adminUrl = electionRef && adminToken ? getUrlAdmin(electionRef, adminToken) : null; const handleEmail = (e) => { setEmail(e.target.value); diff --git a/components/admin/ConfirmField.tsx b/components/admin/ConfirmField.tsx index a22c06e..26582a5 100644 --- a/components/admin/ConfirmField.tsx +++ b/components/admin/ConfirmField.tsx @@ -88,14 +88,13 @@ const submitElection = ( election.restricted, election.randomOrder, async (payload: ElectionPayload) => { - const id = payload.id; const tokens = payload.invites; if (typeof election.emails !== 'undefined' && election.emails.length > 0) { if (typeof payload.invites === 'undefined' || payload.invites.length !== election.emails.length) { throw Error('Can not send invite emails'); } - const urlVotes = payload.invites.map((token: string) => getUrlVote(id.toString(), token)); - const urlResult = getUrlResults(id.toString()); + const urlVotes = payload.invites.map((token: string) => getUrlVote(payload.ref, token)); + const urlResult = getUrlResults(electionRef); await sendInviteMails( election.emails, election.name, diff --git a/pages/vote/[pid]/[[...tid]].tsx b/pages/vote/[pid]/[[...tid]].tsx index dd0be68..e1f5ea9 100644 --- a/pages/vote/[pid]/[[...tid]].tsx +++ b/pages/vote/[pid]/[[...tid]].tsx @@ -21,19 +21,19 @@ export async function getServerSideProps({query: {pid, tid}, locale}) { return { props: { ...(await serverSideTranslations(locale, ['resource'])), - electionId: pid, + electionRef: pid, token: tid || null, }, } } interface VoteInterface { - electionId: string; + electionRef: string; token?: string; } -const GoToBallotConfirm = ({electionId, token}) => { +const GoToBallotConfirm = ({electionRef, token}) => { const {t} = useTranslation(); @@ -52,7 +52,7 @@ const GoToBallotConfirm = ({electionId, token}) => { - +