import { createRef } from "react"; import Head from "next/head"; import { useRouter } from "next/router"; import { useTranslation } from "next-i18next"; import { serverSideTranslations } from "next-i18next/serverSideTranslations"; import { getDetails, apiErrors, ELECTION_NOT_STARTED_ERROR, } from "@services/api"; import { Col, Container, Row } from "reactstrap"; import Link from "next/link"; import { faCopy, faVoteYea, faExclamationTriangle, faExternalLinkAlt, faPollH, } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import CopyField from "@components/CopyField"; import Error from "@components/Error"; import Facebook from "@components/banner/Facebook"; import config from "../../../next-i18next.config.js"; export async function getServerSideProps({ query: { pid }, locale }) { let [details, translations] = await Promise.all([ getDetails(pid), serverSideTranslations(locale, [], config), ]); if (details.includes(ELECTION_NOT_STARTED_ERROR)) { details = { title: "", on_invitation_only: true, restrict_results: true }; } else { if (typeof details === "string" || details instanceof String) { return { props: { err: details, ...translations } }; } if (!details.title) { return { props: { err: "Unknown error", ...translations } }; } } return { props: { invitationOnly: details.on_invitation_only, restrictResults: details.restrict_results, title: details.title, pid: pid, ...translations, }, }; } const ConfirmElection = ({ title, restrictResults, invitationOnly, pid, err, }) => { const { t } = useTranslation(); if (err) { return ; } const origin = typeof window !== "undefined" && window.location.origin ? window.location.origin : "http://localhost"; const urlVote = new URL(`/vote/${pid}`, origin); const urlResult = new URL(`/result/${pid}`, origin); const electionLink = invitationOnly ? ( <>

{t( "Voters received a link to vote by email. Each link can be used only once!" )}

) : ( <>

{t("Voting address")}

); const fb = invitationOnly ? null : ( ); const participate = invitationOnly ? null : ( <> {t("resource.participateBtn")} ); return ( {t("Successful election creation!")}

{t("Successful election creation!")}

{fb}

{title}

{t("Keep these links carefully")}
{electionLink}

{t("Results address")}

{participate} {t("resource.resultsBtn")}
); }; export default ConfirmElection;