@@ -18,19 +18,6 @@ import useApi from '../../../../shared/hooks/useApi';
1818import { useToaster } from '../../../../shared/hooks/useToaster' ;
1919import { MutationKeys } from '../../../../shared/mutations' ;
2020import { QueryKeys } from '../../../../shared/queries' ;
21- import { Webhook } from '../../../../shared/types' ;
22-
23- type FormInputs = Omit < Webhook , 'id' | 'enabled' > ;
24-
25- const defaultValues : FormInputs = {
26- url : '' ,
27- description : '' ,
28- token : '' ,
29- on_hwkey_provision : false ,
30- on_user_created : false ,
31- on_user_deleted : false ,
32- on_user_modified : false ,
33- } ;
3421
3522export const WebhookForm = ( ) => {
3623 const { LL } = useI18nContext ( ) ;
@@ -41,12 +28,6 @@ export const WebhookForm = () => {
4128 const modalState = useModalStore ( ( state ) => state . webhookModal ) ;
4229 const setModalState = useModalStore ( ( state ) => state . setWebhookModal ) ;
4330 const editMode = useMemo ( ( ) => ! isUndefined ( modalState . webhook ) , [ modalState . webhook ] ) ;
44- const defaultFormState : FormInputs = useMemo ( ( ) => {
45- if ( ! isUndefined ( modalState . webhook ) ) {
46- return modalState . webhook ;
47- }
48- return defaultValues ;
49- } , [ modalState . webhook ] ) ;
5031
5132 const queryClient = useQueryClient ( ) ;
5233
@@ -89,7 +70,26 @@ export const WebhookForm = () => {
8970 [ LL . form . error , LL . modals . webhookModal . form . error ] ,
9071 ) ;
9172
92- const { control, handleSubmit } = useForm < FormInputs > ( {
73+ type FormFields = z . infer < typeof zodSchema > ;
74+
75+ const defaultFormState = useMemo ( ( ) : FormFields => {
76+ if ( ! isUndefined ( modalState . webhook ) ) {
77+ return modalState . webhook ;
78+ }
79+ const defaultValues : FormFields = {
80+ url : '' ,
81+ description : '' ,
82+ token : '' ,
83+ enabled : true ,
84+ on_hwkey_provision : false ,
85+ on_user_created : false ,
86+ on_user_deleted : false ,
87+ on_user_modified : false ,
88+ } ;
89+ return defaultValues ;
90+ } , [ modalState . webhook ] ) ;
91+
92+ const { control, handleSubmit } = useForm < FormFields > ( {
9393 defaultValues : defaultFormState ,
9494 mode : 'all' ,
9595 resolver : zodResolver ( zodSchema ) ,
@@ -135,7 +135,7 @@ export const WebhookForm = () => {
135135 } ,
136136 } ) ;
137137
138- const onValidSubmit : SubmitHandler < FormInputs > = ( values ) => {
138+ const onValidSubmit : SubmitHandler < FormFields > = ( values ) => {
139139 if ( editMode ) {
140140 if ( modalState . webhook ) {
141141 editWebhookMutation ( { ...modalState . webhook , ...values } ) ;
@@ -147,6 +147,11 @@ export const WebhookForm = () => {
147147
148148 return (
149149 < form onSubmit = { handleSubmit ( onValidSubmit ) } >
150+ < FormCheckBox
151+ label = { LL . common . controls . enabled ( ) }
152+ labelPlacement = "right"
153+ controller = { { control, name : 'enabled' } }
154+ />
150155 < FormInput
151156 label = { LL . modals . webhookModal . form . fields . url . label ( ) }
152157 controller = { { control, name : 'url' } }
0 commit comments