11import { useMemo } from 'react' ;
2- import Link from 'next/link' ;
3- import { Control } from 'react-hook-form' ;
2+ import { Control , useController } from 'react-hook-form' ;
43import { Select , SelectProps } from 'react-hook-form-mantine' ;
54import { Label , ReferenceArea , ReferenceLine } from 'recharts' ;
6- import type { Alert , AlertChannelType } from '@hyperdx/common-utils/dist/types' ;
7- import { Button , ComboboxData , Group } from '@mantine/core' ;
5+ import type { AlertChannelType } from '@hyperdx/common-utils/dist/types' ;
6+ import { Button , ComboboxData , Group , Modal } from '@mantine/core' ;
7+ import { useDisclosure } from '@mantine/hooks' ;
88
99import api from '@/api' ;
1010
11+ import { CreateWebhookForm } from '../TeamPage' ;
12+
1113type Webhook = {
1214 _id : string ;
1315 name : string ;
@@ -16,7 +18,11 @@ type Webhook = {
1618const WebhookChannelForm = < T extends object > (
1719 props : Partial < SelectProps < T > > ,
1820) => {
19- const { data : webhooks } = api . useWebhooks ( [ 'slack' , 'generic' ] ) ;
21+ const { data : webhooks , refetch : refetchWebhooks } = api . useWebhooks ( [
22+ 'slack' ,
23+ 'generic' ,
24+ ] ) ;
25+ const [ opened , { open, close } ] = useDisclosure ( false ) ;
2026
2127 const hasWebhooks = Array . isArray ( webhooks ?. data ) && webhooks . data . length > 0 ;
2228
@@ -37,6 +43,20 @@ const WebhookChannelForm = <T extends object>(
3743 ] ;
3844 } , [ webhooks ] ) ;
3945
46+ const { field } = useController ( {
47+ control : props . control ,
48+ name : props . name ! ,
49+ } ) ;
50+
51+ const handleWebhookCreated = async ( webhookId ?: string ) => {
52+ await refetchWebhooks ( ) ;
53+ if ( webhookId ) {
54+ field . onChange ( webhookId ) ;
55+ field . onBlur ( ) ;
56+ }
57+ close ( ) ;
58+ } ;
59+
4060 return (
4161 < div >
4262 < Group gap = "md" justify = "space-between" >
@@ -55,12 +75,21 @@ const WebhookChannelForm = <T extends object>(
5575 control = { props . control }
5676 { ...props }
5777 />
58- < Link href = "/team" passHref >
59- < Button size = "xs" variant = "subtle" color = "gray" >
60- Add New Incoming Webhook
61- </ Button >
62- </ Link >
78+ < Button size = "xs" variant = "subtle" color = "gray" onClick = { open } >
79+ Add New Incoming Webhook
80+ </ Button >
6381 </ Group >
82+
83+ < Modal
84+ opened = { opened }
85+ onClose = { close }
86+ title = "Add New Webhook"
87+ centered
88+ zIndex = { 9999 }
89+ size = "lg"
90+ >
91+ < CreateWebhookForm onClose = { close } onSuccess = { handleWebhookCreated } />
92+ </ Modal >
6493 </ div >
6594 ) ;
6695} ;
0 commit comments