refactor: drop toast + over-engineered extras, add inline admin feedback
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:
MohFarawati
2026-07-14 21:03:51 +02:00
parent 1a7b3397f6
commit d48497b992
62 changed files with 443 additions and 1453 deletions
+13 -64
View File
@@ -4,8 +4,7 @@ import { redirect } from "next/navigation";
import { isRedirectError } from "next/dist/client/components/redirect-error";
import { z } from "zod";
import { enforceContactRateLimit, verifyTurnstileToken } from "@/lib/contact-guard";
import { getContactProtectionSettings, getSiteSettings } from "@/lib/app-config";
import { getSiteSettings } from "@/lib/app-config";
import { getLocalizedPath, resolveLocale } from "@/lib/locale";
import { sendContactMessage } from "@/lib/mail";
@@ -16,55 +15,32 @@ const contactFormSchema = z.object({
phone: z.string().trim().max(40).optional(),
company: z.string().trim().max(120).optional(),
message: z.string().trim().min(10).max(5000),
turnstileToken: z.string().trim().optional(),
});
const contactErrorMessages = {
ar: {
invalid: "يرجى تعبئة كل الحقول بشكل صحيح.",
failed: "تعذر إرسال الرسالة حالياً.",
blocked: "تم إرسال عدد كبير من الطلبات. حاول لاحقاً.",
verification: "يرجى إكمال التحقق قبل الإرسال.",
},
en: {
invalid: "Please fill all fields correctly.",
failed: "Message could not be sent right now.",
blocked: "Too many requests. Please try again later.",
verification: "Please complete the verification before sending.",
},
de: {
invalid: "Bitte alle Felder korrekt ausfuellen.",
failed: "Nachricht konnte gerade nicht gesendet werden.",
blocked: "Zu viele Anfragen. Bitte spaeter erneut versuchen.",
verification: "Bitte die Verifizierung vor dem Senden abschliessen.",
},
ar: "تعذّر إرسال الرسالة. تأكد من تعبئة الحقول بشكل صحيح وحاول مجدداً.",
en: "Your message could not be sent. Please check the fields and try again.",
de: "Nachricht konnte nicht gesendet werden. Bitte Eingaben pruefen und erneut versuchen.",
} as const;
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();
params.set(type, message);
return `${pathname}?${params.toString()}`;
}
function getStringValue(formData: FormData, key: string) {
const value = formData.get(key);
return typeof value === "string" ? value : "";
}
function withContactError(pathname: string, message: string) {
const params = new URLSearchParams();
params.set("error", message);
return `${pathname}?${params.toString()}`;
}
export async function submitContactFormAction(formData: FormData) {
const siteSettings = await getSiteSettings();
const locale = resolveLocale(String(formData.get("locale") ?? ""), siteSettings.defaultLocale);
const contactPath = getLocalizedPath(locale, "/contact", siteSettings.defaultLocale);
try {
const protectionSettings = await getContactProtectionSettings();
const values = contactFormSchema.parse({
locale,
name: getStringValue(formData, "name"),
@@ -72,12 +48,8 @@ export async function submitContactFormAction(formData: FormData) {
phone: getStringValue(formData, "phone"),
company: getStringValue(formData, "company"),
message: getStringValue(formData, "message"),
turnstileToken: getStringValue(formData, "turnstileToken"),
});
await verifyTurnstileToken(protectionSettings, values.turnstileToken ?? "");
await enforceContactRateLimit(protectionSettings);
await sendContactMessage({
locale,
name: values.name,
@@ -87,36 +59,13 @@ export async function submitContactFormAction(formData: FormData) {
message: values.message,
});
redirect(
withMessage(
getLocalizedPath(locale, "/success", siteSettings.defaultLocale),
"success",
contactSuccessMessages[locale],
),
);
redirect(getLocalizedPath(locale, "/success", siteSettings.defaultLocale));
} catch (error) {
if (isRedirectError(error)) {
throw error;
}
if (error instanceof z.ZodError) {
redirect(withMessage(contactPath, "error", contactErrorMessages[locale].invalid));
}
if (error instanceof Error && error.message === "Too many contact requests. Please try again later.") {
redirect(withMessage(contactPath, "error", contactErrorMessages[locale].blocked));
}
if (
error instanceof Error &&
(error.message === "Turnstile verification is required." ||
error.message === "Turnstile verification failed." ||
error.message === "Turnstile verification request failed.")
) {
redirect(withMessage(contactPath, "error", contactErrorMessages[locale].verification));
}
console.error("Contact form delivery failed.", error);
redirect(withMessage(contactPath, "error", contactErrorMessages[locale].failed));
redirect(withContactError(contactPath, contactErrorMessages[locale]));
}
}
+18 -7
View File
@@ -7,7 +7,7 @@ import { PageHero } from "@/components/layout/page-hero";
import { MotionFade } from "@/components/motion-fade";
import { ContactForm } from "@/components/site/contact-form";
import { buildLocalizedMetadata } from "@/lib/metadata";
import { getPublicContactProtectionSettings, getSiteSettings } from "@/lib/app-config";
import { getSiteSettings } from "@/lib/app-config";
import { getLocalizedPath, resolveLocale } from "@/lib/locale";
import { AppCard } from "@/components/ui/app-card";
import { CardContent, CardHeader, CardTitle } from "@/components/ui/card";
@@ -18,6 +18,9 @@ type ContactPageProps = {
params: Promise<{
locale: string;
}>;
searchParams?: Promise<{
error?: string;
}>;
};
export async function generateMetadata({ params }: ContactPageProps): Promise<Metadata> {
@@ -34,14 +37,12 @@ export async function generateMetadata({ params }: ContactPageProps): Promise<Me
});
}
export default async function ContactPage({ params }: ContactPageProps) {
export default async function ContactPage({ params, searchParams }: ContactPageProps) {
await params;
const siteSettings = await getSiteSettings();
const localeKey = resolveLocale(await getLocale().catch(() => siteSettings.defaultLocale), siteSettings.defaultLocale);
const [t, protection] = await Promise.all([
getTranslations({ locale: localeKey, namespace: "contactPage" }),
getPublicContactProtectionSettings(),
]);
const t = await getTranslations({ locale: localeKey, namespace: "contactPage" });
const contactError = (await searchParams)?.error;
return (
<>
@@ -52,6 +53,17 @@ export default async function ContactPage({ params }: ContactPageProps) {
description={t("intro")}
/>
{contactError ? (
<Container className="pb-6">
<p
role="alert"
className="rounded-nested border border-destructive/30 bg-destructive/10 px-4 py-3 text-sm font-medium text-destructive"
>
{contactError}
</p>
</Container>
) : null}
<Container className="grid gap-6 pb-12 lg:grid-cols-2 lg:pb-16">
<MotionFade>
<AppCard level={3}>
@@ -85,7 +97,6 @@ export default async function ContactPage({ params }: ContactPageProps) {
action={submitContactFormAction}
locale={localeKey}
previewHref={getLocalizedPath(localeKey, "/success", siteSettings.defaultLocale)}
protection={protection}
copy={{
name: t("name"),
email: t("email"),