52 lines
2.0 KiB
TypeScript
52 lines
2.0 KiB
TypeScript
import { LoaderFunctionArgs, MetaFunction, redirect } from "react-router";
|
|
import { Outlet, useLocation, useNavigate, useParams } from "react-router";
|
|
import { getTranslations } from "~/locale/i18next.server";
|
|
import { useEffect } from "react";
|
|
import { getTenantIdFromUrl } from "~/utils/services/.server/urlService";
|
|
import { verifyUserHasPermission } from "~/utils/helpers/.server/PermissionsService";
|
|
import UrlUtils from "~/utils/app/UrlUtils";
|
|
|
|
// R-P2b — D-P2 restructure: one merged "Rollen und Berechtigungen" tab (S02).
|
|
// The old users/permissions sub-tabs redirect (matrix → members D01 dropdown,
|
|
// permissions → role editor M02); the tab bar lives in MembersPage/RolesPage.
|
|
|
|
export const meta: MetaFunction<typeof loader> = ({ data }) => [{ title: data?.title }];
|
|
|
|
type LoaderData = {
|
|
title: string;
|
|
};
|
|
|
|
export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
|
const { t } = await getTranslations(request);
|
|
const tenantId = await getTenantIdFromUrl(params);
|
|
await verifyUserHasPermission(request, "app.settings.roles.view", tenantId);
|
|
|
|
if (UrlUtils.stripTrailingSlash(new URL(request.url).pathname) === UrlUtils.currentTenantUrl(params, "settings/roles-and-permissions")) {
|
|
throw redirect(UrlUtils.currentTenantUrl(params, "settings/roles-and-permissions/roles"));
|
|
}
|
|
|
|
const data: LoaderData = {
|
|
title: `${t("models.role.plural")} | ${process.env.APP_NAME}`,
|
|
};
|
|
return data;
|
|
};
|
|
|
|
export default function RolesAndPermissionsShell() {
|
|
const params = useParams();
|
|
const location = useLocation();
|
|
const navigate = useNavigate();
|
|
|
|
useEffect(() => {
|
|
if (UrlUtils.stripTrailingSlash(location.pathname) === UrlUtils.currentTenantUrl(params, "settings/roles-and-permissions")) {
|
|
navigate(UrlUtils.currentTenantUrl(params, "settings/roles-and-permissions/roles"));
|
|
}
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [location.pathname]);
|
|
|
|
return (
|
|
<div data-ui-id="ui.settings.rolesAndPermissions.page" className="w-full">
|
|
<Outlet />
|
|
</div>
|
|
);
|
|
}
|