Skip to content

Commit 7e5f3c2

Browse files
fix webhook create-edit form (#1136)
1 parent f2e349b commit 7e5f3c2

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

web/src/pages/webhooks/modals/WebhookModal/WebhookForm.tsx

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,6 @@ import useApi from '../../../../shared/hooks/useApi';
1818
import { useToaster } from '../../../../shared/hooks/useToaster';
1919
import { MutationKeys } from '../../../../shared/mutations';
2020
import { 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

3522
export 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' }}

web/src/pages/webhooks/modals/WebhookModal/style.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#webhook-modal {
22
& > .content {
33
& > form {
4+
.form-checkbox {
5+
padding-bottom: var(--spacing-s);
6+
}
7+
48
& > h3 {
59
@include small-header;
610

@@ -18,6 +22,7 @@
1822

1923
& > .controls {
2024
margin-top: 2.5rem;
25+
2126
@include media-breakpoint-up(lg) {
2227
margin-top: 6.5rem;
2328
}

0 commit comments

Comments
 (0)