Reorganize repo structure and standards references
This commit is contained in:
1 parent
3cb93a81be
commit
be2054274d
5885 files changed
+2588
-195
No files matched your search
+65
@@ -0,0 +1,65 @@
|
||||
import { LoaderFunctionArgs, MetaFunction, useLoaderData } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Outlet } from "react-router";
|
||||
import { getTranslations } from "~/locale/i18next.server";
|
||||
import { getUserPermission } from "~/utils/helpers/.server/PermissionsService";
|
||||
import { getTenantIdFromUrl } from "~/utils/services/.server/urlService";
|
||||
import { getAllGroups, getMyGroups, GroupWithDetails } from "~/utils/db/permissions/groups.db.server";
|
||||
import { getUserInfo } from "~/utils/session.server";
|
||||
import EditPageLayout from "~/components/ui/layouts/EditPageLayout";
|
||||
import GroupsListView from "~/modules/users/components/GroupsListView";
|
||||
import { useRootData } from "~/utils/data/useRootData";
|
||||
import { useAppData } from "~/utils/data/useAppData";
|
||||
import { getUserHasPermission } from "~/utils/helpers/PermissionsHelper";
|
||||
import InfoBanner from "~/components/ui/banners/InfoBanner";
|
||||
import { requireAuth } from "~/utils/loaders.middleware";
|
||||
|
||||
type LoaderData = {
|
||||
title: string;
|
||||
items: GroupWithDetails[];
|
||||
};
|
||||
|
||||
export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
||||
await requireAuth({ request, params });
|
||||
const { t } = await getTranslations(request);
|
||||
const tenantId = await getTenantIdFromUrl(params);
|
||||
const userInfo = await getUserInfo(request);
|
||||
|
||||
const { permission, userPermission } = await getUserPermission({
|
||||
userId: userInfo.userId,
|
||||
permissionName: "app.settings.groups.full",
|
||||
tenantId: tenantId,
|
||||
});
|
||||
let items: GroupWithDetails[];
|
||||
if (!permission || userPermission) {
|
||||
items = await getAllGroups(tenantId);
|
||||
} else {
|
||||
items = await getMyGroups(userInfo.userId, tenantId);
|
||||
}
|
||||
|
||||
const data: LoaderData = {
|
||||
title: `${t("models.group.plural")} | ${process.env.APP_NAME}`,
|
||||
items,
|
||||
};
|
||||
return data;
|
||||
};
|
||||
|
||||
export const meta: MetaFunction<typeof loader> = ({ data }) => [{ title: data?.title }];
|
||||
|
||||
export default function RolesRoute() {
|
||||
const data = useLoaderData<LoaderData>();
|
||||
const rootData = useRootData();
|
||||
const appData = useAppData();
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<EditPageLayout>
|
||||
{rootData.featureFlags?.includes("row-groups") ? (
|
||||
<GroupsListView items={data.items} canManage={getUserHasPermission(appData, "app.settings.groups.full")} />
|
||||
) : (
|
||||
<InfoBanner title={t("settings.groups.disabled.title")} text={t("settings.groups.disabled.description")} />
|
||||
)}
|
||||
<Outlet />
|
||||
</EditPageLayout>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user