+
+ void save()}>
+ Создать
+
+ >
+ }
+ >
+
+
+ setName(e.target.value)}
+ />
+
+
+
+ setUrl(e.target.value)}
+ />
+
+
+
+ setTimeoutMs(e.target.value)}
+ />
+
+
+ )
+}
diff --git a/apps/web/src/lib/auth.ts b/apps/web/src/lib/auth.ts
index 6c44222..f7159a9 100644
--- a/apps/web/src/lib/auth.ts
+++ b/apps/web/src/lib/auth.ts
@@ -308,6 +308,31 @@ export function sessionCanWriteModules(session: {
return role === 'editor' || role === 'operator'
}
+/**
+ * Whether session may create/update directories (`bgp:directories:write`).
+ * Mirrors backend `requirePerm` for JWT (is_admin / permissions) and API-key editor+.
+ */
+export function sessionCanWriteDirectories(session: {
+ role?: string
+ kind?: string
+ is_admin?: boolean
+ permissions?: readonly string[]
+} | null | undefined): boolean {
+ if (!session) return false
+ const jwtPath =
+ session.kind === 'jwt' ||
+ session.is_admin === true ||
+ (session.permissions?.length ?? 0) > 0
+ if (jwtPath) {
+ return (
+ session.is_admin === true ||
+ hasPermission(session.permissions ?? [], 'bgp:directories:write')
+ )
+ }
+ const role = (session.role ?? '').toLowerCase()
+ return role === 'editor' || role === 'operator'
+}
+
/** Nav path → minimum permission to show the item. Sync with app-shell NAV. */
export function permissionForPath(pathname: string): string | null {
if (pathname === '/' || pathname.startsWith('/dashboard')) {
diff --git a/apps/web/src/queries/directories.ts b/apps/web/src/queries/directories.ts
index 925f218..aa57574 100644
--- a/apps/web/src/queries/directories.ts
+++ b/apps/web/src/queries/directories.ts
@@ -1,6 +1,15 @@
-import { queryOptions } from '@tanstack/react-query'
-import { apiJSON } from '@/lib/api-client'
-import type { CommunitiesResponse, DohProfilesResponse } from '@/types/api'
+import { queryOptions, useMutation, useQueryClient } from '@tanstack/react-query'
+import { toast } from 'sonner'
+
+import { apiJSON, apiMutate } from '@/lib/api-client'
+import type {
+ BgpCommunity,
+ BgpCommunityCreate,
+ CommunitiesResponse,
+ DohProfile,
+ DohProfileCreate,
+ DohProfilesResponse,
+} from '@/types/api'
export const directoriesKeys = {
all: ['directories'] as const,
@@ -23,3 +32,31 @@ export function directoriesDohQueryOptions() {
staleTime: 30_000,
})
}
+
+export function useCreateCommunityMutation() {
+ const qc = useQueryClient()
+ return useMutation({
+ mutationFn: (body: BgpCommunityCreate) =>
+ apiMutate