49 lines
1.9 KiB
TypeScript
49 lines
1.9 KiB
TypeScript
import { LoaderFunctionArgs, Outlet, useLoaderData, useParams } from "react-router";
|
|
import { useTranslation } from "react-i18next";
|
|
import ApiKeysTable from "~/components/core/apiKeys/ApiKeysTable";
|
|
import EditPageLayout from "~/components/ui/layouts/EditPageLayout";
|
|
import UrlUtils from "~/utils/app/UrlUtils";
|
|
import { useAppData } from "~/utils/data/useAppData";
|
|
import { RedactedApiKeyWithDetails, getApiKeys } from "~/utils/db/apiKeys.db.server";
|
|
import { verifyUserHasPermission } from "~/utils/helpers/.server/PermissionsService";
|
|
import { getUserHasPermission } from "~/utils/helpers/PermissionsHelper";
|
|
import { getTenantIdFromUrl } from "~/utils/services/.server/urlService";
|
|
|
|
type LoaderData = {
|
|
apiKeys: RedactedApiKeyWithDetails[];
|
|
};
|
|
|
|
export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
|
const tenantId = await getTenantIdFromUrl(params);
|
|
await verifyUserHasPermission(request, "app.settings.apiKeys.view", tenantId);
|
|
const data: LoaderData = {
|
|
apiKeys: await getApiKeys(tenantId),
|
|
};
|
|
return data;
|
|
};
|
|
|
|
export default function ApiKeysRoute() {
|
|
const { t } = useTranslation();
|
|
const data = useLoaderData<LoaderData>();
|
|
const appData = useAppData();
|
|
const params = useParams();
|
|
|
|
return (
|
|
<EditPageLayout
|
|
tabs={[
|
|
{ name: t("shared.overview"), routePath: UrlUtils.getModulePath(params, "api") },
|
|
{ name: t("models.apiCall.plural"), routePath: UrlUtils.getModulePath(params, "api/logs") },
|
|
{ name: t("models.apiKey.plural"), routePath: UrlUtils.getModulePath(params, "api/keys") },
|
|
{ name: t("docs.title"), routePath: UrlUtils.getModulePath(params, "api/docs") },
|
|
]}
|
|
>
|
|
<ApiKeysTable
|
|
canCreate={getUserHasPermission(appData, "app.settings.apiKeys.create")}
|
|
entities={appData.entities}
|
|
items={data.apiKeys}
|
|
/>
|
|
<Outlet />
|
|
</EditPageLayout>
|
|
);
|
|
}
|