Files
flatrender/src/app/[locale]/admin/layout.tsx
T
soroush.asadi 61ba526122 feat(admin): render-engine kill switch (block renders + show message)
Lets an admin disable rendering when no render node is available — users can't
start new renders and see a localized "service unavailable until <date>" message.

- Admin → فارم رندر → موتور رندر (RenderEngineAdmin): on/off toggle + fa/en message
  + optional Jalali "until" date; saved as one `render_service` Website Setting
  (jsonb) via /v1/settings — no backend change, no migration.
- lib/render-service.ts: fetchRenderServiceStatus (fail-open) + renderServiceMessage
  (locale + appends the date).
- Enforcement: POST /api/render returns 503 {code:render_disabled, messages} when off;
  studio render page reads GET /api/render/service on mount → disables "شروع رندر"
  and shows the banner, and handles the 503 on click.
- i18n: appAdminLayout.renderEngine (fa+en, parity 1045/1045). tsc + next build clean.
  Verified: disabled setting → /api/render/service returns enabled:false.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-12 09:47:42 +03:30

98 lines
3.1 KiB
TypeScript

import { redirect } from "next/navigation";
import { getTranslations } from "next-intl/server";
import { AdminShell, type NavGroup } from "@/components/admin/AdminShell";
import { getCurrentUser } from "@/lib/auth/session";
export const dynamic = "force-dynamic";
export default async function AdminLayout({
children,
}: {
children: React.ReactNode;
}) {
const user = await getCurrentUser();
if (!user || !user.is_admin) {
redirect("/dashboard");
}
const t = await getTranslations("auto.appAdminLayout");
const groups: NavGroup[] = [
{
title: "نمای کلی",
items: [{ href: "/admin/stats", label: t("stats") }],
},
{
title: "محتوا",
items: [
{ href: "/admin/home", label: t("homePage") },
{ href: "/admin/categories", label: t("categories") },
{ href: "/admin/templates", label: t("templates") },
{ href: "/admin/projects", label: t("projects") },
{ href: "/admin/ranking", label: t("ranking") },
{ href: "/admin/tags", label: t("tags") },
{ href: "/admin/fonts", label: t("fonts") },
{ href: "/admin/music", label: t("music") },
{ href: "/admin/blogs", label: t("blogs") },
{ href: "/admin/learn", label: t("learn") },
{ href: "/admin/pages", label: t("pages") },
{ href: "/admin/slides", label: t("slides") },
{ href: "/admin/home-events", label: t("homeEvents") },
{ href: "/admin/routes", label: t("routes") },
{ href: "/admin/comments", label: t("comments") },
{ href: "/admin/files", label: t("media") },
{ href: "/admin/ai", label: t("aiContent") },
],
},
{
title: "رشد و ارتباطات",
items: [
{ href: "/admin/messaging", label: t("messaging") },
{ href: "/admin/integrations", label: t("integrations") },
{ href: "/admin/marketing", label: t("marketing") },
{ href: "/admin/crm", label: t("crm") },
],
},
{
title: "کاربران و مالی",
items: [
{ href: "/admin/users", label: t("users") },
{ href: "/admin/plans", label: t("plans") },
{ href: "/admin/discounts", label: t("discounts") },
],
},
{
title: "فارم رندر",
items: [
{ href: "/admin/render-engine", label: t("renderEngine") },
{ href: "/admin/nodes", label: t("nodes") },
{ href: "/admin/node-fonts", label: t("nodeFonts") },
{ href: "/admin/renders", label: t("renderQueue") },
{ href: "/admin/exports", label: t("exports") },
],
},
{
title: "سیستم",
items: [{ href: "/admin/settings", label: t("siteSettings") }],
},
];
const email = user.email ?? "";
const fullName = typeof user.full_name === "string" ? user.full_name.trim() : "";
return (
<AdminShell
groups={groups}
brand={t("brand")}
back={t("backToDashboard")}
user={{
name: fullName || (email ? email.split("@")[0] : "Admin"),
email,
avatarUrl: (user.avatar_url as string | null) ?? null,
}}
>
{children}
</AdminShell>
);
}