diff --git a/pages/privacy-policy.tsx b/pages/privacy-policy.tsx
index 2da3e16..35fded2 100644
--- a/pages/privacy-policy.tsx
+++ b/pages/privacy-policy.tsx
@@ -1,25 +1,26 @@
-import { Col, Container, Row } from 'reactstrap';
-import { useTranslation } from 'next-i18next';
+import {Col, Container, Row} from 'reactstrap';
+import {useTranslation} from 'next-i18next';
import Link from 'next/link';
-import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
-import { GetStaticProps } from 'next';
-import { getLocaleShort } from '@services/utils';
-import { getUrl, RouteTypes } from '@services/routes';
-import { useRouter } from 'next/router';
+import {serverSideTranslations} from 'next-i18next/serverSideTranslations';
+import {GetStaticProps} from 'next';
+import {getLocaleShort} from '@services/utils';
+import {getUrl, RouteTypes} from '@services/routes';
+import {useRouter} from 'next/router';
-export const getStaticProps: GetStaticProps = async ({ locale }) => ({
+export const getStaticProps: GetStaticProps = async ({locale}) => ({
props: {
...(await serverSideTranslations(locale, ['resource'])),
},
});
const PrivacyPolicy = (props) => {
- const { t } = useTranslation();
+ const {t} = useTranslation();
const router = useRouter();
+ const locale = getLocaleShort(router);
return (
-
+
diff --git a/pages/results/[pid]/[[...tid]].tsx b/pages/results/[pid]/[[...tid]].tsx
index 9d9c7c8..78e4cfc 100644
--- a/pages/results/[pid]/[[...tid]].tsx
+++ b/pages/results/[pid]/[[...tid]].tsx
@@ -136,7 +136,8 @@ const ResultBanner = ({result}) => {
const numVotes = getNumVotes(result);
- const url = getUrl(RouteTypes.RESULTS, router, result.ref);
+ const locale = getLocaleShort(router);
+ const url = getUrl(RouteTypes.RESULTS, locale, result.ref);
return (
<>
@@ -234,7 +235,8 @@ const BottomButtonsMobile = ({result}) => {
const {t} = useTranslation();
const router = useRouter();
- const url = getUrl(RouteTypes.RESULTS, router, result.ref);
+ const locale = getLocaleShort(router);
+ const url = getUrl(RouteTypes.RESULTS, locale, result.ref);
return (
@@ -295,7 +297,7 @@ const TitleBanner = ({name, electionRef, token}: TitleBannerInterface) => {
{token ? (
-
+
@@ -315,7 +317,7 @@ const TitleBanner = ({name, electionRef, token}: TitleBannerInterface) => {
{token ? (
-
+
@@ -475,9 +477,10 @@ const ResultPage = ({
}: ResultPageInterface) => {
const {t} = useTranslation();
const router = useRouter();
+ const locale = getLocaleShort(router);
if (err && err.message.startsWith('No votes')) {
- const urlVote = getUrl(RouteTypes.VOTE, router, electionRef, token);
+ const urlVote = getUrl(RouteTypes.VOTE, locale, electionRef, token);
return (
{
@@ -499,7 +502,7 @@ const ResultPage = ({
}
if (err && err.details.startsWith('The election is not closed')) {
- const urlVote = getUrl(RouteTypes.VOTE, router, electionRef, token);
+ const urlVote = getUrl(RouteTypes.VOTE, locale, electionRef, token);
return (
{
diff --git a/pages/votes/[pid]/[[...tid]].tsx b/pages/votes/[pid]/[[...tid]].tsx
index b5f7269..e6468e8 100644
--- a/pages/votes/[pid]/[[...tid]].tsx
+++ b/pages/votes/[pid]/[[...tid]].tsx
@@ -22,7 +22,7 @@ import {
BallotProvider,
} from '@services/BallotContext';
import {getUrl, RouteTypes} from '@services/routes';
-import {isEnded} from '@services/utils';
+import {getLocaleShort, isEnded} from '@services/utils';
import WaitingBallot from '@components/WaitingBallot';
import PatternedBackground from '@components/PatternedBackground';
import {useRouter} from 'next/router';
@@ -46,9 +46,10 @@ export async function getServerSideProps({query: {pid, tid}, locale}) {
}
if (isEnded(election.date_end)) {
+ const url = getUrl(RouteTypes.ENDED_VOTE, locale, electionRef)
return {
redirect: {
- destination: getUrl(RouteTypes.ENDED_VOTE, electionRef),
+ destination: url.toString(),
permanent: false,
},
};
@@ -148,7 +149,8 @@ const VoteBallot = ({election, token, previousBallot}: VoteInterface) => {
};
if (election.restricted) {
- const url = getUrl(RouteTypes.RESTRICTED_VOTE, router)
+ const locale = getLocaleShort(router);
+ const url = getUrl(RouteTypes.RESTRICTED_VOTE, locale)
router.push(url);
}
diff --git a/services/routes.ts b/services/routes.ts
index c31d32a..bff4942 100644
--- a/services/routes.ts
+++ b/services/routes.ts
@@ -1,7 +1,6 @@
/**
* This file provides the paths to the pages
*/
-import {NextRouter} from 'next/router';
import {getWindowUrl, displayRef, getLocaleShort} from './utils';
export enum RouteTypes {
@@ -18,11 +17,10 @@ export enum RouteTypes {
export const getUrl = (
type: RouteTypes,
- router: NextRouter,
+ locale: string,
ref?: string,
token?: string
): URL => {
- const locale = getLocaleShort(router);
if (ref) {
if (token) {
diff --git a/services/utils.ts b/services/utils.ts
index a3dd80c..072ba12 100644
--- a/services/utils.ts
+++ b/services/utils.ts
@@ -2,10 +2,11 @@
* This file contains several utils functions
*/
-import { NextRouter } from 'next/router';
+import {NextRouter} from 'next/router';
import {URL_APP} from './constants';
export const getLocaleShort = (router: NextRouter): string => {
+ console.log("router", router)
if (!router.locale) {
return router.defaultLocale.substring(0, 2);
}
@@ -14,7 +15,7 @@ export const getLocaleShort = (router: NextRouter): string => {
};
export const getWindowUrl = (): string => {
- if( typeof window !== 'undefined' && window.location.origin)
+ if (typeof window !== 'undefined' && window.location.origin)
return window.location.origin;
if (process.env.NODE_ENV === 'development')
return "http://localhost:3000";