From 2e788967b288d18db86a51699f448b4840aa6000 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Guhur Date: Tue, 10 Jan 2023 08:45:03 +0100 Subject: [PATCH] fix: add redirect to legacy --- pages/result/[pid]/[[...tid]].tsx | 29 +++++++++++++++++++++++++++++ pages/vote/[pid]/[[...tid]].tsx | 29 +++++++++++++++++++++++++++++ services/constants.ts | 3 +++ 3 files changed, 61 insertions(+) create mode 100644 pages/result/[pid]/[[...tid]].tsx create mode 100644 pages/vote/[pid]/[[...tid]].tsx diff --git a/pages/result/[pid]/[[...tid]].tsx b/pages/result/[pid]/[[...tid]].tsx new file mode 100644 index 0000000..fb8b467 --- /dev/null +++ b/pages/result/[pid]/[[...tid]].tsx @@ -0,0 +1,29 @@ +import { useRouter } from 'next/router'; +import { URL_LEGACY } from '@services/constants'; +import { useEffect } from 'react'; + +export async function getServerSideProps({ query, locale }) { + const { pid, tid: token } = query; + + return { + props: { + token: token || null, + pid, + }, + }; +} + +const Results = ({ token, pid }) => { + const router = useRouter(); + const url = token + ? new URL(`/result/${pid}/${token}`, URL_LEGACY) + : new URL(`/result/${pid}`, URL_LEGACY); + + useEffect(() => { + router.push(url.href); + }, []); + + return

Redirecting to {url.href}

; +}; + +export default Results; diff --git a/pages/vote/[pid]/[[...tid]].tsx b/pages/vote/[pid]/[[...tid]].tsx new file mode 100644 index 0000000..d342dc6 --- /dev/null +++ b/pages/vote/[pid]/[[...tid]].tsx @@ -0,0 +1,29 @@ +import { useRouter } from 'next/router'; +import { URL_LEGACY } from '@services/constants'; +import { useEffect } from 'react'; + +export async function getServerSideProps({ query, locale }) { + const { pid, tid: token } = query; + + return { + props: { + token: token || null, + pid, + }, + }; +} + +const Votes = ({ token, pid }) => { + const router = useRouter(); + const url = token + ? new URL(`/vote/${pid}/${token}`, URL_LEGACY) + : new URL(`/vote/${pid}`, URL_LEGACY); + + useEffect(() => { + router.push(url.href); + }, []); + + return

Redirecting to {url.href}

; +}; + +export default Votes; diff --git a/services/constants.ts b/services/constants.ts index 7c02860..bf54dc3 100644 --- a/services/constants.ts +++ b/services/constants.ts @@ -48,3 +48,6 @@ export const NEWS_LINK = export const URL_SERVER = process.env.NEXT_PUBLIC_BACKEND_URL || 'https://api.mieuxvoter.fr/'; + +export const URL_LEGACY = + process.env.NEXT_PUBLIC_URL_LEGACY || 'https://legacy.app.mieuxvoter.fr/';