Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/apps/web/app/application/sidebar/AppSidebar.tsx
T
2026-07-08 16:15:37 +02:00

306 lines
9.9 KiB
TypeScript

import { SideBarItem } from "./SidebarItem";
import { TFunction, type i18n as I18n } from "i18next";
import { AppConfiguration } from "~/utils/db/appConfiguration.db.server";
import IconSettings from "~/components/layouts/icons/IconSettings";
import IconDashboard from "~/components/layouts/icons/IconDashboard";
import IconAdmin from "~/components/layouts/icons/IconAdmin";
import IconNotifications from "~/components/layouts/icons/IconNotifications";
import IconEmails from "~/components/layouts/icons/IconEmails";
import IconKeys from "~/components/layouts/icons/IconKeys";
import IconWorkflows from "~/components/layouts/icons/IconWorkflows";
import AddressBookIcon from "~/components/ui/icons/crm/AddressBookIcon";
import IconDocs from "~/components/layouts/icons/IconDocs";
import ViewListIcon from "~/components/ui/icons/ViewListIcon";
import CalendarIcon from "~/components/ui/icons/CalendarIcon";
import { UI_NAV_IDS } from "~/application/ui/uiRegistry";
import { appPath } from "~/utils/app/CanonicalUrlUtils";
import { absoluteAdminPath, type PublicDomainRoutingConfig } from "~/utils/app/CrossHostUrls";
import { resolveConnectorNavState } from "~/utils/connector/connectorNavState";
import { WALKING_SKELETON_MODULE_KEY } from "~/modules/walkingSkeleton/constants";
import { SearchIcon } from "~/components/ui/icons/vendor";
type Props = {
t: TFunction;
i18n: I18n;
tenantId: string;
appConfiguration: AppConfiguration | null;
routing?: PublicDomainRoutingConfig;
productAccess?: Record<string, { allowed: boolean; reason?: string }>;
};
export const AppSidebar = ({ t, tenantId, routing, productAccess }: Props): SideBarItem[] => {
const tenantPath = (path?: string) => appPath({ tenantSlug: tenantId, path, mode: "host-aware" });
const hasFeatureAccess = (featureKey: string) => productAccess?.[featureKey]?.allowed === true;
const hasDashboardAccess = productAccess ? hasFeatureAccess("dashboard") : true;
// R-P1c Konnektor-Demo: Walking-Skeleton-Eintrag zeigt die drei Gate-Zustaende (aktiv/gesperrt/ausgeblendet).
const walkingSkeletonDecision = productAccess?.[WALKING_SKELETON_MODULE_KEY];
const walkingSkeletonState = walkingSkeletonDecision ? resolveConnectorNavState(walkingSkeletonDecision) : "hidden";
const productCoreItems: SideBarItem[] = [
...(hasFeatureAccess("search")
? [
{
id: UI_NAV_IDS.appSearch,
title: t("search.nav.title"),
path: tenantPath("search"),
icon: <SearchIcon />,
permission: "search.use" as const,
},
]
: []),
...(hasFeatureAccess("automation")
? [
{
id: UI_NAV_IDS.appAutomation,
title: t("automation.nav.title"),
path: tenantPath("automations"),
icon: <IconWorkflows />,
permission: "automation.read" as const,
},
]
: []),
...(hasFeatureAccess("crm-basic")
? [
{
id: UI_NAV_IDS.appCrm,
title: t("crm:title"),
// R-P6: typed CRM contacts replace the entity-builder CRM (/crm → /contacts).
path: tenantPath("contacts"),
icon: <AddressBookIcon />,
permission: "crm.read_own" as const,
},
]
: []),
...(hasFeatureAccess("leads")
? [
{
id: UI_NAV_IDS.appLeads,
title: t("leads.nav.title"),
path: tenantPath("leads"),
icon: <ViewListIcon />,
permission: "leads.read_own" as const,
},
]
: []),
...(hasFeatureAccess("projects")
? [
{
id: UI_NAV_IDS.appProjects,
title: t("projects.nav.title"),
path: tenantPath("projects"),
icon: <ViewListIcon />,
permission: "projects.read_own" as const,
},
]
: []),
...(hasFeatureAccess("files")
? [
{
id: "ui.nav.app.files",
title: t("files.nav.title"),
path: tenantPath("files"),
icon: <IconDocs />,
permission: "files.read_own" as const,
},
]
: []),
...(hasFeatureAccess("tasks")
? [
{
id: "ui.nav.app.tasks",
title: t("tasks.nav.title"),
path: tenantPath("tasks"),
icon: <ViewListIcon />,
permission: "tasks.read_own" as const,
},
]
: []),
...(hasFeatureAccess("hr")
? [
{
id: "ui.nav.app.hr",
title: t("hr.nav.title"),
path: tenantPath("hr"),
icon: <AddressBookIcon />,
permission: "hr.read_own" as const,
},
]
: []),
...(hasFeatureAccess("integrations")
? [
{
id: "ui.nav.app.integrations",
title: t("integrations.nav.title"),
path: tenantPath("integrations"),
icon: <IconWorkflows />,
permission: "integrations.read" as const,
},
]
: []),
...(hasFeatureAccess("integrations")
? [
{
// AK-P16a · calendar reuses the integrations feature gate (it is an
// Apps-Engine integration); the entry is gated by calendar.connect_own.
id: UI_NAV_IDS.appCalendar,
title: t("calendar.nav.title"),
path: tenantPath("calendar"),
icon: <CalendarIcon />,
permission: "calendar.connect_own" as const,
},
]
: []),
...(hasFeatureAccess("email-inbox")
? [
{
// VA-P23 · mailbox sync inbox — own `email-inbox` feature gate; the
// entry is gated by email.read_own (own-mailbox visibility, M09 I).
id: UI_NAV_IDS.appEmails,
title: t("emailInbox.nav.title"),
path: tenantPath("emails"),
icon: <IconEmails className="h-5 w-5" />,
permission: "email.read_own" as const,
},
]
: []),
...(hasFeatureAccess("booking")
? [
{
// AK-P16b · Booking module — own `booking` feature gate; the entry is
// gated by bookings.read_own (every provider can see their own bookings).
id: UI_NAV_IDS.appBookings,
title: t("bookings.nav.title"),
path: tenantPath("bookings"),
icon: <CalendarIcon />,
permission: "bookings.read_own" as const,
},
]
: []),
...(hasFeatureAccess("forms")
? [
{
id: UI_NAV_IDS.appForms,
title: t("settings.forms.admin.title"),
path: tenantPath("forms"),
icon: <ViewListIcon />,
permission: "forms.basic" as const,
},
]
: []),
...(hasFeatureAccess("email-marketing")
? [
{
id: UI_NAV_IDS.appEmailMarketing,
title: t("emailMarketing:title"),
path: tenantPath("email-marketing"),
icon: <IconEmails />,
},
]
: []),
...(hasFeatureAccess("workflow-engine")
? [
{
id: UI_NAV_IDS.appWorkflowEngine,
title: t("workflows.title"),
path: tenantPath("workflow-engine"),
icon: <IconWorkflows />,
},
]
: []),
...(hasFeatureAccess("api")
? [
{
id: UI_NAV_IDS.appApi,
title: t("models.apiKey.plural"),
path: tenantPath("settings/api"),
icon: <IconKeys />,
},
]
: []),
...(walkingSkeletonState !== "hidden"
? [
{
id: "ui.nav.app.walkingSkeleton",
title: t("walkingSkeleton.nav"),
path: tenantPath("walking-skeleton"),
icon: <IconDashboard />,
disabled: walkingSkeletonState === "locked",
},
]
: []),
];
const appItem: SideBarItem = {
id: "ui.nav.app.primary",
title: "",
path: "",
items: [
...(hasDashboardAccess
? [
{
id: UI_NAV_IDS.appDashboard,
title: t("app.sidebar.dashboard"),
path: tenantPath("dashboard"),
icon: <IconDashboard />,
permission: "dashboard.read" as const,
// tenantUserTypes: [TenantUserType.OWNER, TenantUserType.ADMIN, TenantUserType.MEMBER],
},
]
: []),
{
id: UI_NAV_IDS.appNotifications,
title: t("app.sidebar.notifications"),
path: tenantPath("notifications"),
icon: <IconNotifications />,
},
...productCoreItems,
// {
// title: t("models.email.plural"),
// path: `${currentTenantUrl}/emails`,
// icon: SvgIcon.EMAILS,
// },
],
};
return [
appItem,
{
id: "ui.nav.app.secondary",
title: "",
path: "",
isSecondary: true,
items: [
{
id: UI_NAV_IDS.appSettings,
title: t("app.sidebar.settings"),
icon: <IconSettings />,
// tenantUserTypes: [TenantUserType.OWNER, TenantUserType.ADMIN],
path: tenantPath("settings"),
redirectTo: tenantPath("settings/profile"),
},
// {
// title: t("app.sidebar.logs"),
// icon: SvgIcon.LOGS,
// tenantUserTypes: [TenantUserType.OWNER, TenantUserType.ADMIN],
// path: `${currentTenantUrl}/logs`,
// },
{
id: UI_NAV_IDS.appSwitchToAdmin,
title: t("admin.switchToAdmin"),
path: absoluteAdminPath(routing, "dashboard"),
icon: <IconAdmin />,
adminOnly: true,
},
],
},
];
};
// function SideText({ text }: { text: string }) {
// return (
// <div className="inline-flex justify-center space-x-1 items-center px-1.5 py-0.5 rounded-sm text-xs font-medium bg-yellow-100 text-yellow-900 italic truncate w-20">
// <div className="truncate">{text}</div>
// </div>
// );
// }