Restructure application to use /home for authenticated pages

- Move authenticated home page from /[locale] to /[locale]/home
- Move login page from /[locale]/login to /[locale] (new landing page)
- Move all restricted pages (bill, location, year-month, print, account) under /[locale]/home
- Simplify middleware to protect all routes under /home instead of using publicPages array
- Update auth config: change signIn page from /login to /
- Update SignInButton callback URL to redirect to /home after login
- Update all internal links throughout the application to reflect new structure
- Update server action redirects in navigationActions.ts
- Public share routes (/share/*) remain unchanged

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Knee Cola
2025-11-25 21:49:01 +01:00
parent 02c68fee5b
commit b9f73e9a90
41 changed files with 158 additions and 160 deletions

View File

@@ -0,0 +1,20 @@
"use client";
import { FC } from 'react';
import LogoutIcon from "@mui/icons-material/Logout";
import { signOut } from 'next-auth/react';
import { useLocale, useTranslations } from 'next-intl';
import { Button } from '@/app/ui/button';
export const LogoutButton: FC = () => {
const t = useTranslations('account-page');
const locale = useLocale();
const handleLogout = () => {
signOut({ callbackUrl: `/${locale}/login` });
};
return (
<Button className='btn' onClick={handleLogout}><LogoutIcon /> {t('logout-button')}</Button>
)
}

View File

@@ -0,0 +1,28 @@
import { FC } from 'react';
import { Main } from '@/app/ui/Main';
import Link from 'next/link';
import SettingsIcon from "@mui/icons-material/Settings";
import AccountCircle from "@mui/icons-material/AccountCircle";
import { getTranslations, getLocale } from 'next-intl/server';
import { LogoutButton } from './LogoutButton';
const Page: FC = async () => {
const t = await getTranslations('account-page');
const locale = await getLocale();
return (
<Main>
<div className="flex flex-col items-center">
<div className="card card-compact card-bordered min-w-[20em] max-w-[90em] bg-base-100 shadow-s my-1">
<div className="card-body">
<h2 className="card-title"><AccountCircle /> {t('title')}</h2>
<Link href={`/${locale}/home/account/settings`} className='btn btn-neutral'><SettingsIcon /> {t('settings-button')}</Link>
<LogoutButton />
</div>
</div>
</div>
</Main>
);
};
export default Page;

View File

@@ -0,0 +1,33 @@
import { FC, Suspense } from 'react';
import { Main } from '@/app/ui/Main';
import { UserSettingsForm as UserSettingsForm, UserSettingsFormSkeleton } from '@/app/ui/UserSettingsForm';
import { getUserSettings } from '@/app/lib/actions/userSettingsActions';
const UserSettingsPage: FC = async () => {
const userSettings = await getUserSettings();
return (
<Main>
<div className="flex flex-col items-center">
<UserSettingsForm userSettings={userSettings} />
</div>
</Main>
);
};
const Page: FC = () => {
return (
<Suspense fallback={
<Main>
<div className="flex flex-col items-center">
<div className="h-8 w-48 skeleton mb-4"></div>
<UserSettingsFormSkeleton />
</div>
</Main>
}>
<UserSettingsPage />
</Suspense>
);
};
export default Page;

View File

@@ -0,0 +1,6 @@
import { NotFoundPage } from '@/app/ui/NotFoundPage';
const BillNotFound = () =>
<NotFoundPage title="404 Bill Not Found" description="Could not find the requested Bill." />;
export default BillNotFound;

View File

@@ -0,0 +1,19 @@
import { fetchLocationById } from '@/app/lib/actions/locationActions';
import { BillEditForm } from '@/app/ui/BillEditForm';
import { Main } from '@/app/ui/Main';
import { notFound } from 'next/navigation';
export default async function Page({ params:{ id:locationID } }: { params: { id:string } }) {
const location = await fetchLocationById(locationID);
if (!location) {
return(notFound());
}
return (
<Main>
<BillEditForm location={location} />
</Main>
);
}

View File

@@ -0,0 +1,6 @@
import { NotFoundPage } from '@/app/ui/NotFoundPage';
const BillNotFound = () =>
<NotFoundPage title="404 Bill Not Found" description="Could not find the requested Bill." />;
export default BillNotFound;

View File

@@ -0,0 +1,20 @@
import { notFound } from 'next/navigation';
import { BillDeleteForm } from '@/app/ui/BillDeleteForm';
import { fetchBillById } from '@/app/lib/actions/billActions';
import { Main } from '@/app/ui/Main';
export default async function Page({ params:{ id } }: { params: { id:string } }) {
const [locationID, billID] = id.split('-');
const [location, bill] = await fetchBillById(locationID, billID) ?? [];
if (!location || !bill) {
return(notFound());
}
return (
<Main>
<BillDeleteForm location={location} bill={bill} />
</Main>
);
}

View File

@@ -0,0 +1,6 @@
import { NotFoundPage } from '@/app/ui/NotFoundPage';
const BillNotFound = () =>
<NotFoundPage title="404 Bill Not Found" description="Could not find the requested Bill." />;
export default BillNotFound;

View File

@@ -0,0 +1,20 @@
import { fetchBillById } from '@/app/lib/actions/billActions';
import { BillEditForm } from '@/app/ui/BillEditForm';
import { Main } from '@/app/ui/Main';
import { notFound } from 'next/navigation';
export default async function Page({ params:{ id } }: { params: { id:string } }) {
const [locationID, billID] = id.split('-');
const [location, bill] = await fetchBillById(locationID, billID) ?? [];
if (!bill || !location) {
return(notFound());
}
return (
<Main>
<BillEditForm location={location} bill={bill} />
</Main>
);
}

View File

@@ -0,0 +1,8 @@
import { LocationEditForm } from '@/app/ui/LocationEditForm';
import { YearMonth } from '@/app/lib/db-types';
import { getUserSettings } from '@/app/lib/actions/userSettingsActions';
export default async function LocationAddPage({ yearMonth }: { yearMonth:YearMonth }) {
const userSettings = await getUserSettings();
return (<LocationEditForm yearMonth={yearMonth} userSettings={userSettings} />);
}

View File

@@ -0,0 +1,11 @@
import { parseYearMonth } from '@/app/lib/format';
import LocationAddPage from './LocationAddPage';
import { Main } from '@/app/ui/Main';
export default async function Page({ params:{ id } }: { params: { id:string } }) {
return (
<Main>
<LocationAddPage yearMonth={ parseYearMonth(id) } />
</Main>
);
}

View File

@@ -0,0 +1,14 @@
import { notFound } from 'next/navigation';
import { fetchLocationById } from '@/app/lib/actions/locationActions';
import { LocationDeleteForm } from '@/app/ui/LocationDeleteForm';
export const LocationDeletePage = async ({ locationId }: { locationId:string }) => {
const location = await fetchLocationById(locationId);
if (!location) {
return(notFound());
}
return (<LocationDeleteForm location={location} />);
}

View File

@@ -0,0 +1,6 @@
import { NotFoundPage } from '@/app/ui/NotFoundPage';
const BillingLocationNotFound = () =>
<NotFoundPage title="404 Billing Location Not Found" description="Could not find the requested Billing Location." />;
export default BillingLocationNotFound;

View File

@@ -0,0 +1,19 @@
import { notFound } from 'next/navigation';
import { fetchLocationById } from '@/app/lib/actions/locationActions';
import { LocationDeleteForm } from '@/app/ui/LocationDeleteForm';
import { Main } from '@/app/ui/Main';
export default async function Page({ params:{ id } }: { params: { id:string } }) {
const location = await fetchLocationById(id);
if (!location) {
return(notFound());
}
return (
<Main>
<LocationDeleteForm location={location} />
</Main>
);
}

View File

@@ -0,0 +1,19 @@
import { notFound } from 'next/navigation';
import { LocationEditForm } from '@/app/ui/LocationEditForm';
import { fetchLocationById } from '@/app/lib/actions/locationActions';
import { getUserSettings } from '@/app/lib/actions/userSettingsActions';
export default async function LocationEditPage({ locationId }: { locationId:string }) {
const location = await fetchLocationById(locationId);
if (!location) {
return(notFound());
}
const userSettings = await getUserSettings();
const result = <LocationEditForm location={location} userSettings={userSettings} />;
return (result);
}

View File

@@ -0,0 +1,6 @@
import { NotFoundPage } from '@/app/ui/NotFoundPage';
const BillingLocationNotFound = () =>
<NotFoundPage title="404 Location Not Found" description="Could not find the requested Location." />;
export default BillingLocationNotFound;

View File

@@ -0,0 +1,15 @@
import { Suspense } from 'react';
import LocationEditPage from './LocationEditPage';
import { Main } from '@/app/ui/Main';
import { LocationEditFormSkeleton } from '@/app/ui/LocationEditForm';
export default async function Page({ params:{ id } }: { params: { id:string } }) {
return (
<Main>
<Suspense fallback={<LocationEditFormSkeleton />}>
<LocationEditPage locationId={id} />
</Suspense>
</Main>
);
}

View File

@@ -0,0 +1,31 @@
import { FC, Suspense } from 'react';
import { Main } from '@/app/ui/Main';
import HomePage from '@/app/ui/HomePage';
import { MonthCardSkeleton } from '@/app/ui/MonthCardSkeleton';
export interface PageProps {
searchParams?: {
year?: string;
month?: string;
};
}
const HomePageSkeleton = () =>
<>
<MonthCardSkeleton checked={true} />
<MonthCardSkeleton />
<MonthCardSkeleton />
</>
const Page:FC<PageProps> = async ({ searchParams }) => {
return (
<Main>
<Suspense fallback={<HomePageSkeleton />}>
<HomePage searchParams={searchParams} />
</Suspense>
</Main>
);
}
export default Page;

View File

@@ -0,0 +1,6 @@
import { NotFoundPage } from '@/app/ui/NotFoundPage';
const PrintPageNotFound = () =>
<NotFoundPage title="404 Print Page Not Found" description="Could not find the requested print preview page." />;
export default PrintPageNotFound;

View File

@@ -0,0 +1,63 @@
import { fetchBarcodeDataForPrint } from '@/app/lib/actions/printActions';
import { notFound } from 'next/navigation';
import { PrintPreview } from '@/app/ui/PrintPreview';
import { getTranslations } from 'next-intl/server';
interface PrintPageProps {
params: {
year: string;
month: string;
locale: string;
};
}
export default async function PrintPage({ params }: PrintPageProps) {
const year = parseInt(params.year);
const month = parseInt(params.month);
// Validate year and month parameters
if (isNaN(year) || isNaN(month) || month < 1 || month > 12) {
notFound();
}
let printData;
try {
printData = await fetchBarcodeDataForPrint(year, month);
} catch (error) {
console.error('Error fetching print data:', error);
notFound();
}
// Get translations for the current locale
const t = await getTranslations("home-page.print-preview");
const yearMonth = `${year}-${month.toString().padStart(2, '0')}`;
const translations = {
title: t("title"),
barcodesFound: t("barcodes-found"),
barcodeSingular: t("barcode-singular"),
printButton: t("print-button"),
printFooter: t("print-footer", { date: new Date().toLocaleDateString() }),
tableHeaderIndex: t("table-header-index"),
tableHeaderBillInfo: t("table-header-bill-info"),
tableHeaderBarcode: t("table-header-barcode"),
emptyStateTitle: t("empty-state-title"),
emptyStateMessage: t("empty-state-message", { yearMonth })
};
// If no barcode data found, show empty state
if (!printData || printData.length === 0) {
return (
<div className="min-h-screen flex items-center justify-center">
<div className="text-center">
<h1 className="text-2xl font-bold mb-4">{translations.emptyStateTitle}</h1>
<p className="text-gray-600">
{translations.emptyStateMessage}
</p>
</div>
</div>
);
}
return <PrintPreview data={printData} year={year} month={month} translations={translations} />;
}

View File

@@ -0,0 +1,13 @@
import { addMonth } from '@/app/lib/actions/monthActions';
import { gotoHome } from '@/app/lib/actions/navigationActions';
import { parseYearMonth } from '@/app/lib/format';
export default async function Page({ params:{ id } }: { params: { id:string } }) {
const { year, month } = parseYearMonth(id);
await addMonth({ year, month });
await gotoHome({ year, month });
return null; // if we don't return anything, the client-side will not re-validate cache
}