feat(webhook): Phase 4 — admin-ui /webhooks page
Routes: - /webhooks (layout) → /webhooks/index (list) + /webhooks/$id (detail) - nav link добавлен в __root.tsx между Outbox и Language switch List page (webhooks.index.tsx): - Table: name | URL | scope filter (colored dots) | dictionaries | status - ScopeChips reuse SCOPE_DOT из lib/scope-style.ts (consistency с dictionaries scope coloring) - Create dialog: name, URL, scope filter (MultiSelect), dictionary & event type (CSV inputs), description. Client-side validation (URL scheme, name required) дублирует server-side @Pattern. - Secret reveal modal после create: warning + plaintext + copy button. Single-time view — после закрытия secret не получить, только rotate. Detail page (webhooks.$id.tsx): - Subscription metadata grid (URL, status, filters, masked secret, createdBy + timestamp) - Action buttons: rotate-secret + delete (с confirmation) - Delivery history table: outboxEventId | status badge (delivered/ retrying/pending/dlq) | attempts | last attempt | HTTP code | error - Pagination 50/page - Status badges: delivered=success, retrying=warning, pending=neutral, dlq=error API client (queries + mutations): - 4 queries: subscriptions list, subscription by id, deliveries page, DLQ page (last unused в UI пока, но готов для admin DLQ tab) - 4 mutations: create, update, delete, rotateSecret. Все invalidate правильные query keys. i18n: 50 ключей × 2 локали (ru-RU + en-US) под webhooks.*
This commit is contained in:
@@ -3,8 +3,10 @@ import {
|
||||
apiClient,
|
||||
type CreateDictionaryRequest,
|
||||
type CreateRecordRequest,
|
||||
type CreateWebhookSubscriptionRequest,
|
||||
type DictionaryDetail,
|
||||
type RecordResponse,
|
||||
type WebhookSubscription,
|
||||
} from './client'
|
||||
|
||||
const idempotencyKey = () =>
|
||||
@@ -96,3 +98,69 @@ export const useCloseRecord = (dictionaryName: string) => {
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// === Webhooks (v2) ===
|
||||
|
||||
export const useCreateWebhook = () => {
|
||||
const qc = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: async (req: CreateWebhookSubscriptionRequest): Promise<WebhookSubscription> => {
|
||||
const { data } = await apiClient.post<WebhookSubscription>(
|
||||
'/admin/webhooks/subscriptions',
|
||||
req,
|
||||
)
|
||||
return data
|
||||
},
|
||||
onSuccess: () => {
|
||||
qc.invalidateQueries({ queryKey: ['webhooks', 'subscriptions'] })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const useUpdateWebhook = () => {
|
||||
const qc = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: async (params: {
|
||||
id: string
|
||||
payload: CreateWebhookSubscriptionRequest
|
||||
}): Promise<WebhookSubscription> => {
|
||||
const { data } = await apiClient.put<WebhookSubscription>(
|
||||
`/admin/webhooks/subscriptions/${encodeURIComponent(params.id)}`,
|
||||
params.payload,
|
||||
)
|
||||
return data
|
||||
},
|
||||
onSuccess: (_data, vars) => {
|
||||
qc.invalidateQueries({ queryKey: ['webhooks', 'subscriptions'] })
|
||||
qc.invalidateQueries({ queryKey: ['webhooks', 'subscriptions', vars.id] })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const useDeleteWebhook = () => {
|
||||
const qc = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: async (id: string): Promise<void> => {
|
||||
await apiClient.delete(`/admin/webhooks/subscriptions/${encodeURIComponent(id)}`)
|
||||
},
|
||||
onSuccess: () => {
|
||||
qc.invalidateQueries({ queryKey: ['webhooks', 'subscriptions'] })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const useRotateWebhookSecret = () => {
|
||||
const qc = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: async (id: string): Promise<WebhookSubscription> => {
|
||||
const { data } = await apiClient.post<WebhookSubscription>(
|
||||
`/admin/webhooks/subscriptions/${encodeURIComponent(id)}/rotate-secret`,
|
||||
)
|
||||
return data
|
||||
},
|
||||
onSuccess: (_data, id) => {
|
||||
qc.invalidateQueries({ queryKey: ['webhooks', 'subscriptions'] })
|
||||
qc.invalidateQueries({ queryKey: ['webhooks', 'subscriptions', id] })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user