Improve admin save UX and portfolio navigation
CI / quality (push) Waiting to run

This commit is contained in:
MOH
2026-03-07 19:20:58 +01:00
parent 3d1976a7a5
commit ee21e8b823
19 changed files with 652 additions and 424 deletions
+39
View File
@@ -0,0 +1,39 @@
"use server";
import { revalidatePath } from "next/cache";
import { redirect } from "next/navigation";
import { routing } from "@/i18n/routing";
import { clearAdminSessionCookie, isAdminAuthenticated } from "@/lib/admin-auth";
import { getLocalizedPath } from "@/lib/locale";
import { setMaintenanceMode } from "@/lib/app-config";
function ensureAdmin() {
if (!isAdminAuthenticated()) {
clearAdminSessionCookie();
redirect("/root");
}
}
export async function updateMaintenanceModeAction(formData: FormData) {
ensureAdmin();
const nextValue = formData.get("enabled") === "true";
const redirectPath = String(formData.get("redirectPath") ?? "/root");
const redirectUrl = new URL(redirectPath, "http://localhost");
redirectUrl.searchParams.set("__saved", "maintenance");
await setMaintenanceMode(nextValue);
revalidatePath("/", "layout");
revalidatePath("/coming-soon");
revalidatePath("/root");
revalidatePath("/root/maintenance");
revalidatePath(redirectPath);
for (const appLocale of routing.locales) {
revalidatePath(getLocalizedPath(appLocale), "layout");
revalidatePath(getLocalizedPath(appLocale, "/coming-soon"));
}
redirect(`${redirectUrl.pathname}${redirectUrl.search}`);
}
+7 -59
View File
@@ -1,18 +1,12 @@
import { Power } from "lucide-react";
import { revalidatePath } from "next/cache";
import { redirect } from "next/navigation"; import { redirect } from "next/navigation";
import { FormSaveButton } from "@/components/root/form-save-button";
import { MotionFade } from "@/components/motion-fade"; import { MotionFade } from "@/components/motion-fade";
import { RootDashboardShell } from "@/components/root/root-dashboard-shell"; import { RootDashboardShell } from "@/components/root/root-dashboard-shell";
import { routing } from "@/i18n/routing";
import { getLocalizedPath } from "@/lib/locale";
import { clearAdminSessionCookie, isAdminAuthenticated } from "@/lib/admin-auth"; import { clearAdminSessionCookie, isAdminAuthenticated } from "@/lib/admin-auth";
import { getMaintenanceMode, setMaintenanceMode } from "@/lib/app-config"; import { getMaintenanceMode } from "@/lib/app-config";
import { AppCard } from "@/components/ui/app-card"; import { AppCard } from "@/components/ui/app-card";
import { Badge } from "@/components/ui/badge"; import { Badge } from "@/components/ui/badge";
import { CardContent } from "@/components/ui/card"; import { CardContent } from "@/components/ui/card";
import { Label } from "@/components/ui/label";
export const dynamic = "force-dynamic"; export const dynamic = "force-dynamic";
@@ -28,8 +22,7 @@ const copy = {
maintenanceText: "Wenn aktiv, werden alle Seiten auf die Coming Soon Seite weitergeleitet.", maintenanceText: "Wenn aktiv, werden alle Seiten auf die Coming Soon Seite weitergeleitet.",
maintenanceOn: "Aktiv", maintenanceOn: "Aktiv",
maintenanceOff: "Inaktiv", maintenanceOff: "Inaktiv",
selectLabel: "Status", selectHint: "Aenderung erfolgt jetzt direkt ueber den Schalter in der Sidebar und wird mit dem Save Button oben gespeichert.",
selectHint: "Aenderung wird erst nach Speichern uebernommen.",
logout: "Ausloggen", logout: "Ausloggen",
backToSite: "Zur Website", backToSite: "Zur Website",
}; };
@@ -42,7 +35,6 @@ export default async function RootMaintenancePage() {
} }
const maintenanceEnabled = await getMaintenanceMode(); const maintenanceEnabled = await getMaintenanceMode();
async function logoutAction() { async function logoutAction() {
"use server"; "use server";
@@ -50,29 +42,6 @@ export default async function RootMaintenancePage() {
redirect("/root"); redirect("/root");
} }
async function updateMaintenanceMode(formData: FormData) {
"use server";
if (!isAdminAuthenticated()) {
redirect("/root");
}
const nextValue = formData.get("enabled") === "true";
await setMaintenanceMode(nextValue);
revalidatePath("/", "layout");
revalidatePath("/coming-soon");
revalidatePath("/root");
revalidatePath("/root/maintenance");
for (const appLocale of routing.locales) {
revalidatePath(getLocalizedPath(appLocale), "layout");
revalidatePath(getLocalizedPath(appLocale, "/coming-soon"));
}
redirect("/root/maintenance");
}
return ( return (
<RootDashboardShell <RootDashboardShell
copy={copy} copy={copy}
@@ -80,38 +49,17 @@ export default async function RootMaintenancePage() {
logoutAction={logoutAction} logoutAction={logoutAction}
headerTitle={copy.title} headerTitle={copy.title}
headerDescription={copy.subtitle} headerDescription={copy.subtitle}
headerActions={
<>
<Badge variant={maintenanceEnabled ? "warning" : "success"}>
{maintenanceEnabled ? copy.maintenanceOn : copy.maintenanceOff}
</Badge>
<FormSaveButton formId="maintenance-form" />
</>
}
> >
<MotionFade delay={0.1}> <MotionFade delay={0.1}>
<AppCard> <AppCard>
<CardContent className="space-y-4 p-6"> <CardContent className="space-y-4 p-6">
<p className="text-sm text-muted-foreground">{copy.maintenanceText}</p> <p className="text-sm text-muted-foreground">{copy.maintenanceText}</p>
<form id="maintenance-form" action={updateMaintenanceMode} className="space-y-3"> <div className="flex flex-wrap items-center gap-3">
<div className="space-y-2"> <Badge variant={maintenanceEnabled ? "warning" : "success"}>
<Label htmlFor="enabled">{copy.selectLabel}</Label>
<select
id="enabled"
name="enabled"
defaultValue={maintenanceEnabled ? "true" : "false"}
className="flex h-11 w-full rounded-pill border border-border bg-background px-4 text-sm text-foreground shadow-sm"
>
<option value="false">{copy.maintenanceOff}</option>
<option value="true">{copy.maintenanceOn}</option>
</select>
<p className="text-xs text-muted-foreground">{copy.selectHint}</p>
</div>
<div className="inline-flex items-center gap-2 rounded-nested border border-border bg-surface-1 px-3 py-2 text-sm text-foreground">
<Power className="h-4 w-4 text-brand-primary" />
{maintenanceEnabled ? copy.maintenanceOn : copy.maintenanceOff} {maintenanceEnabled ? copy.maintenanceOn : copy.maintenanceOff}
</div> </Badge>
</form> <p className="text-xs text-muted-foreground">{copy.selectHint}</p>
</div>
</CardContent> </CardContent>
</AppCard> </AppCard>
</MotionFade> </MotionFade>
+3 -6
View File
@@ -5,6 +5,7 @@ import Link from "next/link";
import { redirect } from "next/navigation"; import { redirect } from "next/navigation";
import { MotionFade } from "@/components/motion-fade"; import { MotionFade } from "@/components/motion-fade";
import { FlashMessage } from "@/components/root/flash-message";
import { RootDashboardShell } from "@/components/root/root-dashboard-shell"; import { RootDashboardShell } from "@/components/root/root-dashboard-shell";
import { AppCard } from "@/components/ui/app-card"; import { AppCard } from "@/components/ui/app-card";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
@@ -74,17 +75,13 @@ export default async function RootMediaPage({ searchParams }: RootMediaPageProps
<div className="space-y-6"> <div className="space-y-6">
{searchParams?.success ? ( {searchParams?.success ? (
<MotionFade delay={0.1}> <MotionFade delay={0.1}>
<p className="rounded-nested border border-status-success/30 bg-status-success/10 px-4 py-3 text-sm text-status-success"> <FlashMessage type="success" message={searchParams.success} />
{searchParams.success}
</p>
</MotionFade> </MotionFade>
) : null} ) : null}
{searchParams?.error ? ( {searchParams?.error ? (
<MotionFade delay={0.12}> <MotionFade delay={0.12}>
<p className="rounded-nested border border-destructive/30 bg-destructive/10 px-4 py-3 text-sm text-destructive"> <FlashMessage type="error" message={searchParams.error} />
{searchParams.error}
</p>
</MotionFade> </MotionFade>
) : null} ) : null}
-7
View File
@@ -277,13 +277,6 @@ export default async function RootPage({ searchParams }: RootPageProps) {
logoutAction={logoutAction} logoutAction={logoutAction}
headerTitle={copy.title} headerTitle={copy.title}
headerDescription={copy.subtitle} headerDescription={copy.subtitle}
sidebarTopContent={
maintenanceEnabled ? (
<p className="px-1 text-xs font-medium text-destructive">
{copy.maintenanceVisitorsShort}
</p>
) : null
}
> >
<div className="space-y-6"> <div className="space-y-6">
<section className="grid gap-4 md:grid-cols-2 xl:grid-cols-4"> <section className="grid gap-4 md:grid-cols-2 xl:grid-cols-4">
+3 -3
View File
@@ -574,7 +574,7 @@ export async function deleteProjectAction(formData: FormData) {
}); });
if (!project) { if (!project) {
redirect(withMessage("/root/portfolio/projects", "error", "Project not found.")); redirect(withMessage("/root/portfolio", "error", "Project not found."));
} }
await prisma.portfolioProject.delete({ await prisma.portfolioProject.delete({
@@ -591,12 +591,12 @@ export async function deleteProjectAction(formData: FormData) {
revalidatePath(getLocalizedPath(locale, `/portfolio/${project.slug}`)); revalidatePath(getLocalizedPath(locale, `/portfolio/${project.slug}`));
} }
redirect(withMessage("/root/portfolio/projects", "success", "Project deleted.")); redirect(withMessage("/root/portfolio", "success", "Project deleted."));
} catch (error) { } catch (error) {
if (isRedirectError(error)) { if (isRedirectError(error)) {
throw error; throw error;
} }
redirect(withMessage("/root/portfolio/projects", "error", "Unable to delete project.")); redirect(withMessage("/root/portfolio", "error", "Unable to delete project."));
} }
} }
+16 -8
View File
@@ -1,6 +1,7 @@
import { redirect } from "next/navigation"; import { redirect } from "next/navigation";
import { MotionFade } from "@/components/motion-fade"; import { MotionFade } from "@/components/motion-fade";
import { FlashMessage } from "@/components/root/flash-message";
import { PortfolioSubnav } from "@/components/root/portfolio-subnav"; import { PortfolioSubnav } from "@/components/root/portfolio-subnav";
import { RootDashboardShell } from "@/components/root/root-dashboard-shell"; import { RootDashboardShell } from "@/components/root/root-dashboard-shell";
import { AppCard } from "@/components/ui/app-card"; import { AppCard } from "@/components/ui/app-card";
@@ -74,22 +75,19 @@ export default async function RootPortfolioCategoriesPage({
logoutAction={logoutAction} logoutAction={logoutAction}
headerTitle={copy.title} headerTitle={copy.title}
headerDescription={copy.subtitle} headerDescription={copy.subtitle}
saveFormSelector="[data-topbar-save-form='category']"
toolbar={<PortfolioSubnav active="categories" />} toolbar={<PortfolioSubnav active="categories" />}
> >
<div className="space-y-6"> <div className="space-y-6">
{searchParams?.success ? ( {searchParams?.success ? (
<MotionFade delay={0.1}> <MotionFade delay={0.1}>
<p className="rounded-nested border border-status-success/30 bg-status-success/10 px-4 py-3 text-sm text-status-success"> <FlashMessage type="success" message={searchParams.success} />
{searchParams.success}
</p>
</MotionFade> </MotionFade>
) : null} ) : null}
{searchParams?.error ? ( {searchParams?.error ? (
<MotionFade delay={0.12}> <MotionFade delay={0.12}>
<p className="rounded-nested border border-destructive/30 bg-destructive/10 px-4 py-3 text-sm text-destructive"> <FlashMessage type="error" message={searchParams.error} />
{searchParams.error}
</p>
</MotionFade> </MotionFade>
) : null} ) : null}
@@ -100,7 +98,12 @@ export default async function RootPortfolioCategoriesPage({
<CardDescription>Eine Kategorie wird genau einem oder mehreren Projekten zugeordnet.</CardDescription> <CardDescription>Eine Kategorie wird genau einem oder mehreren Projekten zugeordnet.</CardDescription>
</CardHeader> </CardHeader>
<CardContent> <CardContent>
<form action={upsertCategoryAction} className="grid gap-4 md:grid-cols-2"> <form
id="portfolio-category-create-form"
action={upsertCategoryAction}
className="grid gap-4 md:grid-cols-2"
data-topbar-save-form="category"
>
<input type="hidden" name="redirectPath" value="/root/portfolio/categories" /> <input type="hidden" name="redirectPath" value="/root/portfolio/categories" />
<div className="space-y-2"> <div className="space-y-2">
<Label htmlFor="create-slug">Slug</Label> <Label htmlFor="create-slug">Slug</Label>
@@ -162,7 +165,12 @@ export default async function RootPortfolioCategoriesPage({
<MotionFade key={category.id} delay={0.18 + index * 0.03}> <MotionFade key={category.id} delay={0.18 + index * 0.03}>
<AppCard> <AppCard>
<CardContent className="p-6"> <CardContent className="p-6">
<form action={upsertCategoryAction} className="grid gap-4 md:grid-cols-2"> <form
id={`portfolio-category-form-${category.id}`}
action={upsertCategoryAction}
className="grid gap-4 md:grid-cols-2"
data-topbar-save-form="category"
>
<input type="hidden" name="id" value={category.id} /> <input type="hidden" name="id" value={category.id} />
<input type="hidden" name="redirectPath" value="/root/portfolio/categories" /> <input type="hidden" name="redirectPath" value="/root/portfolio/categories" />
+151 -56
View File
@@ -1,18 +1,20 @@
import { Boxes, FolderKanban, ImageIcon, Layers3, Plus, Tags } from "lucide-react"; import { Boxes, ExternalLink, FolderKanban, Layers3, Plus, Tags } from "lucide-react";
import Link from "next/link"; import Link from "next/link";
import { redirect } from "next/navigation"; import { redirect } from "next/navigation";
import { PortfolioSubnav } from "@/components/root/portfolio-subnav";
import { RootDashboardShell } from "@/components/root/root-dashboard-shell"; import { RootDashboardShell } from "@/components/root/root-dashboard-shell";
import { MotionFade } from "@/components/motion-fade"; import { MotionFade } from "@/components/motion-fade";
import { FlashMessage } from "@/components/root/flash-message";
import { AppCard } from "@/components/ui/app-card"; import { AppCard } from "@/components/ui/app-card";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
import { CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { clearAdminSessionCookie, isAdminAuthenticated } from "@/lib/admin-auth"; import { clearAdminSessionCookie, isAdminAuthenticated } from "@/lib/admin-auth";
import { import {
getAdminPortfolioCategories, getAdminPortfolioCategories,
getAdminPortfolioProjects, getAdminPortfolioProjects,
getLocalizedValue,
} from "@/lib/portfolio"; } from "@/lib/portfolio";
import { getLocalizedPath } from "@/lib/locale";
export const dynamic = "force-dynamic"; export const dynamic = "force-dynamic";
@@ -29,14 +31,32 @@ const copy = {
totalCategories: "Kategorien", totalCategories: "Kategorien",
totalProjects: "Projekte", totalProjects: "Projekte",
publishedProjects: "Veroeffentlicht", publishedProjects: "Veroeffentlicht",
categoriesAction: "Kategorien verwalten",
projectsAction: "Projekte verwalten",
newProject: "Neues Projekt", newProject: "Neues Projekt",
newCategory: "Neue Kategorie", newCategory: "Neue Kategorie",
media: "Media", category: "Kategorie",
all: "Alle",
status: "Status",
draft: "Entwurf",
published: "Veroeffentlicht",
filter: "Filtern",
sort: "Sortierung",
previewSet: "Preview Link gesetzt",
previewMissing: "Kein Preview Link",
editProject: "Projekt bearbeiten",
openProject: "Projekt ansehen",
empty: "Keine Projekte fuer die aktuellen Filter gefunden.",
}; };
export default async function RootPortfolioPage() { type RootPortfolioPageProps = {
searchParams?: {
category?: string;
status?: "all" | "draft" | "published";
success?: string;
error?: string;
};
};
export default async function RootPortfolioPage({ searchParams }: RootPortfolioPageProps) {
if (!isAdminAuthenticated()) { if (!isAdminAuthenticated()) {
redirect("/root"); redirect("/root");
} }
@@ -48,9 +68,15 @@ export default async function RootPortfolioPage() {
redirect("/root"); redirect("/root");
} }
const selectedStatus = searchParams?.status === "draft" || searchParams?.status === "published"
? searchParams.status
: "all";
const [categories, projects] = await Promise.all([ const [categories, projects] = await Promise.all([
getAdminPortfolioCategories(), getAdminPortfolioCategories(),
getAdminPortfolioProjects(), getAdminPortfolioProjects({
categoryId: searchParams?.category || undefined,
status: selectedStatus,
}),
]); ]);
const publishedProjects = projects.filter((project) => project.isPublished).length; const publishedProjects = projects.filter((project) => project.isPublished).length;
@@ -62,7 +88,6 @@ export default async function RootPortfolioPage() {
logoutAction={logoutAction} logoutAction={logoutAction}
headerTitle={copy.title} headerTitle={copy.title}
headerDescription={copy.subtitle} headerDescription={copy.subtitle}
toolbar={<PortfolioSubnav active="overview" />}
headerActions={ headerActions={
<div className="flex flex-wrap gap-3"> <div className="flex flex-wrap gap-3">
<Button asChild> <Button asChild>
@@ -81,6 +106,18 @@ export default async function RootPortfolioPage() {
} }
> >
<div className="space-y-6"> <div className="space-y-6">
{searchParams?.success ? (
<MotionFade delay={0.08}>
<FlashMessage type="success" message={searchParams.success} />
</MotionFade>
) : null}
{searchParams?.error ? (
<MotionFade delay={0.1}>
<FlashMessage type="error" message={searchParams.error} />
</MotionFade>
) : null}
<section className="grid gap-4 md:grid-cols-3"> <section className="grid gap-4 md:grid-cols-3">
{[ {[
{ {
@@ -119,55 +156,113 @@ export default async function RootPortfolioPage() {
})} })}
</section> </section>
<section className="grid gap-4 lg:grid-cols-3"> <MotionFade delay={0.15}>
<MotionFade delay={0.18}> <AppCard>
<AppCard> <CardContent className="p-6">
<CardHeader> <form className="grid gap-4 md:grid-cols-3">
<CardTitle>{copy.totalCategories}</CardTitle> <div className="space-y-2">
<CardDescription>Sortieren, aktivieren und neue Portfolio Gruppen anlegen.</CardDescription> <label htmlFor="category" className="text-sm font-medium text-foreground">
</CardHeader> {copy.category}
<CardContent> </label>
<Button asChild variant="outline"> <select
<Link href="/root/portfolio/categories">{copy.categoriesAction}</Link> id="category"
</Button> name="category"
</CardContent> defaultValue={searchParams?.category ?? ""}
</AppCard> className="flex h-11 w-full rounded-pill border border-border bg-background px-4 text-sm text-foreground shadow-sm"
</MotionFade> >
<option value="">{copy.all}</option>
{categories.map((category) => (
<option key={category.id} value={category.id}>
{category.name.de}
</option>
))}
</select>
</div>
<MotionFade delay={0.22}> <div className="space-y-2">
<AppCard> <label htmlFor="status" className="text-sm font-medium text-foreground">
<CardHeader> {copy.status}
<CardTitle>{copy.totalProjects}</CardTitle> </label>
<CardDescription>Entwuerfe, veroeffentlichte Projekte und flexible Abschnitte pflegen.</CardDescription> <select
</CardHeader> id="status"
<CardContent className="flex gap-3"> name="status"
<Button asChild variant="outline"> defaultValue={selectedStatus}
<Link href="/root/portfolio/projects">{copy.projectsAction}</Link> className="flex h-11 w-full rounded-pill border border-border bg-background px-4 text-sm text-foreground shadow-sm"
</Button> >
<Button asChild> <option value="all">{copy.all}</option>
<Link href="/root/portfolio/projects/new">{copy.newProject}</Link> <option value="draft">{copy.draft}</option>
</Button> <option value="published">{copy.published}</option>
</CardContent> </select>
</AppCard> </div>
</MotionFade>
<MotionFade delay={0.26}> <div className="flex items-end">
<AppCard> <Button type="submit" variant="outline">
<CardHeader> {copy.filter}
<CardTitle>{copy.media}</CardTitle> </Button>
<CardDescription>Alle Cover und Projektdateien an einem Ort pruefen.</CardDescription> </div>
</CardHeader> </form>
<CardContent> </CardContent>
<Button asChild variant="outline"> </AppCard>
<Link href="/root/media"> </MotionFade>
<ImageIcon className="h-4 w-4" />
{copy.media} <div className="grid gap-4">
</Link> {projects.map((project, index) => (
</Button> <MotionFade key={project.id} delay={0.18 + index * 0.03}>
</CardContent> <AppCard interactive>
</AppCard> <CardHeader className="flex flex-row items-center justify-between gap-4">
</MotionFade> <div>
</section> <CardTitle>{getLocalizedValue(project.title, "de")}</CardTitle>
<p className="mt-1 text-sm text-muted-foreground">
{project.category.name.de}
</p>
</div>
<div className="flex flex-wrap items-center gap-2 text-xs text-muted-foreground">
<span className="rounded-pill border border-border px-3 py-1">
{project.isPublished ? copy.published : copy.draft}
</span>
<span className="rounded-pill border border-border px-3 py-1">
{project.projectYear}
</span>
<span className="rounded-pill border border-border px-3 py-1">
{copy.sort} {project.sortOrder}
</span>
</div>
</CardHeader>
<CardContent className="flex flex-wrap items-center justify-between gap-4">
<div className="space-y-1 text-sm text-muted-foreground">
<p>{project.slug}</p>
<p>{project.previewUrl ? copy.previewSet : copy.previewMissing}</p>
</div>
<div className="flex flex-wrap gap-3">
<Button asChild variant="outline">
<Link
href={getLocalizedPath("de", `/portfolio/${project.slug}`)}
target="_blank"
rel="noreferrer"
>
<ExternalLink className="h-4 w-4" />
{copy.openProject}
</Link>
</Button>
<Button asChild>
<Link href={`/root/portfolio/projects/${project.id}`}>{copy.editProject}</Link>
</Button>
</div>
</CardContent>
</AppCard>
</MotionFade>
))}
{projects.length === 0 ? (
<MotionFade delay={0.18}>
<AppCard>
<CardContent className="p-6 text-sm text-muted-foreground">
{copy.empty}
</CardContent>
</AppCard>
</MotionFade>
) : null}
</div>
</div> </div>
</RootDashboardShell> </RootDashboardShell>
); );
+6 -9
View File
@@ -1,8 +1,8 @@
import { redirect } from "next/navigation"; import { redirect } from "next/navigation";
import { MotionFade } from "@/components/motion-fade"; import { MotionFade } from "@/components/motion-fade";
import { FlashMessage } from "@/components/root/flash-message";
import { PortfolioProjectForm } from "@/components/root/portfolio-project-form"; import { PortfolioProjectForm } from "@/components/root/portfolio-project-form";
import { PortfolioSubnav } from "@/components/root/portfolio-subnav";
import { RootDashboardShell } from "@/components/root/root-dashboard-shell"; import { RootDashboardShell } from "@/components/root/root-dashboard-shell";
import { AppCard } from "@/components/ui/app-card"; import { AppCard } from "@/components/ui/app-card";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
@@ -67,7 +67,7 @@ export default async function RootPortfolioProjectPage({
]); ]);
if (!project) { if (!project) {
redirect("/root/portfolio/projects?error=Project+not+found."); redirect("/root/portfolio?error=Project+not+found.");
} }
return ( return (
@@ -78,22 +78,18 @@ export default async function RootPortfolioProjectPage({
logoutAction={logoutAction} logoutAction={logoutAction}
headerTitle={copy.title} headerTitle={copy.title}
headerDescription={copy.subtitle} headerDescription={copy.subtitle}
toolbar={<PortfolioSubnav active="projects" />} saveFormId="portfolio-project-form"
> >
<div className="space-y-6"> <div className="space-y-6">
{searchParams?.success ? ( {searchParams?.success ? (
<MotionFade delay={0.1}> <MotionFade delay={0.1}>
<p className="rounded-nested border border-status-success/30 bg-status-success/10 px-4 py-3 text-sm text-status-success"> <FlashMessage type="success" message={searchParams.success} />
{searchParams.success}
</p>
</MotionFade> </MotionFade>
) : null} ) : null}
{searchParams?.error ? ( {searchParams?.error ? (
<MotionFade delay={0.12}> <MotionFade delay={0.12}>
<p className="rounded-nested border border-destructive/30 bg-destructive/10 px-4 py-3 text-sm text-destructive"> <FlashMessage type="error" message={searchParams.error} />
{searchParams.error}
</p>
</MotionFade> </MotionFade>
) : null} ) : null}
@@ -103,6 +99,7 @@ export default async function RootPortfolioProjectPage({
categories={categories} categories={categories}
mediaOptions={mediaOptions} mediaOptions={mediaOptions}
project={project} project={project}
formId="portfolio-project-form"
redirectPath={`/root/portfolio/projects/${project.id}`} redirectPath={`/root/portfolio/projects/${project.id}`}
submitLabel={copy.saveProject} submitLabel={copy.saveProject}
/> />
+4 -5
View File
@@ -1,8 +1,8 @@
import { redirect } from "next/navigation"; import { redirect } from "next/navigation";
import { MotionFade } from "@/components/motion-fade"; import { MotionFade } from "@/components/motion-fade";
import { FlashMessage } from "@/components/root/flash-message";
import { PortfolioProjectForm } from "@/components/root/portfolio-project-form"; import { PortfolioProjectForm } from "@/components/root/portfolio-project-form";
import { PortfolioSubnav } from "@/components/root/portfolio-subnav";
import { RootDashboardShell } from "@/components/root/root-dashboard-shell"; import { RootDashboardShell } from "@/components/root/root-dashboard-shell";
import { clearAdminSessionCookie, isAdminAuthenticated } from "@/lib/admin-auth"; import { clearAdminSessionCookie, isAdminAuthenticated } from "@/lib/admin-auth";
import { getMediaOptions } from "@/lib/media"; import { getMediaOptions } from "@/lib/media";
@@ -58,14 +58,12 @@ export default async function RootNewPortfolioProjectPage({
logoutAction={logoutAction} logoutAction={logoutAction}
headerTitle={copy.title} headerTitle={copy.title}
headerDescription={copy.subtitle} headerDescription={copy.subtitle}
toolbar={<PortfolioSubnav active="projects" />} saveFormId="portfolio-project-form"
> >
<div className="space-y-6"> <div className="space-y-6">
{searchParams?.error ? ( {searchParams?.error ? (
<MotionFade delay={0.1}> <MotionFade delay={0.1}>
<p className="rounded-nested border border-destructive/30 bg-destructive/10 px-4 py-3 text-sm text-destructive"> <FlashMessage type="error" message={searchParams.error} />
{searchParams.error}
</p>
</MotionFade> </MotionFade>
) : null} ) : null}
@@ -74,6 +72,7 @@ export default async function RootNewPortfolioProjectPage({
action={saveProjectAction} action={saveProjectAction}
categories={categories} categories={categories}
mediaOptions={mediaOptions} mediaOptions={mediaOptions}
formId="portfolio-project-form"
redirectPath="/root/portfolio/projects/new" redirectPath="/root/portfolio/projects/new"
submitLabel="Projekt anlegen" submitLabel="Projekt anlegen"
/> />
+13 -191
View File
@@ -1,47 +1,7 @@
import { Plus } from "lucide-react";
import Link from "next/link";
import { redirect } from "next/navigation"; import { redirect } from "next/navigation";
import { MotionFade } from "@/components/motion-fade";
import { PortfolioSubnav } from "@/components/root/portfolio-subnav";
import { RootDashboardShell } from "@/components/root/root-dashboard-shell";
import { AppCard } from "@/components/ui/app-card";
import { Button } from "@/components/ui/button";
import { CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { clearAdminSessionCookie, isAdminAuthenticated } from "@/lib/admin-auth";
import {
getAdminPortfolioCategories,
getAdminPortfolioProjects,
getLocalizedValue,
} from "@/lib/portfolio";
export const dynamic = "force-dynamic"; export const dynamic = "force-dynamic";
const copy = {
title: "Portfolio Projekte",
subtitle: "Alle Projekte mit Status, Kategorie und Reihenfolge.",
overview: "Uebersicht",
maintenance: "Wartungsmodus",
uiKit: "UI Kit",
media: "Media",
siteSettings: "SEO",
portfolio: "Portfolio",
logout: "Ausloggen",
backToSite: "Zur Website",
newProject: "Neues Projekt",
category: "Kategorie",
all: "Alle",
status: "Status",
draft: "Entwurf",
published: "Veroeffentlicht",
filter: "Filtern",
sort: "Sortierung",
previewSet: "Preview Link gesetzt",
previewMissing: "Kein Preview Link",
editProject: "Projekt bearbeiten",
empty: "Keine Projekte fuer die aktuellen Filter gefunden.",
};
type RootPortfolioProjectsPageProps = { type RootPortfolioProjectsPageProps = {
searchParams?: { searchParams?: {
category?: string; category?: string;
@@ -54,161 +14,23 @@ type RootPortfolioProjectsPageProps = {
export default async function RootPortfolioProjectsPage({ export default async function RootPortfolioProjectsPage({
searchParams, searchParams,
}: RootPortfolioProjectsPageProps) { }: RootPortfolioProjectsPageProps) {
if (!isAdminAuthenticated()) { const params = new URLSearchParams();
redirect("/root");
if (searchParams?.category) {
params.set("category", searchParams.category);
} }
async function logoutAction() { if (searchParams?.status) {
"use server"; params.set("status", searchParams.status);
clearAdminSessionCookie();
redirect("/root");
} }
const selectedStatus = searchParams?.status === "draft" || searchParams?.status === "published" if (searchParams?.success) {
? searchParams.status params.set("success", searchParams.success);
: "all"; }
const [categories, projects] = await Promise.all([
getAdminPortfolioCategories(),
getAdminPortfolioProjects({
categoryId: searchParams?.category || undefined,
status: selectedStatus,
}),
]);
return ( if (searchParams?.error) {
<RootDashboardShell params.set("error", searchParams.error);
copy={copy} }
active="portfolio"
portfolioChild="projects"
logoutAction={logoutAction}
headerTitle={copy.title}
headerDescription={copy.subtitle}
toolbar={<PortfolioSubnav active="projects" />}
headerActions={
<MotionFade delay={0.04}>
<Button asChild>
<Link href="/root/portfolio/projects/new">
<Plus className="h-4 w-4" />
{copy.newProject}
</Link>
</Button>
</MotionFade>
}
>
<div className="space-y-6">
{searchParams?.success ? (
<MotionFade delay={0.1}>
<p className="rounded-nested border border-status-success/30 bg-status-success/10 px-4 py-3 text-sm text-status-success">
{searchParams.success}
</p>
</MotionFade>
) : null}
{searchParams?.error ? ( redirect(params.toString() ? `/root/portfolio?${params.toString()}` : "/root/portfolio");
<MotionFade delay={0.12}>
<p className="rounded-nested border border-destructive/30 bg-destructive/10 px-4 py-3 text-sm text-destructive">
{searchParams.error}
</p>
</MotionFade>
) : null}
<MotionFade delay={0.15}>
<AppCard>
<CardContent className="p-6">
<form className="grid gap-4 md:grid-cols-3">
<div className="space-y-2">
<label htmlFor="category" className="text-sm font-medium text-foreground">
{copy.category}
</label>
<select
id="category"
name="category"
defaultValue={searchParams?.category ?? ""}
className="flex h-11 w-full rounded-pill border border-border bg-background px-4 text-sm text-foreground shadow-sm"
>
<option value="">{copy.all}</option>
{categories.map((category) => (
<option key={category.id} value={category.id}>
{category.name.de}
</option>
))}
</select>
</div>
<div className="space-y-2">
<label htmlFor="status" className="text-sm font-medium text-foreground">
{copy.status}
</label>
<select
id="status"
name="status"
defaultValue={selectedStatus}
className="flex h-11 w-full rounded-pill border border-border bg-background px-4 text-sm text-foreground shadow-sm"
>
<option value="all">{copy.all}</option>
<option value="draft">{copy.draft}</option>
<option value="published">{copy.published}</option>
</select>
</div>
<div className="flex items-end">
<Button type="submit" variant="outline">
{copy.filter}
</Button>
</div>
</form>
</CardContent>
</AppCard>
</MotionFade>
<div className="grid gap-4">
{projects.map((project, index) => (
<MotionFade key={project.id} delay={0.18 + index * 0.03}>
<AppCard interactive>
<CardHeader className="flex flex-row items-center justify-between gap-4">
<div>
<CardTitle>{getLocalizedValue(project.title, "de")}</CardTitle>
<p className="mt-1 text-sm text-muted-foreground">
{project.category.name.de}
</p>
</div>
<div className="flex flex-wrap items-center gap-2 text-xs text-muted-foreground">
<span className="rounded-pill border border-border px-3 py-1">
{project.isPublished ? copy.published : copy.draft}
</span>
<span className="rounded-pill border border-border px-3 py-1">
{project.projectYear}
</span>
<span className="rounded-pill border border-border px-3 py-1">
{copy.sort} {project.sortOrder}
</span>
</div>
</CardHeader>
<CardContent className="flex flex-wrap items-center justify-between gap-4">
<div className="space-y-1 text-sm text-muted-foreground">
<p>{project.slug}</p>
<p>{project.previewUrl ? copy.previewSet : copy.previewMissing}</p>
</div>
<Button asChild>
<Link href={`/root/portfolio/projects/${project.id}`}>{copy.editProject}</Link>
</Button>
</CardContent>
</AppCard>
</MotionFade>
))}
{projects.length === 0 ? (
<MotionFade delay={0.18}>
<AppCard>
<CardContent className="p-6 text-sm text-muted-foreground">
{copy.empty}
</CardContent>
</AppCard>
</MotionFade>
) : null}
</div>
</div>
</RootDashboardShell>
);
} }
+4 -8
View File
@@ -2,7 +2,7 @@ import { MediaKind } from "@prisma/client";
import { redirect } from "next/navigation"; import { redirect } from "next/navigation";
import { MotionFade } from "@/components/motion-fade"; import { MotionFade } from "@/components/motion-fade";
import { FormSaveButton } from "@/components/root/form-save-button"; import { FlashMessage } from "@/components/root/flash-message";
import { SiteSettingsForm } from "@/components/root/site-settings-form"; import { SiteSettingsForm } from "@/components/root/site-settings-form";
import { RootDashboardShell } from "@/components/root/root-dashboard-shell"; import { RootDashboardShell } from "@/components/root/root-dashboard-shell";
import { clearAdminSessionCookie, isAdminAuthenticated } from "@/lib/admin-auth"; import { clearAdminSessionCookie, isAdminAuthenticated } from "@/lib/admin-auth";
@@ -63,22 +63,18 @@ export default async function RootSiteSettingsPage({
logoutAction={logoutAction} logoutAction={logoutAction}
headerTitle={copy.title} headerTitle={copy.title}
headerDescription={copy.subtitle} headerDescription={copy.subtitle}
headerActions={<FormSaveButton formId="site-settings-form" />} saveFormId="site-settings-form"
> >
<div className="space-y-6"> <div className="space-y-6">
{searchParams?.success ? ( {searchParams?.success ? (
<MotionFade delay={0.1}> <MotionFade delay={0.1}>
<p className="rounded-nested border border-status-success/30 bg-status-success/10 px-4 py-3 text-sm text-status-success"> <FlashMessage type="success" message={searchParams.success} />
{searchParams.success}
</p>
</MotionFade> </MotionFade>
) : null} ) : null}
{searchParams?.error ? ( {searchParams?.error ? (
<MotionFade delay={0.12}> <MotionFade delay={0.12}>
<p className="rounded-nested border border-destructive/30 bg-destructive/10 px-4 py-3 text-sm text-destructive"> <FlashMessage type="error" message={searchParams.error} />
{searchParams.error}
</p>
</MotionFade> </MotionFade>
) : null} ) : null}
+7 -3
View File
@@ -1,6 +1,6 @@
import type { ReactNode } from "react"; import type { ReactNode } from "react";
import Link from "next/link"; import Link from "next/link";
import type { LucideIcon } from "lucide-react"; import { ChevronDown, ChevronRight, type LucideIcon } from "lucide-react";
import { Separator } from "@/components/ui/separator"; import { Separator } from "@/components/ui/separator";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
@@ -10,6 +10,7 @@ type DashboardSidebarItem = {
href: string; href: string;
icon: LucideIcon; icon: LucideIcon;
active?: boolean; active?: boolean;
expanded?: boolean;
children?: DashboardSidebarItem[]; children?: DashboardSidebarItem[];
}; };
@@ -23,6 +24,8 @@ type DashboardSidebarProps = {
export function DashboardSidebar({ items, iconSrc, top, footer }: DashboardSidebarProps) { export function DashboardSidebar({ items, iconSrc, top, footer }: DashboardSidebarProps) {
function renderItem(item: DashboardSidebarItem, nested = false) { function renderItem(item: DashboardSidebarItem, nested = false) {
const Icon = item.icon; const Icon = item.icon;
const hasChildren = Boolean(item.children?.length);
const ChevronIcon = item.expanded ? ChevronDown : ChevronRight;
return ( return (
<div key={item.href} className="space-y-1"> <div key={item.href} className="space-y-1">
@@ -37,9 +40,10 @@ export function DashboardSidebar({ items, iconSrc, top, footer }: DashboardSideb
)} )}
> >
<Icon className="h-4 w-4" /> <Icon className="h-4 w-4" />
<span>{item.label}</span> <span className="flex-1">{item.label}</span>
{hasChildren ? <ChevronIcon className="h-4 w-4 opacity-70" /> : null}
</Link> </Link>
{item.children?.length ? item.children.map((child) => renderItem(child, true)) : null} {item.expanded && item.children?.length ? item.children.map((child) => renderItem(child, true)) : null}
</div> </div>
); );
} }
+67
View File
@@ -0,0 +1,67 @@
"use client";
import { useEffect, useState } from "react";
import { usePathname, useRouter, useSearchParams } from "next/navigation";
import { cn } from "@/lib/utils";
type FlashMessageProps = {
type: "success" | "error";
message: string;
clearDelayMs?: number;
};
export function FlashMessage({
type,
message,
clearDelayMs = 4000,
}: FlashMessageProps) {
const pathname = usePathname();
const router = useRouter();
const searchParams = useSearchParams();
const [visible, setVisible] = useState(true);
useEffect(() => {
setVisible(true);
}, [message, pathname, searchParams]);
useEffect(() => {
if (!message) {
return undefined;
}
const timeoutId = window.setTimeout(() => {
setVisible(false);
const nextParams = new URLSearchParams(searchParams.toString());
nextParams.delete("success");
nextParams.delete("error");
const nextQuery = nextParams.toString();
router.replace(nextQuery ? `${pathname}?${nextQuery}` : pathname, {
scroll: false,
});
}, clearDelayMs);
return () => {
window.clearTimeout(timeoutId);
};
}, [clearDelayMs, message, pathname, router, searchParams]);
if (!visible) {
return null;
}
return (
<p
className={cn(
"rounded-nested border px-4 py-3 text-sm",
type === "success"
? "border-status-success/30 bg-status-success/10 text-status-success"
: "border-destructive/30 bg-destructive/10 text-destructive",
)}
>
{message}
</p>
);
}
+203 -20
View File
@@ -1,12 +1,16 @@
"use client"; "use client";
import { Save } from "lucide-react"; import { LoaderCircle, Save } from "lucide-react";
import { useEffect, useState } from "react"; import { usePathname, useRouter, useSearchParams } from "next/navigation";
import { useEffect, useRef, useState } from "react";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
type FormSaveButtonProps = { type FormSaveButtonProps = {
formId: string; formId?: string;
formIds?: string[];
formSelector?: string;
formSelectors?: string[];
label?: string; label?: string;
}; };
@@ -21,41 +25,220 @@ function serializeForm(form: HTMLFormElement) {
export function FormSaveButton({ export function FormSaveButton({
formId, formId,
formIds,
formSelector,
formSelectors,
label = "Speichern", label = "Speichern",
}: FormSaveButtonProps) { }: FormSaveButtonProps) {
const pathname = usePathname();
const router = useRouter();
const searchParams = useSearchParams();
const [activeFormId, setActiveFormId] = useState<string | null>(formId ?? null);
const [isDirty, setIsDirty] = useState(false); const [isDirty, setIsDirty] = useState(false);
const [isSubmitting, setIsSubmitting] = useState(false);
const baselineRef = useRef<Map<string, string>>(new Map());
const activeFormIdRef = useRef<string | null>(formId ?? null);
const pendingSubmissionRef = useRef<{
formId: string;
originUrl: string;
} | null>(null);
const currentUrl = `${pathname}?${searchParams.toString()}`;
useEffect(() => { useEffect(() => {
const form = document.getElementById(formId); if (!formId && !formIds?.length && !formSelector && !formSelectors?.length) {
activeFormIdRef.current = null;
if (!(form instanceof HTMLFormElement)) { pendingSubmissionRef.current = null;
setActiveFormId(null);
setIsDirty(false); setIsDirty(false);
setIsSubmitting(false);
}
}, [formId, formIds, formSelector, formSelectors]);
useEffect(() => {
const formsById = [formId, ...(formIds ?? [])]
.filter((value): value is string => Boolean(value))
.map((id) => document.getElementById(id))
.filter((form): form is HTMLFormElement => form instanceof HTMLFormElement);
const formsBySelector = [formSelector, ...(formSelectors ?? [])]
.filter((value): value is string => Boolean(value))
.flatMap((selector) => Array.from(document.querySelectorAll(selector)))
.filter((form): form is HTMLFormElement => form instanceof HTMLFormElement);
const forms = Array.from(new Map([...formsById, ...formsBySelector].map((form) => [form.id, form])).values());
if (forms.length === 0) {
baselineRef.current.clear();
activeFormIdRef.current = formId ?? null;
setActiveFormId(formId ?? null);
setIsDirty(false);
setIsSubmitting(false);
return undefined; return undefined;
} }
const initialSnapshot = serializeForm(form); const availableIds = forms.map((form) => form.id).filter(Boolean);
const fallbackFormId = availableIds[0] ?? null;
const updateDirtyState = () => { const readDirtyState = (nextActiveFormId: string | null) => {
setIsDirty(serializeForm(form) !== initialSnapshot); if (!nextActiveFormId) {
setIsDirty(false);
return;
}
const nextForm = forms.find((form) => form.id === nextActiveFormId);
if (!nextForm) {
setIsDirty(false);
return;
}
setIsDirty(serializeForm(nextForm) !== baselineRef.current.get(nextActiveFormId));
}; };
updateDirtyState(); const syncBaseline = (form: HTMLFormElement) => {
baselineRef.current.set(form.id, serializeForm(form));
readDirtyState(form.id === activeFormIdRef.current ? form.id : activeFormIdRef.current ?? fallbackFormId);
setIsSubmitting(false);
};
form.addEventListener("input", updateDirtyState); const handleFormActivity = (form: HTMLFormElement) => {
form.addEventListener("change", updateDirtyState); activeFormIdRef.current = form.id;
form.addEventListener("reset", updateDirtyState); setActiveFormId(form.id);
setIsSubmitting(false);
setIsDirty(serializeForm(form) !== baselineRef.current.get(form.id));
};
const handleSubmit = (form: HTMLFormElement, event: SubmitEvent) => {
if (pendingSubmissionRef.current) {
event.preventDefault();
event.stopPropagation();
return;
}
activeFormIdRef.current = form.id;
pendingSubmissionRef.current = {
formId: form.id,
originUrl: currentUrl,
};
setActiveFormId(form.id);
setIsSubmitting(true);
setIsDirty(false);
};
for (const form of forms) {
if (!form.id) {
continue;
}
syncBaseline(form);
const onFocusIn = () => handleFormActivity(form);
const onInput = () => handleFormActivity(form);
const onChange = () => handleFormActivity(form);
const onReset = () => syncBaseline(form);
const onSubmit = (event: Event) => handleSubmit(form, event as SubmitEvent);
form.addEventListener("focusin", onFocusIn);
form.addEventListener("input", onInput);
form.addEventListener("change", onChange);
form.addEventListener("reset", onReset);
form.addEventListener("submit", onSubmit);
(form as HTMLFormElement & {
__saveButtonHandlers?: {
onFocusIn: () => void;
onInput: () => void;
onChange: () => void;
onReset: () => void;
onSubmit: (event: Event) => void;
};
}).__saveButtonHandlers = { onFocusIn, onInput, onChange, onReset, onSubmit };
}
const nextActive =
activeFormIdRef.current && availableIds.includes(activeFormIdRef.current)
? activeFormIdRef.current
: fallbackFormId;
activeFormIdRef.current = nextActive;
setActiveFormId(nextActive);
readDirtyState(nextActive);
return () => { return () => {
form.removeEventListener("input", updateDirtyState); for (const form of forms) {
form.removeEventListener("change", updateDirtyState); const handlers = (form as HTMLFormElement & {
form.removeEventListener("reset", updateDirtyState); __saveButtonHandlers?: {
onFocusIn: () => void;
onInput: () => void;
onChange: () => void;
onReset: () => void;
onSubmit: (event: Event) => void;
};
}).__saveButtonHandlers;
if (!handlers) {
continue;
}
form.removeEventListener("focusin", handlers.onFocusIn);
form.removeEventListener("input", handlers.onInput);
form.removeEventListener("change", handlers.onChange);
form.removeEventListener("reset", handlers.onReset);
form.removeEventListener("submit", handlers.onSubmit);
delete (
form as HTMLFormElement & {
__saveButtonHandlers?: {
onFocusIn: () => void;
onInput: () => void;
onChange: () => void;
onReset: () => void;
onSubmit: (event: Event) => void;
};
}
).__saveButtonHandlers;
}
}; };
}, [formId]); }, [currentUrl, formId, formIds, formSelector, formSelectors, pathname, searchParams]);
useEffect(() => {
const pendingSubmission = pendingSubmissionRef.current;
if (!pendingSubmission) {
return;
}
const hasError = searchParams.has("error");
const hasSuccess = searchParams.has("success") || searchParams.has("__saved");
const navigated = currentUrl !== pendingSubmission.originUrl;
if (hasError) {
pendingSubmissionRef.current = null;
setIsSubmitting(false);
return;
}
if (!hasSuccess && !navigated) {
return;
}
pendingSubmissionRef.current = null;
router.refresh();
if (!searchParams.has("__saved")) {
return;
}
const nextParams = new URLSearchParams(searchParams.toString());
nextParams.delete("__saved");
const nextQuery = nextParams.toString();
router.replace(nextQuery ? `${pathname}?${nextQuery}` : pathname, {
scroll: false,
});
}, [currentUrl, pathname, router, searchParams]);
return ( return (
<Button type="submit" form={formId} disabled={!isDirty}> <Button type="submit" form={activeFormId ?? undefined} disabled={!activeFormId || !isDirty || isSubmitting}>
<Save className="h-4 w-4" /> {isSubmitting ? <LoaderCircle className="h-4 w-4 animate-spin" /> : <Save className="h-4 w-4" />}
{label} {isSubmitting ? "Speichert..." : label}
</Button> </Button>
); );
} }
+3 -1
View File
@@ -48,6 +48,7 @@ type PortfolioProjectFormProps = {
categories: PortfolioCategoryView[]; categories: PortfolioCategoryView[];
mediaOptions: MediaOption[]; mediaOptions: MediaOption[];
project?: PortfolioProjectView | null; project?: PortfolioProjectView | null;
formId: string;
redirectPath: string; redirectPath: string;
submitLabel: string; submitLabel: string;
}; };
@@ -120,6 +121,7 @@ export function PortfolioProjectForm({
categories, categories,
mediaOptions, mediaOptions,
project, project,
formId,
redirectPath, redirectPath,
submitLabel, submitLabel,
}: PortfolioProjectFormProps) { }: PortfolioProjectFormProps) {
@@ -190,7 +192,7 @@ export function PortfolioProjectForm({
); );
return ( return (
<form action={action} className="space-y-6"> <form id={formId} action={action} className="space-y-6">
<input type="hidden" name="id" value={project?.id ?? ""} /> <input type="hidden" name="id" value={project?.id ?? ""} />
<input type="hidden" name="redirectPath" value={redirectPath} /> <input type="hidden" name="redirectPath" value={redirectPath} />
<input type="hidden" name="currentCoverImagePath" value={project?.coverImagePath ?? ""} /> <input type="hidden" name="currentCoverImagePath" value={project?.coverImagePath ?? ""} />
+1 -6
View File
@@ -5,7 +5,7 @@ import { CardContent } from "@/components/ui/card";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
type PortfolioSubnavProps = { type PortfolioSubnavProps = {
active: "overview" | "categories" | "projects"; active: "overview" | "categories";
}; };
const items = [ const items = [
@@ -19,11 +19,6 @@ const items = [
label: "Kategorien", label: "Kategorien",
href: "/root/portfolio/categories", href: "/root/portfolio/categories",
}, },
{
key: "projects",
label: "Projekte",
href: "/root/portfolio/projects",
},
] as const; ] as const;
export function PortfolioSubnav({ active }: PortfolioSubnavProps) { export function PortfolioSubnav({ active }: PortfolioSubnavProps) {
+27 -12
View File
@@ -15,12 +15,16 @@ import Link from "next/link";
import { DashboardLayout } from "@/components/dashboard/dashboard-layout"; import { DashboardLayout } from "@/components/dashboard/dashboard-layout";
import { MotionFade } from "@/components/motion-fade"; import { MotionFade } from "@/components/motion-fade";
import { FormSaveButton } from "@/components/root/form-save-button";
import { SidebarMaintenanceControl } from "@/components/root/sidebar-maintenance-control";
import { ThemeToggle } from "@/components/theme-toggle"; import { ThemeToggle } from "@/components/theme-toggle";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
import { getSiteSettingsMediaBindings } from "@/lib/app-config"; import { getMaintenanceMode, getSiteSettingsMediaBindings } from "@/lib/app-config";
import { getLocalizedPath } from "@/lib/locale"; import { getLocalizedPath } from "@/lib/locale";
import { getRootNavigation } from "@/lib/root-navigation"; import { getRootNavigation } from "@/lib/root-navigation";
import { updateMaintenanceModeAction } from "@/app/root/maintenance/actions";
type RootDashboardCopy = { type RootDashboardCopy = {
title: string; title: string;
subtitle: string; subtitle: string;
@@ -41,6 +45,9 @@ type RootDashboardShellProps = {
logoutAction: () => Promise<void>; logoutAction: () => Promise<void>;
headerTitle: string; headerTitle: string;
headerDescription: string; headerDescription: string;
saveFormId?: string;
saveFormSelector?: string;
saveButtonLabel?: string;
headerActions?: ReactNode; headerActions?: ReactNode;
sidebarTopContent?: ReactNode; sidebarTopContent?: ReactNode;
toolbar?: ReactNode; toolbar?: ReactNode;
@@ -54,12 +61,18 @@ export async function RootDashboardShell({
logoutAction, logoutAction,
headerTitle, headerTitle,
headerDescription, headerDescription,
saveFormId,
saveFormSelector,
saveButtonLabel,
headerActions, headerActions,
sidebarTopContent, sidebarTopContent,
toolbar, toolbar,
children, children,
}: RootDashboardShellProps) { }: RootDashboardShellProps) {
const mediaBindings = await getSiteSettingsMediaBindings(); const [mediaBindings, maintenanceEnabled] = await Promise.all([
getSiteSettingsMediaBindings(),
getMaintenanceMode(),
]);
const sidebarItems = getRootNavigation(copy, active, portfolioChild).filter( const sidebarItems = getRootNavigation(copy, active, portfolioChild).filter(
(item) => item.href !== "/root/maintenance" && item.href !== "/root/ui-kit", (item) => item.href !== "/root/maintenance" && item.href !== "/root/ui-kit",
); );
@@ -81,6 +94,11 @@ export async function RootDashboardShell({
: FolderKanban; : FolderKanban;
const sharedActions = ( const sharedActions = (
<> <>
<FormSaveButton
formIds={saveFormId ? ["sidebar-maintenance-form", saveFormId] : ["sidebar-maintenance-form"]}
formSelectors={saveFormSelector ? [saveFormSelector] : undefined}
label={saveButtonLabel ?? "Speichern"}
/>
<ThemeToggle ariaLabel="Theme wechseln" /> <ThemeToggle ariaLabel="Theme wechseln" />
</> </>
); );
@@ -105,16 +123,13 @@ export async function RootDashboardShell({
} }
sidebarFooter={ sidebarFooter={
<> <>
<Button <SidebarMaintenanceControl
asChild action={updateMaintenanceModeAction}
variant={active === "maintenance" ? "default" : "outline"} initialEnabled={maintenanceEnabled}
className="w-full justify-between" label={copy.maintenance}
> onLabel="Besucher gesperrt"
<Link href="/root/maintenance"> offLabel="Website offen"
{copy.maintenance} />
<ShieldAlert className="h-4 w-4" />
</Link>
</Button>
<Button <Button
asChild asChild
variant={active === "ui-kit" ? "default" : "outline"} variant={active === "ui-kit" ? "default" : "outline"}
@@ -0,0 +1,75 @@
"use client";
import { ShieldAlert } from "lucide-react";
import { usePathname } from "next/navigation";
import { useState } from "react";
import { Badge } from "@/components/ui/badge";
import { cn } from "@/lib/utils";
type SidebarMaintenanceControlProps = {
action: (formData: FormData) => Promise<void>;
initialEnabled: boolean;
label: string;
onLabel: string;
offLabel: string;
};
export function SidebarMaintenanceControl({
action,
initialEnabled,
label,
onLabel,
offLabel,
}: SidebarMaintenanceControlProps) {
const pathname = usePathname();
const [enabled, setEnabled] = useState(initialEnabled);
return (
<form id="sidebar-maintenance-form" action={action} className="space-y-2">
<input type="hidden" name="redirectPath" value={pathname} />
<input type="hidden" name="enabled" value={enabled ? "true" : "false"} />
<label
htmlFor="sidebar-maintenance-enabled"
className={cn(
"flex cursor-pointer items-center justify-between gap-3 rounded-nested border px-3 py-2 transition-colors",
enabled
? "border-status-warning/40 bg-status-warning-soft/80"
: "border-border bg-surface-1 hover:bg-surface-2",
)}
>
<span className="flex min-w-0 items-center gap-3">
<span
className={cn(
"flex h-9 w-9 items-center justify-center rounded-full border",
enabled
? "border-status-warning/40 bg-status-warning-soft text-status-warning"
: "border-border bg-background text-muted-foreground",
)}
>
<ShieldAlert className="h-4 w-4" />
</span>
<span className="min-w-0">
<span className="block text-sm font-medium text-foreground">{label}</span>
<span className="block text-xs text-muted-foreground">
{enabled ? onLabel : offLabel}
</span>
</span>
</span>
<Badge variant={enabled ? "warning" : "success"}>
{enabled ? "ON" : "OFF"}
</Badge>
</label>
<input
id="sidebar-maintenance-enabled"
type="checkbox"
checked={enabled}
onChange={(event) => setEnabled(event.target.checked)}
className="sr-only"
/>
</form>
);
}
+23 -30
View File
@@ -24,6 +24,7 @@ export type RootNavItem = {
href: string; href: string;
icon: LucideIcon; icon: LucideIcon;
active?: boolean; active?: boolean;
expanded?: boolean;
children?: RootNavItem[]; children?: RootNavItem[];
}; };
@@ -67,36 +68,28 @@ export function getRootNavigation(
label: copy.portfolio, label: copy.portfolio,
href: "/root/portfolio", href: "/root/portfolio",
icon: FolderKanban, icon: FolderKanban,
active: active === "portfolio", active: active === "portfolio" && !portfolioChild,
children: expanded: active === "portfolio",
active === "portfolio" children: [
? [ {
{ label: "Overview",
label: "Overview", href: "/root/portfolio",
href: "/root/portfolio", icon: LayoutDashboard,
icon: LayoutDashboard, active: portfolioChild === "overview",
active: portfolioChild === "overview", },
}, {
{ label: "Add Project",
label: "Add Project", href: "/root/portfolio/projects/new",
href: "/root/portfolio/projects/new", icon: PlusSquare,
icon: PlusSquare, active: portfolioChild === "new-project",
active: portfolioChild === "new-project", },
}, {
{ label: "Add Category",
label: "Add Category", href: "/root/portfolio/categories",
href: "/root/portfolio/categories", icon: Tags,
icon: Tags, active: portfolioChild === "categories",
active: portfolioChild === "categories", },
}, ].filter((item, index, array) => array.findIndex((entry) => entry.href === item.href) === index),
{
label: "Projects",
href: "/root/portfolio/projects",
icon: FolderKanban,
active: portfolioChild === "projects",
},
].filter((item, index, array) => array.findIndex((entry) => entry.href === item.href) === index)
: undefined,
}, },
]; ];
} }