268 lines
8.1 KiB
TypeScript
268 lines
8.1 KiB
TypeScript
import type { PropsWithChildren } from "react";
|
|
import { AppShellMain } from "@mantine/core";
|
|
import {
|
|
IconAffiliateFilled,
|
|
IconApi,
|
|
IconBook2,
|
|
IconBox,
|
|
IconBuildingStore,
|
|
IconBrandDiscord,
|
|
IconBrandDocker,
|
|
IconBrandGithub,
|
|
IconBrandTablerFilled,
|
|
IconCertificate,
|
|
IconClipboardListFilled,
|
|
IconDatabaseExport,
|
|
IconDirectionsFilled,
|
|
IconGitFork,
|
|
IconHelpSquareRoundedFilled,
|
|
IconHomeFilled,
|
|
IconLayoutDashboardFilled,
|
|
IconMailForward,
|
|
IconPhotoFilled,
|
|
IconPointerFilled,
|
|
IconRobot,
|
|
IconSearch,
|
|
IconSettingsFilled,
|
|
IconUserFilled,
|
|
IconUsers,
|
|
IconUsersGroup,
|
|
} from "@tabler/icons-react";
|
|
|
|
import { getRscUserSettingsAsync } from "@homarr/api/user-server";
|
|
import { auth } from "@homarr/auth/next";
|
|
import { isProviderEnabled } from "@homarr/auth/server";
|
|
import { createLogger } from "@homarr/core/infrastructure/logs";
|
|
import { createDocumentationLink } from "@homarr/definitions";
|
|
import { dbEnv } from "@homarr/core/infrastructure/db/env";
|
|
import { env } from "@homarr/docker/env";
|
|
import { getScopedI18n } from "@homarr/translation/server";
|
|
|
|
import { MainHeader } from "~/components/layout/header";
|
|
import { homarrLogoPath } from "~/components/layout/logo/homarr-logo";
|
|
import type { NavigationLink } from "~/components/layout/navigation";
|
|
import { MainNavigation } from "~/components/layout/navigation";
|
|
import { ClientShell } from "~/components/layout/shell";
|
|
import { ManageTourGate } from "~/components/onboarding/manage-tour-gate";
|
|
import { env as nextEnv } from "~/env";
|
|
|
|
const logger = createLogger({ module: "manageLayout" });
|
|
|
|
export default async function ManageLayout({ children }: PropsWithChildren) {
|
|
const sessionPromise = auth();
|
|
const shouldRunManageTourPromise = sessionPromise.then(async (session) => {
|
|
if (!session || nextEnv.DEMO_MODE) return false;
|
|
|
|
try {
|
|
const user = await getRscUserSettingsAsync(session.user.id);
|
|
return user !== undefined && !user.completedManageTour;
|
|
} catch (error) {
|
|
logger.error(new Error("Failed to load the management tour status", { cause: error }));
|
|
return false;
|
|
}
|
|
});
|
|
const [t, session, shouldRunManageTour] = await Promise.all([
|
|
getScopedI18n("management.navbar"),
|
|
sessionPromise,
|
|
shouldRunManageTourPromise,
|
|
]);
|
|
const navigationLinks: NavigationLink[] = [
|
|
{
|
|
label: t("items.home"),
|
|
icon: IconHomeFilled,
|
|
href: "/manage",
|
|
"data-onboarding-tour-id": "manage-welcome",
|
|
},
|
|
{
|
|
icon: IconLayoutDashboardFilled,
|
|
href: "/manage/boards",
|
|
label: t("items.boards"),
|
|
"data-onboarding-tour-id": "manage-boards",
|
|
},
|
|
{
|
|
icon: IconBox,
|
|
href: "/manage/apps",
|
|
label: t("items.apps"),
|
|
hidden: !session?.user.permissions.includes("app-create"),
|
|
iconProps: {
|
|
strokeWidth: 2.5,
|
|
},
|
|
"data-onboarding-tour-id": "manage-apps",
|
|
},
|
|
{
|
|
icon: IconAffiliateFilled,
|
|
href: "/manage/integrations",
|
|
label: t("items.integrations"),
|
|
hidden: !session?.user.permissions.includes("integration-create"),
|
|
"data-onboarding-tour-id": "manage-integrations",
|
|
},
|
|
{
|
|
icon: IconApi,
|
|
href: "/manage/custom-widgets",
|
|
label: t("items.customWidgets"),
|
|
hidden: !session?.user.permissions.includes("admin"),
|
|
},
|
|
{
|
|
icon: IconBuildingStore,
|
|
href: "/manage/workshop",
|
|
label: t("items.workshop"),
|
|
hidden: !session?.user.permissions.includes("admin"),
|
|
},
|
|
{
|
|
icon: IconSearch,
|
|
href: "/manage/search-engines",
|
|
label: t("items.searchEngies"),
|
|
hidden: !session?.user.permissions.includes("search-engine-create"),
|
|
iconProps: {
|
|
strokeWidth: 2.5,
|
|
},
|
|
"data-onboarding-tour-id": "manage-search-engines",
|
|
},
|
|
{
|
|
icon: IconPhotoFilled,
|
|
href: "/manage/medias",
|
|
label: t("items.medias"),
|
|
hidden: !session?.user.permissions.includes("media-upload"),
|
|
"data-onboarding-tour-id": "manage-medias",
|
|
},
|
|
{
|
|
icon: IconUserFilled,
|
|
label: t("items.users.label"),
|
|
hidden: !session?.user.permissions.includes("admin"),
|
|
"data-onboarding-tour-id": "manage-users",
|
|
items: [
|
|
{
|
|
label: t("items.users.items.manage"),
|
|
icon: IconUsers,
|
|
href: "/manage/users",
|
|
},
|
|
{
|
|
label: t("items.users.items.invites"),
|
|
icon: IconMailForward,
|
|
href: "/manage/users/invites",
|
|
hidden: !isProviderEnabled("credentials"),
|
|
},
|
|
{
|
|
label: t("items.users.items.groups"),
|
|
icon: IconUsersGroup,
|
|
href: "/manage/users/groups",
|
|
},
|
|
],
|
|
},
|
|
{
|
|
label: t("items.tools.label"),
|
|
icon: IconPointerFilled,
|
|
// As permissions always include there children permissions, we can check other-view-logs as admin includes it
|
|
hidden: !session?.user.permissions.includes("other-view-logs"),
|
|
items: [
|
|
{
|
|
label: t("items.tools.items.docker"),
|
|
icon: IconBrandDocker,
|
|
href: "/manage/tools/docker",
|
|
hidden: !(session?.user.permissions.includes("admin") && env.ENABLE_DOCKER),
|
|
},
|
|
{
|
|
label: t("items.tools.items.kubernetes"),
|
|
icon: IconBox,
|
|
href: "/manage/tools/kubernetes",
|
|
hidden: !(session?.user.permissions.includes("admin") && env.ENABLE_KUBERNETES),
|
|
},
|
|
{
|
|
label: t("items.tools.items.api"),
|
|
icon: IconDirectionsFilled,
|
|
href: "/manage/tools/api",
|
|
hidden: !session?.user.permissions.includes("admin"),
|
|
},
|
|
{
|
|
label: t("items.tools.items.logs"),
|
|
icon: IconBrandTablerFilled,
|
|
href: "/manage/tools/logs",
|
|
hidden: !session?.user.permissions.includes("other-view-logs"),
|
|
},
|
|
{
|
|
label: t("items.tools.items.certificates"),
|
|
icon: IconCertificate,
|
|
href: "/manage/tools/certificates",
|
|
hidden: !session?.user.permissions.includes("admin"),
|
|
},
|
|
{
|
|
label: t("items.tools.items.tasks"),
|
|
icon: IconClipboardListFilled,
|
|
href: "/manage/tools/tasks",
|
|
hidden: !session?.user.permissions.includes("admin"),
|
|
},
|
|
{
|
|
label: t("items.tools.items.backup"),
|
|
icon: IconDatabaseExport,
|
|
href: "/manage/tools/backup",
|
|
hidden: !session?.user.permissions.includes("admin") || dbEnv.DRIVER !== "better-sqlite3",
|
|
},
|
|
],
|
|
},
|
|
{
|
|
label: t("items.assistant"),
|
|
href: "/manage/assistant",
|
|
icon: IconRobot,
|
|
hidden: !session?.user.permissions.includes("admin"),
|
|
},
|
|
{
|
|
label: t("items.settings"),
|
|
href: "/manage/settings",
|
|
icon: IconSettingsFilled,
|
|
hidden: !session?.user.permissions.includes("admin"),
|
|
"data-onboarding-tour-id": "manage-settings",
|
|
},
|
|
{
|
|
label: t("items.help.label"),
|
|
icon: IconHelpSquareRoundedFilled,
|
|
items: [
|
|
{
|
|
label: t("items.help.items.documentation"),
|
|
icon: IconBook2,
|
|
href: createDocumentationLink("/docs/getting-started"),
|
|
external: true,
|
|
},
|
|
{
|
|
label: t("items.help.items.submitIssue"),
|
|
icon: IconBrandGithub,
|
|
href: "https://github.com/homarr-labs/homarr/issues/new/choose",
|
|
external: true,
|
|
},
|
|
{
|
|
label: t("items.help.items.discord"),
|
|
icon: IconBrandDiscord,
|
|
href: "https://discord.com/invite/aCsmEV5RgA",
|
|
external: true,
|
|
},
|
|
{
|
|
label: t("items.help.items.sourceCode"),
|
|
icon: IconGitFork,
|
|
href: "https://github.com/homarr-labs/homarr",
|
|
external: true,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
label: t("items.about"),
|
|
icon: homarrLogoPath,
|
|
href: "/manage/about",
|
|
},
|
|
];
|
|
|
|
const isAdmin = session?.user.permissions.includes("admin") ?? false;
|
|
|
|
const shell = (
|
|
<ClientShell hasNavigation>
|
|
<MainHeader></MainHeader>
|
|
<MainNavigation links={navigationLinks}></MainNavigation>
|
|
<AppShellMain>{children}</AppShellMain>
|
|
</ClientShell>
|
|
);
|
|
|
|
return (
|
|
<ManageTourGate enabled={shouldRunManageTour} isAdmin={isAdmin}>
|
|
{shell}
|
|
</ManageTourGate>
|
|
);
|
|
}
|