271 lines
12 KiB
TypeScript
271 lines
12 KiB
TypeScript
import { Outlet, useLoaderData, useLocation, useNavigate, useParams } from "react-router";
|
|
import { useTranslation } from "react-i18next";
|
|
import { LoaderFunctionArgs, MetaFunction } from "react-router";
|
|
import { getTranslations } from "~/locale/i18next.server";
|
|
import UrlUtils from "~/utils/app/UrlUtils";
|
|
import { useEffect } from "react";
|
|
import { getUserHasPermission } from "~/utils/helpers/PermissionsHelper";
|
|
import { useAppOrAdminData } from "~/utils/data/useAppOrAdminData";
|
|
import { useAppData } from "~/utils/data/useAppData";
|
|
import SidebarIconsLayout, { IconDto } from "~/components/ui/layouts/SidebarIconsLayout";
|
|
import CustomerIcon from "~/components/ui/icons/settings/CustomerIcon";
|
|
import CustomerIconFilled from "~/components/ui/icons/settings/CustomerIconFilled";
|
|
import PeopleIcon from "~/components/ui/icons/settings/PeopleIcon";
|
|
import PeopleIconFilled from "~/components/ui/icons/settings/PeopleIconFilled";
|
|
import MembershipCardIcon from "~/components/ui/icons/settings/MembershipCardIcon";
|
|
import MembershipCardIconFilled from "~/components/ui/icons/settings/MembershipCardIconFilled";
|
|
import CompanyIcon from "~/components/ui/icons/crm/CompanyIcon";
|
|
import CompanyIconFilled from "~/components/ui/icons/crm/CompanyIconFilled";
|
|
import ActivityHistoryIcon from "~/components/ui/icons/entities/ActivityHistoryIcon";
|
|
import ActivityHistoryIconFilled from "~/components/ui/icons/entities/ActivityHistoryIconFilled";
|
|
import { MailIcon, PlugIcon } from "~/components/ui/icons/vendor";
|
|
import { isDemoDataUiEnabled } from "~/utils/services/.server/demoDataUi.server";
|
|
import { UI_NAV_IDS } from "~/application/ui/uiRegistry";
|
|
|
|
type LoaderData = {
|
|
title: string;
|
|
demoDataUiEnabled: boolean;
|
|
};
|
|
|
|
export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
|
const { t } = await getTranslations(request);
|
|
const data: LoaderData = {
|
|
title: `${t("app.navbar.settings")} | ${process.env.APP_NAME}`,
|
|
demoDataUiEnabled: isDemoDataUiEnabled(undefined, { tenantSlug: params.tenant }),
|
|
};
|
|
return data;
|
|
};
|
|
|
|
export const meta: MetaFunction<typeof loader> = ({ data }) => [{ title: data?.title }];
|
|
|
|
export default function SettingsRoute() {
|
|
const { t } = useTranslation();
|
|
const { demoDataUiEnabled } = useLoaderData<LoaderData>();
|
|
const navigate = useNavigate();
|
|
const location = useLocation();
|
|
const params = useParams();
|
|
const appOrAdminData = useAppOrAdminData();
|
|
const appData = useAppData();
|
|
const hasFeatureAccess = (featureKey: string) => appOrAdminData.productAccess?.[featureKey]?.allowed === true;
|
|
|
|
const getTabs = () => {
|
|
const tabs: IconDto[] = [];
|
|
// AK-SET-01 Hub A: Profil, Sicherheit, Benachrichtigungen und "Meine Daten"
|
|
// sind Tabs INNERHALB von "Mein Konto". Ungated — jeder verwaltet seine
|
|
// eigenen Einstellungen, und der DSGVO-Self-Service muss für alle
|
|
// erreichbar bleiben (DoD B6).
|
|
tabs.push({
|
|
name: t("settings.hubs.account.title"),
|
|
href: UrlUtils.currentTenantUrl(params, "settings/profile"),
|
|
icon: (
|
|
<span data-ui-id={UI_NAV_IDS.appSettingsAccount}>
|
|
<CustomerIcon className="size-4" aria-hidden="true" />
|
|
</span>
|
|
),
|
|
iconSelected: (
|
|
<span data-ui-id={UI_NAV_IDS.appSettingsAccount}>
|
|
<CustomerIconFilled className="size-4" aria-hidden="true" />
|
|
</span>
|
|
),
|
|
});
|
|
// AK-SET-01 Hub B: Mitglieder, Rollen und Gruppen sind Tabs INNERHALB von
|
|
// "Team & Zugriff". Welche Tabs erscheinen, entscheidet der Hub-Loader.
|
|
if (
|
|
getUserHasPermission(appOrAdminData, "app.settings.members.view") ||
|
|
getUserHasPermission(appOrAdminData, "app.settings.roles.view") ||
|
|
getUserHasPermission(appOrAdminData, "app.settings.groups.full")
|
|
) {
|
|
tabs.push({
|
|
name: t("settings.hubs.team.title"),
|
|
href: UrlUtils.currentTenantUrl(
|
|
params,
|
|
getUserHasPermission(appOrAdminData, "app.settings.members.view")
|
|
? "settings/team"
|
|
: getUserHasPermission(appOrAdminData, "app.settings.roles.view")
|
|
? "settings/team/roles"
|
|
: "settings/team/groups"
|
|
),
|
|
icon: (
|
|
<span data-ui-id={UI_NAV_IDS.appSettingsTeam}>
|
|
<PeopleIcon className="size-4" aria-hidden="true" />
|
|
</span>
|
|
),
|
|
iconSelected: (
|
|
<span data-ui-id={UI_NAV_IDS.appSettingsTeam}>
|
|
<PeopleIconFilled className="size-4" aria-hidden="true" />
|
|
</span>
|
|
),
|
|
});
|
|
}
|
|
// AK-SET-01 Hub D: Abo, Nutzung und Rechnungen sind jetzt Tabs INNERHALB von
|
|
// "Abrechnung" — hier steht nur noch der eine Hub-Eintrag. Sichtbar, sobald
|
|
// eine der beiden Permissions reicht; welche Tabs erscheinen, entscheidet
|
|
// der Hub-Loader.
|
|
if (
|
|
getUserHasPermission(appOrAdminData, "app.settings.subscription.view") ||
|
|
getUserHasPermission(appOrAdminData, "app.settings.subscription.invoices.view")
|
|
) {
|
|
tabs.push({
|
|
name: t("settings.hubs.billing.title"),
|
|
href: UrlUtils.currentTenantUrl(
|
|
params,
|
|
getUserHasPermission(appOrAdminData, "app.settings.subscription.view") ? "settings/billing" : "settings/billing/invoices"
|
|
),
|
|
icon: (
|
|
<span data-ui-id={UI_NAV_IDS.appSettingsBilling}>
|
|
<MembershipCardIcon className="size-4" aria-hidden="true" />
|
|
</span>
|
|
),
|
|
iconSelected: (
|
|
<span data-ui-id={UI_NAV_IDS.appSettingsBilling}>
|
|
<MembershipCardIconFilled className="size-4" aria-hidden="true" />
|
|
</span>
|
|
),
|
|
});
|
|
}
|
|
// AK-SET-01 Hub C: Stammdaten, Richtlinien und Demo-Daten sind Tabs INNERHALB
|
|
// von "Workspace" — hier steht nur noch der eine Hub-Eintrag. Welche Tabs
|
|
// erscheinen, entscheidet der Hub-Loader.
|
|
if (
|
|
getUserHasPermission(appOrAdminData, "app.settings.account.view") ||
|
|
(demoDataUiEnabled && getUserHasPermission(appOrAdminData, "app.onboarding.demoData.manage"))
|
|
) {
|
|
tabs.push({
|
|
name: t("settings.hubs.workspace.title"),
|
|
href: UrlUtils.currentTenantUrl(
|
|
params,
|
|
getUserHasPermission(appOrAdminData, "app.settings.account.view") ? "settings/workspace" : "settings/workspace/demo-data"
|
|
),
|
|
icon: (
|
|
<span data-ui-id={UI_NAV_IDS.appSettingsWorkspace}>
|
|
<CompanyIcon className="size-4" aria-hidden="true" />
|
|
</span>
|
|
),
|
|
iconSelected: (
|
|
<span data-ui-id={UI_NAV_IDS.appSettingsWorkspace}>
|
|
<CompanyIconFilled className="size-4" aria-hidden="true" />
|
|
</span>
|
|
),
|
|
});
|
|
}
|
|
if (getUserHasPermission(appOrAdminData, "portal.read") || getUserHasPermission(appOrAdminData, "portal.admin")) {
|
|
tabs.push({
|
|
name: t("customerPortal.admin.title"),
|
|
href: UrlUtils.currentTenantUrl(
|
|
params,
|
|
getUserHasPermission(appOrAdminData, "portal.read") ? "settings/customer-portal" : "settings/customer-portal/email-templates"
|
|
),
|
|
icon: (
|
|
<span data-ui-id={UI_NAV_IDS.appSettingsCustomerPortal}>
|
|
<MailIcon className="size-4" aria-hidden="true" />
|
|
</span>
|
|
),
|
|
iconSelected: (
|
|
<span data-ui-id={UI_NAV_IDS.appSettingsCustomerPortal}>
|
|
<MailIcon className="size-4" aria-hidden="true" />
|
|
</span>
|
|
),
|
|
});
|
|
}
|
|
// AK-SET-01 Hub E: Katalog, Postfächer, Kalender, Telefonie, Plugins und
|
|
// API-Schlüssel sind Tabs INNERHALB von "Erweiterungen" — hier steht nur noch
|
|
// der eine Hub-Eintrag. Welche Tabs erscheinen, entscheidet der Hub-Loader.
|
|
const canOpenIntegrationCatalog = hasFeatureAccess("integrations") && getUserHasPermission(appOrAdminData, "integrations.read");
|
|
const canOpenEmail =
|
|
hasFeatureAccess("email-inbox") && (getUserHasPermission(appOrAdminData, "email.read_own") || getUserHasPermission(appOrAdminData, "email.read_all"));
|
|
const canOpenCalendar =
|
|
hasFeatureAccess("integrations") &&
|
|
(getUserHasPermission(appOrAdminData, "calendar.connect_own") || getUserHasPermission(appOrAdminData, "calendar.admin"));
|
|
const canOpenTelephony = hasFeatureAccess("telephony") && getUserHasPermission(appOrAdminData, "telephony.manage");
|
|
const canOpenPlugins = getUserHasPermission(appOrAdminData, "app.plugins.use");
|
|
const canOpenApi = hasFeatureAccess("api") && getUserHasPermission(appOrAdminData, "app.settings.apiKeys.view");
|
|
const firstIntegrationPath = canOpenIntegrationCatalog
|
|
? "settings/integrations"
|
|
: canOpenEmail
|
|
? "settings/integrations/email"
|
|
: canOpenCalendar
|
|
? "settings/integrations/calendar"
|
|
: canOpenTelephony
|
|
? "settings/integrations/telephony"
|
|
: canOpenPlugins
|
|
? "settings/integrations/plugins"
|
|
: "settings/integrations/api";
|
|
if (canOpenIntegrationCatalog || canOpenEmail || canOpenCalendar || canOpenTelephony || canOpenPlugins || canOpenApi) {
|
|
tabs.push({
|
|
name: t("settings.hubs.integrations.title"),
|
|
href: UrlUtils.currentTenantUrl(params, firstIntegrationPath),
|
|
icon: (
|
|
<span data-ui-id={UI_NAV_IDS.appSettingsIntegrations}>
|
|
<PlugIcon className="size-4" aria-hidden="true" />
|
|
</span>
|
|
),
|
|
iconSelected: (
|
|
<span data-ui-id={UI_NAV_IDS.appSettingsIntegrations}>
|
|
<PlugIcon className="size-4" aria-hidden="true" />
|
|
</span>
|
|
),
|
|
});
|
|
}
|
|
// AK-SET-01 Hub F: Audit-Log, Audit-Export, Chat-Audit und die
|
|
// Datenschutz-Verwaltung sind Tabs INNERHALB von "Compliance & Protokolle".
|
|
const canOpenAudit = getUserHasPermission(appOrAdminData, "app.settings.auditTrails.view");
|
|
const canOpenChatAudit = hasFeatureAccess("chat") && getUserHasPermission(appOrAdminData, "chat.read_all_channels");
|
|
const canOpenTenantExport = getUserHasPermission(appOrAdminData, "privacy.tenant_export");
|
|
const canOpenAvv = getUserHasPermission(appOrAdminData, "privacy.avv.read");
|
|
const canOpenSubprocessors = getUserHasPermission(appOrAdminData, "privacy.subprocessors.read");
|
|
const canOpenTenantDeletion = getUserHasPermission(appOrAdminData, "privacy.tenant_deletion");
|
|
const firstCompliancePath = canOpenAudit
|
|
? "settings/compliance"
|
|
: canOpenChatAudit
|
|
? "settings/compliance/chat"
|
|
: canOpenTenantExport
|
|
? "settings/compliance/data-export"
|
|
: canOpenAvv
|
|
? "settings/compliance/avv"
|
|
: canOpenSubprocessors
|
|
? "settings/compliance/subprocessors"
|
|
: "settings/compliance/tenant-deletion";
|
|
if (canOpenAudit || canOpenChatAudit || canOpenTenantExport || canOpenAvv || canOpenSubprocessors || canOpenTenantDeletion) {
|
|
tabs.push({
|
|
name: t("settings.hubs.compliance.title"),
|
|
href: UrlUtils.currentTenantUrl(params, firstCompliancePath),
|
|
icon: (
|
|
<span data-ui-id={UI_NAV_IDS.appSettingsCompliance}>
|
|
<ActivityHistoryIcon className="size-4" aria-hidden="true" />
|
|
</span>
|
|
),
|
|
iconSelected: (
|
|
<span data-ui-id={UI_NAV_IDS.appSettingsCompliance}>
|
|
<ActivityHistoryIconFilled className="size-4" aria-hidden="true" />
|
|
</span>
|
|
),
|
|
});
|
|
}
|
|
// setTabs(tabs);
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
return tabs;
|
|
};
|
|
|
|
useEffect(() => {
|
|
if (UrlUtils.stripTrailingSlash(location.pathname) === UrlUtils.currentTenantUrl(params, "settings")) {
|
|
navigate(UrlUtils.currentTenantUrl(params, "settings/profile"));
|
|
}
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [location.pathname]);
|
|
|
|
// The activation route is intentionally outside the regular settings rail.
|
|
// The app loader also derives this flag from a persisted signup selection,
|
|
// even when subscription enforcement is globally optional on staging.
|
|
if (appData.subscriptionActivationRequired === true) {
|
|
return <Outlet />;
|
|
}
|
|
|
|
return (
|
|
<SidebarIconsLayout label={{ align: "right" }} items={getTabs()} sticky>
|
|
<Outlet />
|
|
</SidebarIconsLayout>
|
|
);
|
|
}
|