/
githubmirror
/
novu
Обзор
Документация
Войти
/
githubmirror
/
novu
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
next
packages/react/src/hooks/useDeleteChannelConnection.ts
66 строк
2 KB
Paweł Tymczuk
feat(dashboard,api-service,js,react,framework): novu copilot agent for slack fixes NV-8316 (#11973)
22 июл 2026, 14:06
Не верифицирован
22 июл 2026, 14:06
7d56d88
Код
Авторство
О чём код?
import type { NovuError } from '@novu/js'; import { useCallback, useRef, useState } from 'react'; import { useNovu } from './NovuProvider'; export type UseDeleteChannelConnectionProps = { onSuccess?: () => void; onError?: (error: NovuError) => void; }; export type UseDeleteChannelConnectionResult = { isDeleting: boolean; error?: NovuError; remove: (identifier: string) => Promise<{ data?: undefined; error?: NovuError | undefined; }>; }; /** * Delete a channel connection by identifier. Works for both subscriber-owned and * shared (workspace-level) connections the current subscriber can access. */ export const useDeleteChannelConnection = ( props: UseDeleteChannelConnectionProps = {} ): UseDeleteChannelConnectionResult => { const propsRef = useRef<UseDeleteChannelConnectionProps>(props); propsRef.current = props; const novu = useNovu(); const [isDeleting, setIsDeleting] = useState(false); const [error, setError] = useState<NovuError>(); const remove = useCallback( async (identifier: string) => { setError(undefined); setIsDeleting(true); try { const response = await novu.channelConnections.delete({ identifier }); if (response.error) { setError(response.error as NovuError); propsRef.current.onError?.(response.error as NovuError); } else { propsRef.current.onSuccess?.(); } return response as { data?: undefined; error?: NovuError }; } catch (err) { const novuError = err as NovuError; setError(novuError); propsRef.current.onError?.(novuError); return { error: novuError }; } finally { setIsDeleting(false); } }, [novu] ); return { remove, isDeleting, error, }; };