1- import { Fragment , useCallback , useMemo , useState } from 'react' ;
1+ import { useCallback , useState } from 'react' ;
22import Head from 'next/head' ;
3- import { HTTPError } from 'ky' ;
43import { CopyToClipboard } from 'react-copy-to-clipboard' ;
54import { SubmitHandler , useForm , useWatch } from 'react-hook-form' ;
65import { DEFAULT_METADATA_MAX_ROWS_TO_READ } from '@hyperdx/common-utils/dist/core/metadata' ;
7- import {
8- TeamClickHouseSettings ,
9- WebhookService ,
10- } from '@hyperdx/common-utils/dist/types' ;
6+ import { TeamClickHouseSettings } from '@hyperdx/common-utils/dist/types' ;
117import {
128 Box ,
139 Button ,
@@ -25,7 +21,6 @@ import {
2521 TextInput ,
2622 Tooltip ,
2723} from '@mantine/core' ;
28- import { useDisclosure } from '@mantine/hooks' ;
2924import { notifications } from '@mantine/notifications' ;
3025import {
3126 IconCheck ,
@@ -42,13 +37,11 @@ import { IS_LOCAL_MODE } from '@/config';
4237
4338import { PageHeader } from './components/PageHeader' ;
4439import TeamMembersSection from './components/TeamSettings/TeamMembersSection' ;
45- import { WebhookForm } from './components/TeamSettings/WebhookForm ' ;
40+ import WebhooksSection from './components/TeamSettings/WebhooksSection ' ;
4641import api from './api' ;
4742import { useConnections } from './connection' ;
4843import { DEFAULT_QUERY_TIMEOUT , DEFAULT_SEARCH_ROW_LIMIT } from './defaults' ;
4944import { withAppNav } from './layout' ;
50- import type { Webhook } from './types' ;
51- import { useConfirm } from './useConfirm' ;
5245
5346function ConnectionsSection ( ) {
5447 const { data : connections } = useConnections ( ) ;
@@ -159,159 +152,15 @@ function SourcesSection() {
159152 </ Box >
160153 ) ;
161154}
162-
163- function DeleteWebhookButton ( {
164- webhookId,
165- webhookName,
166- onSuccess,
167- } : {
168- webhookId : string ;
169- webhookName : string ;
170- onSuccess : VoidFunction ;
171- } ) {
172- const confirm = useConfirm ( ) ;
173- const deleteWebhook = api . useDeleteWebhook ( ) ;
174-
175- const handleDelete = async ( ) => {
176- if (
177- await confirm (
178- `Are you sure you want to delete ${ webhookName } webhook?` ,
179- 'Delete' ,
180- )
181- ) {
182- try {
183- await deleteWebhook . mutateAsync ( { id : webhookId } ) ;
184- notifications . show ( {
185- color : 'green' ,
186- message : 'Webhook deleted successfully' ,
187- } ) ;
188- onSuccess ( ) ;
189- } catch ( e ) {
190- console . error ( e ) ;
191- const message =
192- ( e instanceof HTTPError
193- ? ( await e . response . json ( ) ) ?. message
194- : null ) || 'Something went wrong. Please contact HyperDX team.' ;
195- notifications . show ( {
196- message,
197- color : 'red' ,
198- autoClose : 5000 ,
199- } ) ;
200- }
201- }
202- } ;
203-
204- return (
205- < Button
206- color = "red"
207- size = "compact-xs"
208- variant = "outline"
209- onClick = { handleDelete }
210- loading = { deleteWebhook . isPending }
211- >
212- Delete
213- </ Button >
214- ) ;
215- }
216-
217155function IntegrationsSection ( ) {
218- const { data : webhookData , refetch : refetchWebhooks } = api . useWebhooks ( [
219- WebhookService . Slack ,
220- WebhookService . Generic ,
221- WebhookService . IncidentIO ,
222- ] ) ;
223-
224- const allWebhooks = useMemo < Webhook [ ] > ( ( ) => {
225- return Array . isArray ( webhookData ?. data ) ? webhookData . data : [ ] ;
226- } , [ webhookData ] ) ;
227-
228- const [ editedWebhookId , setEditedWebhookId ] = useState < string | null > ( null ) ;
229- const [
230- isAddWebhookModalOpen ,
231- { open : openWebhookModal , close : closeWebhookModal } ,
232- ] = useDisclosure ( ) ;
233-
234156 return (
235157 < Box id = "integrations" >
236158 < Text size = "md" > Integrations</ Text >
237159 < Divider my = "md" />
238160 < Card >
239- < Text mb = "xs" > Webhooks</ Text >
240-
241- < Stack >
242- { allWebhooks . map ( webhook => (
243- < Fragment key = { webhook . _id } >
244- < Group justify = "space-between" align = "flex-start" >
245- < Stack gap = { 0 } >
246- < Text size = "sm" >
247- { webhook . name } ({ webhook . service } )
248- </ Text >
249- < Text size = "xs" opacity = { 0.7 } >
250- { webhook . url }
251- </ Text >
252- { webhook . description && (
253- < Text size = "xxs" opacity = { 0.7 } >
254- { webhook . description }
255- </ Text >
256- ) }
257- </ Stack >
258- < Group gap = "xs" >
259- { editedWebhookId !== webhook . _id && (
260- < >
261- < Button
262- variant = "subtle"
263- onClick = { ( ) => setEditedWebhookId ( webhook . _id ) }
264- size = "compact-xs"
265- leftSection = { < IconPencil size = { 14 } /> }
266- >
267- Edit
268- </ Button >
269- < DeleteWebhookButton
270- webhookId = { webhook . _id }
271- webhookName = { webhook . name }
272- onSuccess = { refetchWebhooks }
273- />
274- </ >
275- ) }
276- { editedWebhookId === webhook . _id && (
277- < Button
278- variant = "subtle"
279- onClick = { ( ) => setEditedWebhookId ( null ) }
280- size = "compact-xs"
281- >
282- < IconX size = { 14 } className = "me-2" /> Cancel
283- </ Button >
284- ) }
285- </ Group >
286- </ Group >
287- { editedWebhookId === webhook . _id && (
288- < WebhookForm
289- webhook = { webhook }
290- onClose = { ( ) => setEditedWebhookId ( null ) }
291- onSuccess = { ( ) => {
292- setEditedWebhookId ( null ) ;
293- refetchWebhooks ( ) ;
294- } }
295- />
296- ) }
297- < Divider />
298- </ Fragment >
299- ) ) }
161+ < Stack gap = "md" >
162+ < WebhooksSection />
300163 </ Stack >
301-
302- { ! isAddWebhookModalOpen ? (
303- < Button variant = "outline" onClick = { openWebhookModal } >
304- Add Webhook
305- </ Button >
306- ) : (
307- < WebhookForm
308- onClose = { closeWebhookModal }
309- onSuccess = { ( ) => {
310- refetchWebhooks ( ) ;
311- closeWebhookModal ( ) ;
312- } }
313- />
314- ) }
315164 </ Card >
316165 </ Box >
317166 ) ;
0 commit comments