From a7649b983aaba4c082a6e0104ce1eed61eb576d0 Mon Sep 17 00:00:00 2001 From: lukasbicus Date: Mon, 21 Oct 2024 11:36:32 +0200 Subject: [PATCH] Setup landing page redirect. --- app/actions.ts | 11 +++++++++++ app/lib/shared.ts | 9 +++++++++ app/page.tsx | 18 ++++++++++++++---- 3 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 app/actions.ts create mode 100644 app/lib/shared.ts diff --git a/app/actions.ts b/app/actions.ts new file mode 100644 index 0000000..89058c7 --- /dev/null +++ b/app/actions.ts @@ -0,0 +1,11 @@ +'use server'; + +import { Cookies, Routes } from '@/app/lib/shared'; +import { cookies } from 'next/headers'; +import { redirect } from 'next/navigation'; + +export async function saveLandingPageCookieAndRedirect() { + const route = Routes.AddCards; + cookies().set(Cookies.LandingPage, route); + redirect(route); +} diff --git a/app/lib/shared.ts b/app/lib/shared.ts new file mode 100644 index 0000000..b8941ea --- /dev/null +++ b/app/lib/shared.ts @@ -0,0 +1,9 @@ +export enum Routes { + AddCards = '/add-cards', + MyCards = '/my-cards', + Settings = '/settings', +} + +export enum Cookies { + LandingPage = 'LandingPage', +} diff --git a/app/page.tsx b/app/page.tsx index e7254f9..055f04e 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,6 +1,14 @@ -import Link from 'next/link'; +import { saveLandingPageCookieAndRedirect } from '@/app/actions'; +import { Cookies } from '@/app/lib/shared'; +import { cookies } from 'next/headers'; +import { redirect } from 'next/navigation'; export default function Home() { + const cookieStore = cookies(); + const landingPage = cookieStore.get(Cookies.LandingPage)?.value; + if (landingPage) { + redirect(landingPage); + } return (
- - Get Started - +
+ +