Add Sonner-based notifications and UX polish

This commit is contained in:
MOH
2026-03-10 17:43:26 +01:00
parent eceb0f3a54
commit 77cc9dca87
32 changed files with 279 additions and 310 deletions
+13 -7
View File
@@ -40,9 +40,15 @@ const contactErrorMessages = {
}, },
} as const; } as const;
function withError(pathname: string, message: string) { const contactSuccessMessages = {
ar: "شكراً على رسالتك.",
en: "Thank you for your message.",
de: "Vielen Dank fuer deine Nachricht.",
} as const;
function withMessage(pathname: string, type: "success" | "error", message: string) {
const params = new URLSearchParams(); const params = new URLSearchParams();
params.set("error", message); params.set(type, message);
return `${pathname}?${params.toString()}`; return `${pathname}?${params.toString()}`;
} }
@@ -80,18 +86,18 @@ export async function submitContactFormAction(formData: FormData) {
message: values.message, message: values.message,
}); });
redirect(getLocalizedPath(locale, "/success")); redirect(withMessage(getLocalizedPath(locale, "/success"), "success", contactSuccessMessages[locale]));
} catch (error) { } catch (error) {
if (isRedirectError(error)) { if (isRedirectError(error)) {
throw error; throw error;
} }
if (error instanceof z.ZodError) { if (error instanceof z.ZodError) {
redirect(withError(contactPath, contactErrorMessages[locale].invalid)); redirect(withMessage(contactPath, "error", contactErrorMessages[locale].invalid));
} }
if (error instanceof Error && error.message === "Too many contact requests. Please try again later.") { if (error instanceof Error && error.message === "Too many contact requests. Please try again later.") {
redirect(withError(contactPath, contactErrorMessages[locale].blocked)); redirect(withMessage(contactPath, "error", contactErrorMessages[locale].blocked));
} }
if ( if (
@@ -100,10 +106,10 @@ export async function submitContactFormAction(formData: FormData) {
error.message === "Turnstile verification failed." || error.message === "Turnstile verification failed." ||
error.message === "Turnstile verification request failed.") error.message === "Turnstile verification request failed.")
) { ) {
redirect(withError(contactPath, contactErrorMessages[locale].verification)); redirect(withMessage(contactPath, "error", contactErrorMessages[locale].verification));
} }
console.error("Contact form delivery failed.", error); console.error("Contact form delivery failed.", error);
redirect(withError(contactPath, contactErrorMessages[locale].failed)); redirect(withMessage(contactPath, "error", contactErrorMessages[locale].failed));
} }
} }
+1 -13
View File
@@ -5,7 +5,6 @@ import { getTranslations } from "next-intl/server";
import { Container } from "@/components/layout/container"; import { Container } from "@/components/layout/container";
import { PageHero } from "@/components/layout/page-hero"; import { PageHero } from "@/components/layout/page-hero";
import { MotionFade } from "@/components/motion-fade"; import { MotionFade } from "@/components/motion-fade";
import { FlashMessage } from "@/components/root/flash-message";
import { ContactForm } from "@/components/site/contact-form"; import { ContactForm } from "@/components/site/contact-form";
import { buildLocalizedMetadata } from "@/lib/metadata"; import { buildLocalizedMetadata } from "@/lib/metadata";
import { getPublicContactProtectionSettings } from "@/lib/app-config"; import { getPublicContactProtectionSettings } from "@/lib/app-config";
@@ -19,9 +18,6 @@ type ContactPageProps = {
params: { params: {
locale: string; locale: string;
}; };
searchParams?: {
error?: string;
};
}; };
export async function generateMetadata({ export async function generateMetadata({
@@ -38,10 +34,7 @@ export async function generateMetadata({
}); });
} }
export default async function ContactPage({ export default async function ContactPage({ params: { locale } }: ContactPageProps) {
params: { locale },
searchParams,
}: ContactPageProps) {
const localeKey = resolveLocale(locale); const localeKey = resolveLocale(locale);
const [t, protection] = await Promise.all([ const [t, protection] = await Promise.all([
getTranslations({ locale: localeKey, namespace: "contactPage" }), getTranslations({ locale: localeKey, namespace: "contactPage" }),
@@ -86,11 +79,6 @@ export default async function ContactPage({
<MotionFade delay={0.05}> <MotionFade delay={0.05}>
<AppCard> <AppCard>
<CardContent className="pt-6"> <CardContent className="pt-6">
{searchParams?.error ? (
<div className="mb-4">
<FlashMessage type="error" message={searchParams.error} />
</div>
) : null}
<ContactForm <ContactForm
action={submitContactFormAction} action={submitContactFormAction}
locale={localeKey} locale={localeKey}
+7 -1
View File
@@ -3,8 +3,10 @@ import { unstable_noStore as noStore } from "next/cache";
import localFont from "next/font/local"; import localFont from "next/font/local";
import Script from "next/script"; import Script from "next/script";
import { getLocale } from "next-intl/server"; import { getLocale } from "next-intl/server";
import { QueryToastBridge } from "@/components/root/query-toast-bridge";
import { SoundProvider } from "@/components/sound-provider"; import { SoundProvider } from "@/components/sound-provider";
import { ThemeProvider } from "@/components/theme-provider"; import { ThemeProvider } from "@/components/theme-provider";
import { Toaster } from "@/components/ui/sonner";
import { buildAppMetadata } from "@/lib/metadata"; import { buildAppMetadata } from "@/lib/metadata";
import { getDirection } from "@/lib/locale"; import { getDirection } from "@/lib/locale";
import "./globals.css"; import "./globals.css";
@@ -95,7 +97,11 @@ export default async function RootLayout({
<html lang={locale} dir={getDirection(locale)} suppressHydrationWarning> <html lang={locale} dir={getDirection(locale)} suppressHydrationWarning>
<body className={`${museo.variable} ${dubai.variable}`}> <body className={`${museo.variable} ${dubai.variable}`}>
<ThemeProvider> <ThemeProvider>
<SoundProvider>{children}</SoundProvider> <SoundProvider>
{children}
<QueryToastBridge />
<Toaster />
</SoundProvider>
</ThemeProvider> </ThemeProvider>
<Script <Script
src="https://plausible.mohfarawati.de/js/pa-H7WDubj39eeDW3cfzeXhU.js" src="https://plausible.mohfarawati.de/js/pa-H7WDubj39eeDW3cfzeXhU.js"
+4 -1
View File
@@ -21,7 +21,10 @@ export async function updateMaintenanceModeAction(formData: FormData) {
const nextValue = formData.get("enabled") === "true"; const nextValue = formData.get("enabled") === "true";
const redirectPath = String(formData.get("redirectPath") ?? "/root"); const redirectPath = String(formData.get("redirectPath") ?? "/root");
const redirectUrl = new URL(redirectPath, "http://localhost"); const redirectUrl = new URL(redirectPath, "http://localhost");
redirectUrl.searchParams.set("__saved", "maintenance"); redirectUrl.searchParams.set(
"success",
nextValue ? "Wartungsmodus aktiviert." : "Wartungsmodus deaktiviert.",
);
await setMaintenanceMode(nextValue); await setMaintenanceMode(nextValue);
revalidatePath("/", "layout"); revalidatePath("/", "layout");
+1 -24
View File
@@ -1,6 +1,5 @@
import { redirect } from "next/navigation"; import { redirect } from "next/navigation";
import { FlashMessage } from "@/components/root/flash-message";
import { MarqueeSettingsForm } from "@/components/root/marquee-settings-form"; import { MarqueeSettingsForm } from "@/components/root/marquee-settings-form";
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";
@@ -26,16 +25,7 @@ const copy = {
backToSite: "Zur Website", backToSite: "Zur Website",
}; };
type RootMarqueePageProps = { export default async function RootMarqueePage() {
searchParams?: {
success?: string;
error?: string;
};
};
export default async function RootMarqueePage({
searchParams,
}: RootMarqueePageProps) {
if (!isAdminAuthenticated()) { if (!isAdminAuthenticated()) {
redirect("/root"); redirect("/root");
} }
@@ -57,21 +47,8 @@ export default async function RootMarqueePage({
headerTitle={copy.title} headerTitle={copy.title}
headerDescription={copy.subtitle} headerDescription={copy.subtitle}
saveFormId="marquee-settings-form" saveFormId="marquee-settings-form"
reloadDocumentOnSave
> >
<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}
<MotionFade delay={0.14}> <MotionFade delay={0.14}>
<MarqueeSettingsForm <MarqueeSettingsForm
action={saveMarqueeSettingsAction} action={saveMarqueeSettingsAction}
+1 -22
View File
@@ -1,8 +1,6 @@
import { redirect } from "next/navigation"; import { redirect } from "next/navigation";
import { FlashMessage } from "@/components/root/flash-message";
import { MediaLibraryManager } from "@/components/root/media-library-manager"; import { MediaLibraryManager } from "@/components/root/media-library-manager";
import { MotionFade } from "@/components/motion-fade";
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 { getAdminMediaAssets } from "@/lib/media"; import { getAdminMediaAssets } from "@/lib/media";
@@ -22,14 +20,7 @@ const copy = {
backToSite: "Zur Website", backToSite: "Zur Website",
}; };
type RootMediaPageProps = { export default async function RootMediaPage() {
searchParams?: {
success?: string;
error?: string;
};
};
export default async function RootMediaPage({ searchParams }: RootMediaPageProps) {
if (!isAdminAuthenticated()) { if (!isAdminAuthenticated()) {
redirect("/root"); redirect("/root");
} }
@@ -52,18 +43,6 @@ export default async function RootMediaPage({ searchParams }: RootMediaPageProps
headerDescription={copy.subtitle} headerDescription={copy.subtitle}
> >
<div className="space-y-6"> <div className="space-y-6">
{searchParams?.success ? (
<MotionFade delay={0.1}>
<FlashMessage type="success" message={searchParams.success} />
</MotionFade>
) : null}
{searchParams?.error ? (
<MotionFade delay={0.12}>
<FlashMessage type="error" message={searchParams.error} />
</MotionFade>
) : null}
<MediaLibraryManager mediaAssets={mediaAssets} /> <MediaLibraryManager mediaAssets={mediaAssets} />
</div> </div>
</RootDashboardShell> </RootDashboardShell>
+1 -24
View File
@@ -1,7 +1,5 @@
import { redirect } from "next/navigation"; import { redirect } from "next/navigation";
import { MotionFade } from "@/components/motion-fade";
import { FlashMessage } from "@/components/root/flash-message";
import { PortfolioCategoriesManager } from "@/components/root/portfolio-categories-manager"; import { PortfolioCategoriesManager } from "@/components/root/portfolio-categories-manager";
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";
@@ -24,16 +22,7 @@ const copy = {
backToSite: "Zur Website", backToSite: "Zur Website",
}; };
type RootPortfolioCategoriesPageProps = { export default async function RootPortfolioCategoriesPage() {
searchParams?: {
success?: string;
error?: string;
};
};
export default async function RootPortfolioCategoriesPage({
searchParams,
}: RootPortfolioCategoriesPageProps) {
if (!isAdminAuthenticated()) { if (!isAdminAuthenticated()) {
redirect("/root"); redirect("/root");
} }
@@ -59,18 +48,6 @@ export default async function RootPortfolioCategoriesPage({
headerDescription={copy.subtitle} headerDescription={copy.subtitle}
> >
<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}
<PortfolioCategoriesManager <PortfolioCategoriesManager
categories={categories} categories={categories}
activeCount={activeCount} activeCount={activeCount}
-14
View File
@@ -1,8 +1,6 @@
import { redirect } from "next/navigation"; import { redirect } from "next/navigation";
import { RootDashboardShell } from "@/components/root/root-dashboard-shell"; import { RootDashboardShell } from "@/components/root/root-dashboard-shell";
import { MotionFade } from "@/components/motion-fade";
import { FlashMessage } from "@/components/root/flash-message";
import { PortfolioProjectsOverview } from "@/components/root/portfolio-projects-overview"; import { PortfolioProjectsOverview } from "@/components/root/portfolio-projects-overview";
import { clearAdminSessionCookie, isAdminAuthenticated } from "@/lib/admin-auth"; import { clearAdminSessionCookie, isAdminAuthenticated } from "@/lib/admin-auth";
import { getAdminPortfolioCategories, getAdminPortfolioProjects } from "@/lib/portfolio"; import { getAdminPortfolioCategories, getAdminPortfolioProjects } from "@/lib/portfolio";
@@ -67,18 +65,6 @@ export default async function RootPortfolioPage({ searchParams }: RootPortfolioP
headerDescription={copy.subtitle} headerDescription={copy.subtitle}
> >
<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}
<PortfolioProjectsOverview <PortfolioProjectsOverview
categories={categories} categories={categories}
projects={projects} projects={projects}
-18
View File
@@ -1,7 +1,6 @@
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 { 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";
@@ -39,15 +38,10 @@ type RootPortfolioProjectPageProps = {
params: { params: {
id: string; id: string;
}; };
searchParams?: {
success?: string;
error?: string;
};
}; };
export default async function RootPortfolioProjectPage({ export default async function RootPortfolioProjectPage({
params, params,
searchParams,
}: RootPortfolioProjectPageProps) { }: RootPortfolioProjectPageProps) {
if (!isAdminAuthenticated()) { if (!isAdminAuthenticated()) {
redirect("/root"); redirect("/root");
@@ -82,18 +76,6 @@ export default async function RootPortfolioProjectPage({
saveButtonLabel={copy.saveProject} saveButtonLabel={copy.saveProject}
> >
<div className="space-y-6"> <div className="space-y-6">
{searchParams?.success ? (
<MotionFade delay={0.1}>
<FlashMessage type="success" message={searchParams.success} />
</MotionFade>
) : null}
{searchParams?.error ? (
<MotionFade delay={0.12}>
<FlashMessage type="error" message={searchParams.error} />
</MotionFade>
) : null}
<MotionFade delay={0.15}> <MotionFade delay={0.15}>
<PortfolioProjectForm <PortfolioProjectForm
action={saveProjectAction} action={saveProjectAction}
+1 -16
View File
@@ -1,7 +1,6 @@
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 { 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";
@@ -25,15 +24,7 @@ const copy = {
backToSite: "Zur Website", backToSite: "Zur Website",
}; };
type RootNewPortfolioProjectPageProps = { export default async function RootNewPortfolioProjectPage() {
searchParams?: {
error?: string;
};
};
export default async function RootNewPortfolioProjectPage({
searchParams,
}: RootNewPortfolioProjectPageProps) {
if (!isAdminAuthenticated()) { if (!isAdminAuthenticated()) {
redirect("/root"); redirect("/root");
} }
@@ -61,12 +52,6 @@ export default async function RootNewPortfolioProjectPage({
saveFormId="portfolio-project-form" saveFormId="portfolio-project-form"
> >
<div className="space-y-6"> <div className="space-y-6">
{searchParams?.error ? (
<MotionFade delay={0.1}>
<FlashMessage type="error" message={searchParams.error} />
</MotionFade>
) : null}
<MotionFade delay={0.15}> <MotionFade delay={0.15}>
<PortfolioProjectForm <PortfolioProjectForm
action={saveProjectAction} action={saveProjectAction}
-16
View File
@@ -1,7 +1,5 @@
import { redirect } from "next/navigation"; import { redirect } from "next/navigation";
import { MotionFade } from "@/components/motion-fade";
import { FlashMessage } from "@/components/root/flash-message";
import { PortfolioProjectsOverview } from "@/components/root/portfolio-projects-overview"; import { PortfolioProjectsOverview } from "@/components/root/portfolio-projects-overview";
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";
@@ -26,8 +24,6 @@ type RootPortfolioProjectsPageProps = {
searchParams?: { searchParams?: {
category?: string; category?: string;
status?: "all" | "draft" | "published"; status?: "all" | "draft" | "published";
success?: string;
error?: string;
}; };
}; };
@@ -69,18 +65,6 @@ export default async function RootPortfolioProjectsPage({
headerDescription={copy.subtitle} headerDescription={copy.subtitle}
> >
<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}
<PortfolioProjectsOverview <PortfolioProjectsOverview
categories={categories} categories={categories}
projects={projects} projects={projects}
+1 -24
View File
@@ -2,7 +2,6 @@ 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 { 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";
@@ -30,16 +29,7 @@ const copy = {
backToSite: "Zur Website", backToSite: "Zur Website",
}; };
type RootSiteSettingsPageProps = { export default async function RootSiteSettingsPage() {
searchParams?: {
success?: string;
error?: string;
};
};
export default async function RootSiteSettingsPage({
searchParams,
}: RootSiteSettingsPageProps) {
if (!isAdminAuthenticated()) { if (!isAdminAuthenticated()) {
redirect("/root"); redirect("/root");
} }
@@ -65,21 +55,8 @@ export default async function RootSiteSettingsPage({
headerTitle={copy.title} headerTitle={copy.title}
headerDescription={copy.subtitle} headerDescription={copy.subtitle}
saveFormId="site-settings-form" saveFormId="site-settings-form"
reloadDocumentOnSave
> >
<div className="space-y-6"> <div className="space-y-6">
{searchParams?.success ? (
<MotionFade delay={0.1}>
<FlashMessage type="success" message={searchParams.success} />
</MotionFade>
) : null}
{searchParams?.error ? (
<MotionFade delay={0.12}>
<FlashMessage type="error" message={searchParams.error} />
</MotionFade>
) : null}
<MotionFade delay={0.16}> <MotionFade delay={0.16}>
<SiteSettingsForm <SiteSettingsForm
action={saveSiteSettingsAction} action={saveSiteSettingsAction}
+1 -24
View File
@@ -2,7 +2,6 @@ import { redirect } from "next/navigation";
import { MotionFade } from "@/components/motion-fade"; import { MotionFade } from "@/components/motion-fade";
import { ContactProtectionForm } from "@/components/root/contact-protection-form"; import { ContactProtectionForm } from "@/components/root/contact-protection-form";
import { FlashMessage } from "@/components/root/flash-message";
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 { getContactProtectionFormValues } from "@/lib/app-config"; import { getContactProtectionFormValues } from "@/lib/app-config";
@@ -26,16 +25,7 @@ const copy = {
backToSite: "Zur Website", backToSite: "Zur Website",
}; };
type RootSMTPProtectionPageProps = { export default async function RootSMTPProtectionPage() {
searchParams?: {
success?: string;
error?: string;
};
};
export default async function RootSMTPProtectionPage({
searchParams,
}: RootSMTPProtectionPageProps) {
if (!isAdminAuthenticated()) { if (!isAdminAuthenticated()) {
redirect("/root"); redirect("/root");
} }
@@ -58,21 +48,8 @@ export default async function RootSMTPProtectionPage({
headerTitle={copy.title} headerTitle={copy.title}
headerDescription={copy.subtitle} headerDescription={copy.subtitle}
saveFormId="contact-protection-form" saveFormId="contact-protection-form"
reloadDocumentOnSave
> >
<div className="space-y-6"> <div className="space-y-6">
{searchParams?.success ? (
<MotionFade delay={0.1}>
<FlashMessage type="success" message={searchParams.success} />
</MotionFade>
) : null}
{searchParams?.error ? (
<MotionFade delay={0.12}>
<FlashMessage type="error" message={searchParams.error} />
</MotionFade>
) : null}
<MotionFade delay={0.16}> <MotionFade delay={0.16}>
<ContactProtectionForm <ContactProtectionForm
action={saveContactProtectionSettingsAction} action={saveContactProtectionSettingsAction}
+1 -22
View File
@@ -1,7 +1,6 @@
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 { SMTPSettingsForm } from "@/components/root/smtp-settings-form"; import { SMTPSettingsForm } from "@/components/root/smtp-settings-form";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
@@ -27,14 +26,7 @@ const copy = {
backToSite: "Zur Website", backToSite: "Zur Website",
}; };
type RootSMTPPageProps = { export default async function RootSMTPPage() {
searchParams?: {
success?: string;
error?: string;
};
};
export default async function RootSMTPPage({ searchParams }: RootSMTPPageProps) {
if (!isAdminAuthenticated()) { if (!isAdminAuthenticated()) {
redirect("/root"); redirect("/root");
} }
@@ -57,7 +49,6 @@ export default async function RootSMTPPage({ searchParams }: RootSMTPPageProps)
headerTitle={copy.title} headerTitle={copy.title}
headerDescription={copy.subtitle} headerDescription={copy.subtitle}
saveFormId="smtp-settings-form" saveFormId="smtp-settings-form"
reloadDocumentOnSave
headerActions={( headerActions={(
<form action={sendTestEmailAction}> <form action={sendTestEmailAction}>
<Button type="submit" variant="outline"> <Button type="submit" variant="outline">
@@ -67,18 +58,6 @@ export default async function RootSMTPPage({ searchParams }: RootSMTPPageProps)
)} )}
> >
<div className="space-y-6"> <div className="space-y-6">
{searchParams?.success ? (
<MotionFade delay={0.1}>
<FlashMessage type="success" message={searchParams.success} />
</MotionFade>
) : null}
{searchParams?.error ? (
<MotionFade delay={0.12}>
<FlashMessage type="error" message={searchParams.error} />
</MotionFade>
) : null}
<MotionFade delay={0.16}> <MotionFade delay={0.16}>
<SMTPSettingsForm <SMTPSettingsForm
action={saveMailSettingsAction} action={saveMailSettingsAction}
@@ -25,16 +25,25 @@ export function FloatingPreferences({
<SoundToggle <SoundToggle
ariaLabel={t("soundMute")} ariaLabel={t("soundMute")}
mutedAriaLabel={t("soundUnmute")} mutedAriaLabel={t("soundUnmute")}
mutedToastLabel={t("soundMuted")}
unmutedToastLabel={t("soundEnabled")}
variant="ghost" variant="ghost"
className="h-9 w-9 rounded-pill border border-transparent bg-transparent text-foreground/80 hover:bg-accent hover:text-foreground" className="h-9 w-9 rounded-pill border border-transparent bg-transparent text-foreground/80 hover:bg-accent hover:text-foreground"
/> />
<ThemeToggle <ThemeToggle
ariaLabel={t("themeToggle")} ariaLabel={t("themeToggle")}
lightToastLabel={t("themeLight")}
darkToastLabel={t("themeDark")}
variant="ghost" variant="ghost"
className="h-9 w-9 rounded-pill border border-transparent bg-transparent text-foreground/80 hover:bg-accent hover:text-foreground" className="h-9 w-9 rounded-pill border border-transparent bg-transparent text-foreground/80 hover:bg-accent hover:text-foreground"
/> />
<LocaleToggle <LocaleToggle
locale={locale} locale={locale}
localeChangedLabels={{
de: t("localeChangedDe"),
en: t("localeChangedEn"),
ar: t("localeChangedAr"),
}}
className="h-9 w-9 rounded-pill border border-transparent bg-transparent p-0 text-foreground/80 hover:bg-accent hover:text-foreground" className="h-9 w-9 rounded-pill border border-transparent bg-transparent p-0 text-foreground/80 hover:bg-accent hover:text-foreground"
/> />
</div> </div>
+16
View File
@@ -13,16 +13,20 @@ import {
import { AppLocale, getLocalizedPath, stripLocalePrefix } from "@/lib/locale"; import { AppLocale, getLocalizedPath, stripLocalePrefix } from "@/lib/locale";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
const PENDING_TOAST_STORAGE_KEY = "mohfarawati-pending-toast";
type LocaleToggleProps = { type LocaleToggleProps = {
locale: string; locale: string;
className?: string; className?: string;
showLabel?: boolean; showLabel?: boolean;
localeChangedLabels?: Partial<Record<AppLocale, string>>;
}; };
export function LocaleToggle({ export function LocaleToggle({
locale, locale,
className, className,
showLabel = false, showLabel = false,
localeChangedLabels,
}: LocaleToggleProps) { }: LocaleToggleProps) {
const pathname = usePathname(); const pathname = usePathname();
const locales: AppLocale[] = ["de", "en", "ar"]; const locales: AppLocale[] = ["de", "en", "ar"];
@@ -75,6 +79,18 @@ export function LocaleToggle({
> >
<a <a
href={getLocalizedPath(targetLocale, currentPath)} href={getLocalizedPath(targetLocale, currentPath)}
onClick={() => {
const message = localeChangedLabels?.[targetLocale];
if (!message) {
return;
}
window.sessionStorage.setItem(
PENDING_TOAST_STORAGE_KEY,
JSON.stringify({ message, type: "success" }),
);
}}
className="group flex h-10 w-10 items-center justify-center rounded-full" className="group flex h-10 w-10 items-center justify-center rounded-full"
> >
<Image <Image
-67
View File
@@ -1,67 +0,0 @@
"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>
);
}
+3 -8
View File
@@ -30,7 +30,6 @@ export function FormSaveButton({
formSelector, formSelector,
formSelectors, formSelectors,
label = "Speichern", label = "Speichern",
reloadDocumentOnSuccess = false,
}: FormSaveButtonProps) { }: FormSaveButtonProps) {
const pathname = usePathname(); const pathname = usePathname();
const router = useRouter(); const router = useRouter();
@@ -280,12 +279,8 @@ export function FormSaveButton({
} }
pendingSubmissionRef.current = null; pendingSubmissionRef.current = null;
if (reloadDocumentOnSuccess) { setIsSubmitting(false);
window.location.reload(); dirtyFormsRef.current.delete(pendingSubmission.formId);
return;
}
router.refresh();
if (!searchParams.has("__saved")) { if (!searchParams.has("__saved")) {
return; return;
@@ -298,7 +293,7 @@ export function FormSaveButton({
router.replace(nextQuery ? `${pathname}?${nextQuery}` : pathname, { router.replace(nextQuery ? `${pathname}?${nextQuery}` : pathname, {
scroll: false, scroll: false,
}); });
}, [currentUrl, pathname, reloadDocumentOnSuccess, router, searchParams]); }, [currentUrl, pathname, router, searchParams]);
return ( return (
<Button type="submit" form={activeFormId ?? undefined} disabled={!activeFormId || !isDirty || isSubmitting}> <Button type="submit" form={activeFormId ?? undefined} disabled={!activeFormId || !isDirty || isSubmitting}>
+1 -1
View File
@@ -33,7 +33,7 @@ import { createMediaAssetAction, deleteMediaAssetAction } from "@/app/root/media
const copy = { const copy = {
addMedia: "Upload Media File", addMedia: "Upload Media File",
addMediaDescription: "Datei hochladen und direkt in die Media Library uebernehmen.", addMediaDescription: "Datei hochladen und direkt in die Media Library uebernehmen.",
addMediaHint: "PNG, JPG, GIF oder PDF bis 4 MB", addMediaHint: "PNG, JPG, GIF oder PDF bis 5 MB",
label: "Bezeichnung", label: "Bezeichnung",
kind: "Typ", kind: "Typ",
image: "Image", image: "Image",
+84
View File
@@ -0,0 +1,84 @@
"use client";
import { useEffect, useRef } from "react";
import { usePathname, useRouter, useSearchParams } from "next/navigation";
import { toast } from "sonner";
const TOAST_PARAM_NAMES = ["success", "error"] as const;
const PENDING_TOAST_STORAGE_KEY = "mohfarawati-pending-toast";
export function QueryToastBridge() {
const pathname = usePathname();
const router = useRouter();
const searchParams = useSearchParams();
const handledKeyRef = useRef<string | null>(null);
useEffect(() => {
const rawToast = window.sessionStorage.getItem(PENDING_TOAST_STORAGE_KEY);
if (!rawToast) {
return;
}
try {
const pendingToast = JSON.parse(rawToast) as {
message?: string;
type?: "success" | "error";
};
if (!pendingToast.message) {
return;
}
if (pendingToast.type === "error") {
toast.error(pendingToast.message);
} else if (pendingToast.type === "success") {
toast.success(pendingToast.message);
} else {
toast(pendingToast.message);
}
} finally {
window.sessionStorage.removeItem(PENDING_TOAST_STORAGE_KEY);
}
}, [pathname]);
useEffect(() => {
const successMessage = searchParams.get("success");
const errorMessage = searchParams.get("error");
if (!successMessage && !errorMessage) {
handledKeyRef.current = null;
return;
}
const handledKey = `${pathname}:${successMessage ?? ""}:${errorMessage ?? ""}`;
if (handledKeyRef.current === handledKey) {
return;
}
handledKeyRef.current = handledKey;
if (successMessage) {
toast.success(successMessage);
}
if (errorMessage) {
toast.error(errorMessage);
}
const nextParams = new URLSearchParams(searchParams.toString());
for (const name of TOAST_PARAM_NAMES) {
nextParams.delete(name);
}
const nextQuery = nextParams.toString();
router.replace(nextQuery ? `${pathname}?${nextQuery}` : pathname, {
scroll: false,
});
}, [pathname, router, searchParams]);
return null;
}
+11 -2
View File
@@ -120,8 +120,17 @@ export async function RootDashboardShell({
label={saveButtonLabel ?? "Speichern"} label={saveButtonLabel ?? "Speichern"}
reloadDocumentOnSuccess={reloadDocumentOnSave} reloadDocumentOnSuccess={reloadDocumentOnSave}
/> />
<SoundToggle ariaLabel="Mute sounds" mutedAriaLabel="Unmute sounds" /> <SoundToggle
<ThemeToggle ariaLabel="Theme wechseln" /> ariaLabel="Mute sounds"
mutedAriaLabel="Unmute sounds"
mutedToastLabel="Sound muted"
unmutedToastLabel="Sound enabled"
/>
<ThemeToggle
ariaLabel="Theme wechseln"
lightToastLabel="Light mode enabled"
darkToastLabel="Dark mode enabled"
/>
</> </>
); );
+11 -1
View File
@@ -1,6 +1,7 @@
"use client"; "use client";
import { Volume2, VolumeX } from "lucide-react"; import { Volume2, VolumeX } from "lucide-react";
import { toast } from "sonner";
import { useSound } from "@/components/sound-provider"; import { useSound } from "@/components/sound-provider";
import { Button, type ButtonProps } from "@/components/ui/button"; import { Button, type ButtonProps } from "@/components/ui/button";
@@ -9,6 +10,8 @@ import { cn } from "@/lib/utils";
type SoundToggleProps = { type SoundToggleProps = {
ariaLabel?: string; ariaLabel?: string;
mutedAriaLabel?: string; mutedAriaLabel?: string;
mutedToastLabel?: string;
unmutedToastLabel?: string;
variant?: ButtonProps["variant"]; variant?: ButtonProps["variant"];
className?: string; className?: string;
iconClassName?: string; iconClassName?: string;
@@ -17,18 +20,25 @@ type SoundToggleProps = {
export function SoundToggle({ export function SoundToggle({
ariaLabel = "Mute sounds", ariaLabel = "Mute sounds",
mutedAriaLabel = "Unmute sounds", mutedAriaLabel = "Unmute sounds",
mutedToastLabel = "Sound muted",
unmutedToastLabel = "Sound enabled",
variant = "outline", variant = "outline",
className, className,
iconClassName, iconClassName,
}: SoundToggleProps) { }: SoundToggleProps) {
const { isMuted, toggleMuted } = useSound(); const { isMuted, toggleMuted } = useSound();
const handleToggle = () => {
toggleMuted();
toast(isMuted ? unmutedToastLabel : mutedToastLabel);
};
return ( return (
<Button <Button
type="button" type="button"
variant={variant} variant={variant}
size="icon" size="icon"
onClick={toggleMuted} onClick={handleToggle}
aria-label={isMuted ? mutedAriaLabel : ariaLabel} aria-label={isMuted ? mutedAriaLabel : ariaLabel}
aria-pressed={isMuted} aria-pressed={isMuted}
className={cn("group cursor-pointer", className)} className={cn("group cursor-pointer", className)}
+6
View File
@@ -3,6 +3,7 @@
import { Moon, Sun } from "lucide-react"; import { Moon, Sun } from "lucide-react";
import { useTheme } from "next-themes"; import { useTheme } from "next-themes";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { toast } from "sonner";
import { useSound } from "@/components/sound-provider"; import { useSound } from "@/components/sound-provider";
import { Button, type ButtonProps } from "@/components/ui/button"; import { Button, type ButtonProps } from "@/components/ui/button";
@@ -11,6 +12,8 @@ import { cn } from "@/lib/utils";
type ThemeToggleProps = { type ThemeToggleProps = {
ariaLabel?: string; ariaLabel?: string;
label?: string; label?: string;
lightToastLabel?: string;
darkToastLabel?: string;
variant?: ButtonProps["variant"]; variant?: ButtonProps["variant"];
className?: string; className?: string;
iconClassName?: string; iconClassName?: string;
@@ -19,6 +22,8 @@ type ThemeToggleProps = {
export function ThemeToggle({ export function ThemeToggle({
ariaLabel = "Toggle theme", ariaLabel = "Toggle theme",
label, label,
lightToastLabel = "Light mode enabled",
darkToastLabel = "Dark mode enabled",
variant = "outline", variant = "outline",
className, className,
iconClassName, iconClassName,
@@ -54,6 +59,7 @@ export function ThemeToggle({
setTheme(nextTheme); setTheme(nextTheme);
playSound(nextTheme === "dark" ? "/audio/dark.mp3" : "/audio/light.mp3"); playSound(nextTheme === "dark" ? "/audio/dark.mp3" : "/audio/light.mp3");
toast(nextTheme === "dark" ? darkToastLabel : lightToastLabel);
}; };
return ( return (
+50
View File
@@ -0,0 +1,50 @@
"use client";
import { usePathname } from "next/navigation";
import { useTheme } from "next-themes";
import { useEffect, useState } from "react";
import { Toaster as Sonner, type ToasterProps } from "sonner";
export function Toaster(props: ToasterProps) {
const pathname = usePathname();
const { resolvedTheme = "light" } = useTheme();
const [documentLang, setDocumentLang] = useState("de");
useEffect(() => {
setDocumentLang(document.documentElement.lang || "de");
}, [pathname]);
const isArabic = documentLang === "ar";
const toastFontFamily = isArabic ? "var(--font-dubai), sans-serif" : "var(--font-museo), sans-serif";
return (
<Sonner
theme={resolvedTheme as ToasterProps["theme"]}
position="top-center"
duration={2400}
toastOptions={{
style: {
borderRadius: "16px",
padding: "10px 12px",
background: "hsl(var(--card))",
color: "hsl(var(--card-foreground))",
border: "1px solid hsl(var(--border))",
fontFamily: toastFontFamily,
},
classNames: {
toast:
"rounded-[16px] border border-border bg-card px-3 py-2 text-card-foreground shadow-panel",
default:
"border-border bg-card text-card-foreground",
title: "text-[13px] font-medium leading-5",
description: "text-[13px] leading-5 text-muted-foreground",
success:
"border-status-success/30 bg-status-success-soft text-status-success dark:border-status-success/40 dark:bg-status-success-soft dark:text-status-success",
error:
"border-destructive/30 bg-destructive/10 text-destructive dark:border-destructive/40 dark:bg-destructive/20 dark:text-destructive-foreground",
},
}}
{...props}
/>
);
}
+2 -2
View File
@@ -164,7 +164,7 @@ export function inferMediaKindFromMimeType(mimeType: string | null | undefined):
export function inferMediaKindFromFileName(fileName: string): MediaKind { export function inferMediaKindFromFileName(fileName: string): MediaKind {
const extension = path.extname(fileName).toLowerCase(); const extension = path.extname(fileName).toLowerCase();
if ([".jpg", ".jpeg", ".png", ".webp", ".svg"].includes(extension)) { if ([".gif", ".jpg", ".jpeg", ".png", ".webp", ".svg"].includes(extension)) {
return MediaKind.IMAGE; return MediaKind.IMAGE;
} }
@@ -174,7 +174,7 @@ export function inferMediaKindFromFileName(fileName: string): MediaKind {
export function getKindFromUploadFile(file: File) { export function getKindFromUploadFile(file: File) {
const extension = getExtensionForMimeType(file.type); const extension = getExtensionForMimeType(file.type);
if (extension && [".jpg", ".jpeg", ".png", ".webp", ".svg"].includes(extension)) { if (extension && [".gif", ".jpg", ".jpeg", ".png", ".webp", ".svg"].includes(extension)) {
return MediaKind.IMAGE; return MediaKind.IMAGE;
} }
+1
View File
@@ -8,6 +8,7 @@ export const MAX_MEDIA_FILE_SIZE = 5 * 1024 * 1024;
const MIME_EXTENSIONS: Record<string, string> = { const MIME_EXTENSIONS: Record<string, string> = {
"image/x-icon": ".ico", "image/x-icon": ".ico",
"image/vnd.microsoft.icon": ".ico", "image/vnd.microsoft.icon": ".ico",
"image/gif": ".gif",
"image/jpeg": ".jpg", "image/jpeg": ".jpg",
"image/png": ".png", "image/png": ".png",
"image/webp": ".webp", "image/webp": ".webp",
+9 -1
View File
@@ -9,8 +9,16 @@
"openMenu": "فتح القائمة", "openMenu": "فتح القائمة",
"closeMenu": "إغلاق القائمة", "closeMenu": "إغلاق القائمة",
"themeToggle": "تبديل المظهر", "themeToggle": "تبديل المظهر",
"themeLight": "تم تفعيل الوضع الفاتح",
"themeDark": "تم تفعيل الوضع الداكن",
"soundMute": "كتم الأصوات", "soundMute": "كتم الأصوات",
"soundUnmute": "تشغيل الأصوات" "soundUnmute": "تشغيل الأصوات",
"soundMuted": "تم كتم الصوت",
"soundEnabled": "تم تشغيل الصوت",
"localeChangedDe": "تم تغيير اللغة إلى الألمانية",
"localeChangedEn": "تم تغيير اللغة إلى الإنجليزية",
"localeChangedAr": "تم تغيير اللغة إلى العربية",
"logoTripleClick": "هدي اللعب... اللوغو مو زر طوارئ."
}, },
"footer": { "footer": {
"copyright": "© {year} moh-sass. جميع الحقوق محفوظة." "copyright": "© {year} moh-sass. جميع الحقوق محفوظة."
+9 -1
View File
@@ -9,8 +9,16 @@
"openMenu": "Menü öffnen", "openMenu": "Menü öffnen",
"closeMenu": "Menü schliessen", "closeMenu": "Menü schliessen",
"themeToggle": "Theme wechseln", "themeToggle": "Theme wechseln",
"themeLight": "Heller Modus aktiviert",
"themeDark": "Dunkler Modus aktiviert",
"soundMute": "Sounds stummschalten", "soundMute": "Sounds stummschalten",
"soundUnmute": "Sounds aktivieren" "soundUnmute": "Sounds aktivieren",
"soundMuted": "Sound stummgeschaltet",
"soundEnabled": "Sound aktiviert",
"localeChangedDe": "Sprache auf Deutsch gewechselt",
"localeChangedEn": "Sprache auf Englisch gewechselt",
"localeChangedAr": "Sprache auf Arabisch gewechselt",
"logoTripleClick": "Ganz ruhig. Das Logo ist kein Panikknopf."
}, },
"footer": { "footer": {
"copyright": "© {year} moh-sass. Alle Rechte vorbehalten." "copyright": "© {year} moh-sass. Alle Rechte vorbehalten."
+9 -1
View File
@@ -9,8 +9,16 @@
"openMenu": "Open menu", "openMenu": "Open menu",
"closeMenu": "Close menu", "closeMenu": "Close menu",
"themeToggle": "Toggle theme", "themeToggle": "Toggle theme",
"themeLight": "Light mode enabled",
"themeDark": "Dark mode enabled",
"soundMute": "Mute sounds", "soundMute": "Mute sounds",
"soundUnmute": "Unmute sounds" "soundUnmute": "Unmute sounds",
"soundMuted": "Sound muted",
"soundEnabled": "Sound enabled",
"localeChangedDe": "Language changed to German",
"localeChangedEn": "Language changed to English",
"localeChangedAr": "Language changed to Arabic",
"logoTripleClick": "Easy there. The logo is not a panic button."
}, },
"footer": { "footer": {
"copyright": "© {year} moh-sass. All rights reserved." "copyright": "© {year} moh-sass. All rights reserved."
+11
View File
@@ -29,6 +29,7 @@
"react": "^18", "react": "^18",
"react-dom": "^18", "react-dom": "^18",
"react-hook-form": "^7.71.2", "react-hook-form": "^7.71.2",
"sonner": "^2.0.7",
"tailwind-merge": "^3.5.0", "tailwind-merge": "^3.5.0",
"zod": "^4.3.6" "zod": "^4.3.6"
}, },
@@ -9002,6 +9003,16 @@
"url": "https://github.com/sponsors/isaacs" "url": "https://github.com/sponsors/isaacs"
} }
}, },
"node_modules/sonner": {
"version": "2.0.7",
"resolved": "https://registry.npmjs.org/sonner/-/sonner-2.0.7.tgz",
"integrity": "sha512-W6ZN4p58k8aDKA4XPcx2hpIQXBRAgyiWVkYhT7CvK6D3iAu7xjvVyhQHg2/iaKJZ1XVJ4r7XuwGL+WGEK37i9w==",
"license": "MIT",
"peerDependencies": {
"react": "^18.0.0 || ^19.0.0 || ^19.0.0-rc",
"react-dom": "^18.0.0 || ^19.0.0 || ^19.0.0-rc"
}
},
"node_modules/source-map-js": { "node_modules/source-map-js": {
"version": "1.2.1", "version": "1.2.1",
"resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz", "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz",
+1
View File
@@ -38,6 +38,7 @@
"react": "^18", "react": "^18",
"react-dom": "^18", "react-dom": "^18",
"react-hook-form": "^7.71.2", "react-hook-form": "^7.71.2",
"sonner": "^2.0.7",
"tailwind-merge": "^3.5.0", "tailwind-merge": "^3.5.0",
"zod": "^4.3.6" "zod": "^4.3.6"
}, },
+14
View File
@@ -0,0 +1,14 @@
import { describe, expect, it } from "vitest";
import { getExtensionForMimeType } from "@/lib/media-storage";
import { inferMediaKindFromFileName } from "@/lib/media-service";
describe("media upload types", () => {
it("accepts gif mime types", () => {
expect(getExtensionForMimeType("image/gif")).toBe(".gif");
});
it("treats gif files as images", () => {
expect(inferMediaKindFromFileName("animation.gif")).toBe("IMAGE");
});
});