Skip to content

Commit

Permalink
Setup landing page redirect.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasbicus committed Oct 21, 2024
1 parent 7c90443 commit a7649b9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
11 changes: 11 additions & 0 deletions app/actions.ts
Original file line number Diff line number Diff line change
@@ -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);
}
9 changes: 9 additions & 0 deletions app/lib/shared.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export enum Routes {
AddCards = '/add-cards',
MyCards = '/my-cards',
Settings = '/settings',
}

export enum Cookies {
LandingPage = 'LandingPage',
}
18 changes: 14 additions & 4 deletions app/page.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<main
className="hero min-h-screen"
Expand All @@ -18,9 +26,11 @@ export default function Home() {
that puts you in charge of your data and cards.
</p>
<div className="flex justify-center gap-4">
<Link className="btn btn-primary " href="/my-cards">
Get Started
</Link>
<form action={saveLandingPageCookieAndRedirect}>
<button className="btn btn-primary" type="submit">
Get Started
</button>
</form>
<button className="btn">About</button>
</div>
</div>
Expand Down

0 comments on commit a7649b9

Please sign in to comment.