refactor: drop toast + over-engineered extras, add inline admin feedback
CI / quality (push) Waiting to run
CI / quality (push) Waiting to run
Phase 1 cleanup of the personal-site revamp. Backend/architecture untouched; changes are limited to removing unused complexity and restoring feedback. Removals - Toast system: delete react-hot-toast, Toaster, QueryToastBridge, lib/toast, the toggle/easter-egg calls, related i18n keys and the dependency. - Contact protection: remove Turnstile + per-IP rate limiting (lib/contact-guard, lib/contact-protection, admin screen, form widget, app-config wiring, nav entry, test). - Speculative specs: delete orders, products, downloads, project-inquiry. Inline feedback (replaces toast, no new deps) - Add lib/admin-feedback (withFlash/readFlash) and components/admin/admin-flash, rendered centrally by AdminDashboardShell. - Emit success/error messages for media, site-settings, portfolio, smtp, marquee and maintenance actions; pages read them via searchParams. - Contact form shows validation/delivery errors inline; success still redirects to /success. Docs - Fix stale paths in frontend-system-* (components/root -> components/admin, lib/root-navigation -> lib/admin-navigation, drop phantom src/) and remove contact-protection references from docs and CLAUDE.md. - Add docs/PHASE0_DIAGNOSIS.md (diagnosis report). Note: proxy.ts self-fetch kept intentionally; it also drives maintenance mode.
This commit is contained in:
@@ -15,6 +15,7 @@ import {
|
||||
} from "lucide-react";
|
||||
import Link from "next/link";
|
||||
|
||||
import { AdminFlash } from "@/components/admin/admin-flash";
|
||||
import { DashboardLayout } from "@/components/dashboard/dashboard-layout";
|
||||
import { MotionFade } from "@/components/motion-fade";
|
||||
import { SidebarMaintenanceControl } from "@/components/admin/sidebar-maintenance-control";
|
||||
@@ -24,6 +25,7 @@ import { Button } from "@/components/ui/button";
|
||||
import { buildSiteUrl, getAdminAppPath } from "@/lib/admin-routing";
|
||||
import { getMaintenanceMode, getSiteSettingsMediaBindings } from "@/lib/app-config";
|
||||
import { getAdminNavigation } from "@/lib/admin-navigation";
|
||||
import type { FlashMessages } from "@/lib/admin-feedback";
|
||||
|
||||
import { updateMaintenanceModeAction } from "@/app/_admin/maintenance/actions";
|
||||
|
||||
@@ -40,7 +42,6 @@ type AdminDashboardCopy = {
|
||||
localizationSettings?: string;
|
||||
marquee?: string;
|
||||
smtp?: string;
|
||||
contactProtection?: string;
|
||||
logout: string;
|
||||
backToSite: string;
|
||||
};
|
||||
@@ -48,9 +49,9 @@ type AdminDashboardCopy = {
|
||||
type AdminDashboardShellProps = {
|
||||
copy: AdminDashboardCopy;
|
||||
active: "overview" | "maintenance" | "ui-kit" | "portfolio" | "media" | "site-settings" | "smtp" | "marquee";
|
||||
smtpChild?: "settings" | "contact-protection";
|
||||
portfolioChild?: "overview" | "projects" | "new-project" | "categories";
|
||||
siteSettingsChild?: "brand" | "localization";
|
||||
flash?: FlashMessages;
|
||||
logoutAction: () => Promise<void>;
|
||||
headerTitle: string;
|
||||
headerDescription: string;
|
||||
@@ -63,9 +64,9 @@ type AdminDashboardShellProps = {
|
||||
export async function AdminDashboardShell({
|
||||
copy,
|
||||
active,
|
||||
smtpChild,
|
||||
portfolioChild,
|
||||
siteSettingsChild,
|
||||
flash,
|
||||
logoutAction,
|
||||
headerTitle,
|
||||
headerDescription,
|
||||
@@ -78,7 +79,7 @@ export async function AdminDashboardShell({
|
||||
getSiteSettingsMediaBindings(),
|
||||
getMaintenanceMode(),
|
||||
]);
|
||||
const sidebarItems = getAdminNavigation(copy, active, smtpChild, portfolioChild, siteSettingsChild);
|
||||
const sidebarItems = getAdminNavigation(copy, active, portfolioChild, siteSettingsChild);
|
||||
const normalizedSidebarItems = sidebarItems.filter(
|
||||
(item) =>
|
||||
item.href !== getAdminAppPath("/maintenance") &&
|
||||
@@ -155,18 +156,19 @@ export async function AdminDashboardShell({
|
||||
<SoundToggle
|
||||
ariaLabel="Mute sounds"
|
||||
mutedAriaLabel="Unmute sounds"
|
||||
mutedToastLabel="Sound muted"
|
||||
unmutedToastLabel="Sound enabled"
|
||||
/>
|
||||
<ThemeToggle
|
||||
ariaLabel="Theme wechseln"
|
||||
lightToastLabel="Light mode enabled"
|
||||
darkToastLabel="Dark mode enabled"
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<div className="space-y-6">
|
||||
{flash?.success || flash?.error ? (
|
||||
<MotionFade delay={0.05}>
|
||||
<AdminFlash success={flash.success} error={flash.error} />
|
||||
</MotionFade>
|
||||
) : null}
|
||||
{toolbar ? <MotionFade delay={0.05}>{toolbar}</MotionFade> : null}
|
||||
{children}
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import type { FlashMessages } from "@/lib/admin-feedback";
|
||||
|
||||
type AdminFlashProps = FlashMessages & {
|
||||
className?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Inline feedback banner for admin pages. Renders a success and/or error
|
||||
* message inside the page (replacing the removed toast system). Purely
|
||||
* presentational — no client state, no data access.
|
||||
*/
|
||||
export function AdminFlash({ success, error, className }: AdminFlashProps) {
|
||||
if (!success && !error) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={className ? `space-y-2 ${className}` : "space-y-2"}>
|
||||
{success ? (
|
||||
<p
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
className="rounded-nested border border-status-success/30 bg-status-success-soft px-4 py-3 text-sm font-medium text-status-success"
|
||||
>
|
||||
{success}
|
||||
</p>
|
||||
) : null}
|
||||
{error ? (
|
||||
<p
|
||||
role="alert"
|
||||
className="rounded-nested border border-destructive/30 bg-destructive/10 px-4 py-3 text-sm font-medium text-destructive"
|
||||
>
|
||||
{error}
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,137 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
|
||||
import { AppCard } from "@/components/ui/app-card";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Checkbox } from "@/components/ui/checkbox";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import type { ContactProtectionFormValues } from "@/lib/contact-protection";
|
||||
|
||||
type ContactProtectionFormProps = {
|
||||
action: (formData: FormData) => Promise<void>;
|
||||
initialSettings: ContactProtectionFormValues;
|
||||
};
|
||||
|
||||
export function ContactProtectionForm({
|
||||
action,
|
||||
initialSettings,
|
||||
}: ContactProtectionFormProps) {
|
||||
const [turnstileEnabled, setTurnstileEnabled] = useState(initialSettings.turnstile.enabled);
|
||||
const [rateLimitEnabled, setRateLimitEnabled] = useState(initialSettings.rateLimit.enabled);
|
||||
|
||||
return (
|
||||
<form id="contact-protection-form" action={action} className="grid gap-6 xl:grid-cols-2">
|
||||
<AppCard layer="single">
|
||||
<CardHeader>
|
||||
<CardTitle>Turnstile</CardTitle>
|
||||
<CardDescription>Cloudflare Schutz fuer das Kontaktformular.</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="grid gap-5 p-4 md:grid-cols-2">
|
||||
<div className="space-y-4 md:col-span-2">
|
||||
<label
|
||||
htmlFor="turnstileEnabled"
|
||||
className="flex cursor-pointer items-start gap-3 rounded-nested border border-input bg-card px-4 py-4 transition-colors hover:bg-accent/20"
|
||||
>
|
||||
<Checkbox
|
||||
id="turnstileEnabled"
|
||||
name="turnstileEnabled"
|
||||
checked={turnstileEnabled}
|
||||
onCheckedChange={(checked) => setTurnstileEnabled(checked === true)}
|
||||
className="mt-0.5"
|
||||
/>
|
||||
<span className="space-y-1">
|
||||
<span className="block text-sm font-medium text-foreground">Enable Turnstile</span>
|
||||
<span className="block text-xs text-muted-foreground">
|
||||
{turnstileEnabled
|
||||
? "ON: Besucher muessen die Pruefung bestehen."
|
||||
: "OFF: Kein Turnstile Schutz im Formular."}
|
||||
</span>
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="turnstileSiteKey">Turnstile Site Key</Label>
|
||||
<Input
|
||||
id="turnstileSiteKey"
|
||||
name="turnstileSiteKey"
|
||||
defaultValue={initialSettings.turnstile.siteKey}
|
||||
autoComplete="off"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="turnstileSecretKey">Turnstile Secret Key</Label>
|
||||
<Input
|
||||
id="turnstileSecretKey"
|
||||
name="turnstileSecretKey"
|
||||
type="password"
|
||||
defaultValue={initialSettings.turnstile.secretKey}
|
||||
placeholder={initialSettings.turnstile.hasSecretKey ? "Saved secret key will be kept" : "Secret key"}
|
||||
autoComplete="new-password"
|
||||
/>
|
||||
</div>
|
||||
</CardContent>
|
||||
</AppCard>
|
||||
|
||||
<AppCard layer="single">
|
||||
<CardHeader>
|
||||
<CardTitle>Rate Limiting</CardTitle>
|
||||
<CardDescription>Begrenzung wiederholter Kontaktanfragen.</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="grid gap-5 p-4 md:grid-cols-2">
|
||||
<div className="space-y-4 md:col-span-2">
|
||||
<label
|
||||
htmlFor="contactRateLimitEnabled"
|
||||
className="flex cursor-pointer items-start gap-3 rounded-nested border border-input bg-card px-4 py-4 transition-colors hover:bg-accent/20"
|
||||
>
|
||||
<Checkbox
|
||||
id="contactRateLimitEnabled"
|
||||
name="contactRateLimitEnabled"
|
||||
checked={rateLimitEnabled}
|
||||
onCheckedChange={(checked) => setRateLimitEnabled(checked === true)}
|
||||
className="mt-0.5"
|
||||
/>
|
||||
<span className="space-y-1">
|
||||
<span className="block text-sm font-medium text-foreground">Enable rate limiting</span>
|
||||
<span className="block text-xs text-muted-foreground">
|
||||
{rateLimitEnabled
|
||||
? "ON: Das Formular blockiert zu viele Anfragen pro Zeitfenster."
|
||||
: "OFF: Keine serverseitige Begrenzung aktiv."}
|
||||
</span>
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="contactRateLimitMaxRequests">Max Requests</Label>
|
||||
<Input
|
||||
id="contactRateLimitMaxRequests"
|
||||
name="contactRateLimitMaxRequests"
|
||||
type="number"
|
||||
min="1"
|
||||
defaultValue={initialSettings.rateLimit.maxRequests}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="contactRateLimitWindowMinutes">Window Minutes</Label>
|
||||
<Input
|
||||
id="contactRateLimitWindowMinutes"
|
||||
name="contactRateLimitWindowMinutes"
|
||||
type="number"
|
||||
min="1"
|
||||
defaultValue={initialSettings.rateLimit.windowMinutes}
|
||||
/>
|
||||
</div>
|
||||
</CardContent>
|
||||
</AppCard>
|
||||
<div className="xl:col-span-2 flex justify-end">
|
||||
<Button type="submit">Save Protection</Button>
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useRef } from "react";
|
||||
import { usePathname, useRouter, useSearchParams } from "next/navigation";
|
||||
|
||||
import { toast } from "@/lib/toast";
|
||||
|
||||
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";
|
||||
};
|
||||
const localizedMessage = pendingToast.message;
|
||||
|
||||
if (!localizedMessage) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (pendingToast.type === "error") {
|
||||
toast.error(localizedMessage);
|
||||
} else if (pendingToast.type === "success") {
|
||||
toast.success(localizedMessage);
|
||||
} else {
|
||||
toast(localizedMessage);
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
Reference in New Issue
Block a user