452 lines
15 KiB
TypeScript
452 lines
15 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 IconEmails from "~/components/layouts/icons/IconEmails";
|
|
import IconWorkflows from "~/components/layouts/icons/IconWorkflows";
|
|
import AddressBookIcon from "~/components/ui/icons/crm/AddressBookIcon";
|
|
import CalendarCheckIcon from "~/components/ui/icons/CalendarCheckIcon";
|
|
import CalendarClockIcon from "~/components/ui/icons/CalendarClockIcon";
|
|
import CalendarDaysIcon from "~/components/ui/icons/CalendarDaysIcon";
|
|
import CalendarRangeIcon from "~/components/ui/icons/CalendarRangeIcon";
|
|
import InboxIcon from "~/components/ui/icons/emails/InboxIcon";
|
|
import MegaphoneIcon from "~/components/ui/icons/emails/MegaphoneIcon";
|
|
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 { ClipboardIcon, FileTextIcon, LockIcon, PhoneIcon, ShieldCheckIcon, TrendingUpIcon, UserIcon } from "~/components/ui/icons/vendor";
|
|
import BoardIcon from "~/components/ui/icons/BoardIcon";
|
|
import ComboChartIcon from "~/components/ui/icons/ComboChartIcon";
|
|
import DataSourceIcon from "~/components/ui/icons/DataSourceIcon";
|
|
import TableIcon from "~/components/ui/icons/TableIcon";
|
|
import ChatAltIcon from "~/components/ui/icons/ChatAltIcon";
|
|
|
|
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 overviewItems: SideBarItem[] = [
|
|
...(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],
|
|
},
|
|
]
|
|
: []),
|
|
];
|
|
|
|
const crmContextItems: SideBarItem[] = [
|
|
...(hasFeatureAccess("crm-basic")
|
|
? [
|
|
{
|
|
id: "ui.nav.app.crm.contacts",
|
|
title: t("crm.contacts.title"),
|
|
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: <TrendingUpIcon />,
|
|
permission: "leads.read_own" as const,
|
|
// Leads is a workspace area: inbox/board plus the two admin screens
|
|
// share an inner sub-sidenav (rendered by app.$tenant when >1 item
|
|
// is visible — non-admins only see the inbox, so no rail for them).
|
|
activePaths: [tenantPath("leads"), tenantPath("leads-statistics"), tenantPath("admin/lead-sources"), tenantPath("admin/lead-anti-spam")],
|
|
contextItems: [
|
|
{
|
|
id: "ui.nav.app.leads.inbox",
|
|
title: t("leads.list.title"),
|
|
path: tenantPath("leads"),
|
|
icon: <InboxIcon />,
|
|
permission: "leads.read_own" as const,
|
|
},
|
|
{
|
|
id: "ui.nav.app.leads.statistics",
|
|
title: t("leads.statistics.title"),
|
|
path: tenantPath("leads-statistics"),
|
|
icon: <ComboChartIcon />,
|
|
permission: "leads.read_own" as const,
|
|
},
|
|
{
|
|
id: "ui.nav.app.leads.sources",
|
|
title: t("leads.sources.title"),
|
|
path: tenantPath("admin/lead-sources"),
|
|
icon: <DataSourceIcon />,
|
|
permission: "leads.admin" as const,
|
|
},
|
|
{
|
|
id: "ui.nav.app.leads.antiSpam",
|
|
title: t("leads.antiSpam.title"),
|
|
path: tenantPath("admin/lead-anti-spam"),
|
|
icon: <ShieldCheckIcon />,
|
|
permission: "leads.admin" as const,
|
|
},
|
|
],
|
|
},
|
|
]
|
|
: []),
|
|
];
|
|
|
|
const projectContextItems: SideBarItem[] = [
|
|
...(hasFeatureAccess("projects")
|
|
? [
|
|
{
|
|
// WF-P8 S00 (Subframe 2026-07-15): the boards start page is the
|
|
// module entry; the kanban/list/detail routes under /projects keep
|
|
// this consolidated entry highlighted via activePaths.
|
|
id: "ui.nav.app.projects.boards",
|
|
title: t("projects.boards.nav"),
|
|
path: tenantPath("projects/boards"),
|
|
icon: <BoardIcon />,
|
|
permission: "projects.read_own" as const,
|
|
activePaths: [tenantPath("projects")],
|
|
// Plantafel is its own sidebar entry but lives under /projects.
|
|
excludePaths: [tenantPath("projects/plantafel")],
|
|
},
|
|
{
|
|
id: UI_NAV_IDS.appPlantafel,
|
|
title: t("projects.nav.plantafel"),
|
|
path: tenantPath("projects/plantafel"),
|
|
icon: <CalendarRangeIcon />,
|
|
permission: "plantafel.read_own" as const,
|
|
},
|
|
]
|
|
: []),
|
|
];
|
|
|
|
const communicationContextItems: SideBarItem[] = [
|
|
...(hasFeatureAccess("email-inbox")
|
|
? [
|
|
{
|
|
id: UI_NAV_IDS.appEmails,
|
|
title: t("emailInbox.nav.title"),
|
|
path: tenantPath("emails"),
|
|
icon: <IconEmails />,
|
|
permission: "email.read_own" as const,
|
|
},
|
|
]
|
|
: []),
|
|
...(hasFeatureAccess("email-marketing")
|
|
? [
|
|
{
|
|
id: UI_NAV_IDS.appEmailMarketing,
|
|
title: t("emailMarketing:title"),
|
|
path: tenantPath("email-marketing"),
|
|
icon: <MegaphoneIcon />,
|
|
permission: "emailMarketing.view" as const,
|
|
},
|
|
]
|
|
: []),
|
|
...(hasFeatureAccess("forms")
|
|
? [
|
|
{
|
|
id: UI_NAV_IDS.appForms,
|
|
title: t("settings.forms.admin.title"),
|
|
path: tenantPath("forms"),
|
|
icon: <TableIcon />,
|
|
permission: "forms.basic" as const,
|
|
},
|
|
]
|
|
: []),
|
|
...(hasFeatureAccess("telephony")
|
|
? [
|
|
{
|
|
id: UI_NAV_IDS.appTelephony,
|
|
title: t("telephony.nav.title"),
|
|
path: tenantPath("calls"),
|
|
icon: <PhoneIcon />,
|
|
permission: "telephony.read_own" as const,
|
|
},
|
|
]
|
|
: []),
|
|
];
|
|
|
|
const appointmentContextItems: SideBarItem[] = [
|
|
...(hasFeatureAccess("integrations")
|
|
? [
|
|
{
|
|
id: UI_NAV_IDS.appCalendar,
|
|
title: t("calendar.nav.title"),
|
|
path: tenantPath("calendar"),
|
|
icon: <CalendarDaysIcon />,
|
|
permission: "calendar.connect_own" as const,
|
|
},
|
|
]
|
|
: []),
|
|
...(hasFeatureAccess("booking")
|
|
? [
|
|
{
|
|
id: UI_NAV_IDS.appBookings,
|
|
title: t("bookings.nav.title"),
|
|
path: tenantPath("bookings"),
|
|
icon: <CalendarCheckIcon />,
|
|
permission: "bookings.read_own" as const,
|
|
},
|
|
{
|
|
id: UI_NAV_IDS.appAvailability,
|
|
title: t("bookings.availability.title"),
|
|
path: tenantPath("availability"),
|
|
icon: <CalendarClockIcon />,
|
|
permission: "bookings.read_own" as const,
|
|
},
|
|
]
|
|
: []),
|
|
];
|
|
|
|
const workspaceArea = ({
|
|
id,
|
|
title,
|
|
icon,
|
|
contextItems,
|
|
}: {
|
|
id: string;
|
|
title: string;
|
|
icon: SideBarItem["icon"];
|
|
contextItems: SideBarItem[];
|
|
}): SideBarItem | null => {
|
|
const firstItem = contextItems[0];
|
|
if (!firstItem) return null;
|
|
return {
|
|
id,
|
|
title,
|
|
path: firstItem.path,
|
|
icon,
|
|
activePaths: contextItems.map((item) => item.path),
|
|
contextItems,
|
|
};
|
|
};
|
|
|
|
const appointmentsArea = workspaceArea({
|
|
id: "ui.nav.app.appointments",
|
|
title: t("app.sidebar.areas.appointments"),
|
|
icon: <CalendarDaysIcon />,
|
|
contextItems: appointmentContextItems,
|
|
});
|
|
|
|
const taskItems: SideBarItem[] = [
|
|
...(hasFeatureAccess("tasks")
|
|
? [
|
|
{
|
|
id: "ui.nav.app.tasks",
|
|
title: t("tasks.nav.title"),
|
|
path: tenantPath("tasks"),
|
|
icon: <ClipboardIcon />,
|
|
permission: "tasks.read_own" as const,
|
|
},
|
|
]
|
|
: []),
|
|
];
|
|
|
|
const fileItems: SideBarItem[] = [
|
|
...(hasFeatureAccess("files")
|
|
? [
|
|
{
|
|
id: "ui.nav.app.files",
|
|
title: t("files.nav.title"),
|
|
path: tenantPath("files"),
|
|
icon: <FileTextIcon />,
|
|
permission: "files.read_own" as const,
|
|
},
|
|
]
|
|
: []),
|
|
];
|
|
|
|
const hrItems: SideBarItem[] = [
|
|
...(hasFeatureAccess("hr")
|
|
? [
|
|
{
|
|
id: UI_NAV_IDS.appHr,
|
|
title: t("hr.nav.title"),
|
|
path: tenantPath("hr"),
|
|
icon: <UserIcon />,
|
|
permission: "hr.read_own" as const,
|
|
},
|
|
]
|
|
: []),
|
|
];
|
|
|
|
const passwordSafeItems: SideBarItem[] = [
|
|
...(hasFeatureAccess("hr")
|
|
? [
|
|
{
|
|
id: UI_NAV_IDS.appPasswordSafe,
|
|
title: t("hr.passwordSafe.title"),
|
|
path: tenantPath("passwords"),
|
|
icon: <LockIcon />,
|
|
anyPermissions: ["hr.passwordsafe.use" as const, "hr.passwordsafe.admin" as const],
|
|
activePaths: [tenantPath("passwords")],
|
|
contextItems: [
|
|
{
|
|
id: "ui.nav.app.passwordSafe.vaults",
|
|
title: t("hr.passwordSafe.nav.vaults"),
|
|
path: tenantPath("passwords"),
|
|
icon: <LockIcon />,
|
|
permission: "hr.passwordsafe.use" as const,
|
|
exact: true,
|
|
},
|
|
{
|
|
id: "ui.nav.app.passwordSafe.admin",
|
|
title: t("hr.passwordSafe.nav.admin"),
|
|
path: tenantPath("passwords/admin"),
|
|
icon: <ShieldCheckIcon />,
|
|
permission: "hr.passwordsafe.admin" as const,
|
|
},
|
|
],
|
|
},
|
|
]
|
|
: []),
|
|
];
|
|
|
|
const chatItems: SideBarItem[] = [
|
|
...(hasFeatureAccess("chat")
|
|
? [
|
|
{
|
|
id: UI_NAV_IDS.appChat,
|
|
title: t("chat.nav.title"),
|
|
path: tenantPath("chat"),
|
|
icon: <ChatAltIcon />,
|
|
permission: "chat.read_own_channels" as const,
|
|
},
|
|
]
|
|
: []),
|
|
];
|
|
|
|
const automationItems: SideBarItem[] = [
|
|
...(hasFeatureAccess("automation")
|
|
? [
|
|
{
|
|
id: UI_NAV_IDS.appAutomation,
|
|
title: t("automation.nav.title"),
|
|
path: tenantPath("automations"),
|
|
icon: <IconWorkflows />,
|
|
permission: "automation.read" as const,
|
|
},
|
|
]
|
|
: []),
|
|
...(walkingSkeletonState !== "hidden"
|
|
? [
|
|
{
|
|
id: "ui.nav.app.walkingSkeleton",
|
|
title: t("walkingSkeleton.nav"),
|
|
path: tenantPath("walking-skeleton"),
|
|
icon: <IconDashboard />,
|
|
disabled: walkingSkeletonState === "locked",
|
|
},
|
|
]
|
|
: []),
|
|
];
|
|
|
|
const startItems = [...overviewItems, ...taskItems];
|
|
const customerItems = crmContextItems.map((item, index) => (index === 0 ? { ...item, id: UI_NAV_IDS.appCrm, title: t("crm:title") } : item));
|
|
const projectItems = [...projectContextItems.map((item, index) => (index === 0 ? { ...item, id: UI_NAV_IDS.appProjects } : item)), ...fileItems];
|
|
const organizationItems = [...(appointmentsArea ? [appointmentsArea] : []), ...chatItems, ...hrItems, ...passwordSafeItems];
|
|
|
|
const navigationGroups: SideBarItem[] = [
|
|
{
|
|
id: "ui.nav.app.overview",
|
|
title: "",
|
|
path: "",
|
|
items: startItems,
|
|
},
|
|
{
|
|
id: "ui.nav.app.customers",
|
|
title: t("app.sidebar.sections.customers"),
|
|
path: "",
|
|
items: customerItems,
|
|
},
|
|
{
|
|
id: "ui.nav.app.projects",
|
|
title: t("app.sidebar.sections.projects"),
|
|
path: "",
|
|
items: projectItems,
|
|
},
|
|
{
|
|
id: "ui.nav.app.communication",
|
|
title: t("app.sidebar.sections.communication"),
|
|
path: "",
|
|
items: communicationContextItems,
|
|
},
|
|
{
|
|
id: "ui.nav.app.organization",
|
|
title: t("app.sidebar.sections.organization"),
|
|
path: "",
|
|
items: organizationItems,
|
|
},
|
|
{
|
|
id: "ui.nav.app.automationPlatform",
|
|
title: t("app.sidebar.sections.automationPlatform"),
|
|
path: "",
|
|
items: automationItems,
|
|
},
|
|
].filter((group) => (group.items?.length ?? 0) > 0);
|
|
|
|
const secondaryItem: SideBarItem = {
|
|
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,
|
|
},
|
|
],
|
|
};
|
|
|
|
return [...navigationGroups, secondaryItem];
|
|
};
|
|
|
|
// 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>
|
|
// );
|
|
// }
|