diff --git a/public/app/features/alerting/components/BasicSettings.tsx b/public/app/features/alerting/components/BasicSettings.tsx
index 6705da037ef..a739d7ce401 100644
--- a/public/app/features/alerting/components/BasicSettings.tsx
+++ b/public/app/features/alerting/components/BasicSettings.tsx
@@ -1,7 +1,8 @@
import React from 'react';
+import { Controller } from 'react-hook-form';
import { SelectableValue } from '@grafana/data';
-import { Field, Input, InputControl, Select } from '@grafana/ui';
+import { Field, Input, Select } from '@grafana/ui';
import { NotificationChannelSecureFields, NotificationChannelType } from '../../../types';
@@ -31,7 +32,7 @@ export const BasicSettings = ({
- }
control={control}
diff --git a/public/app/features/alerting/components/OptionElement.tsx b/public/app/features/alerting/components/OptionElement.tsx
index bc43c8dee85..aa0581e7f32 100644
--- a/public/app/features/alerting/components/OptionElement.tsx
+++ b/public/app/features/alerting/components/OptionElement.tsx
@@ -1,10 +1,11 @@
import React from 'react';
+import { Controller, UseFormReturn } from 'react-hook-form';
-import { FormAPI, Input, InputControl, Select, TextArea } from '@grafana/ui';
+import { Input, Select, TextArea } from '@grafana/ui';
import { NotificationChannelOption } from '../../../types';
-interface Props extends Pick, 'register' | 'control'> {
+interface Props extends Pick, 'register' | 'control'> {
option: NotificationChannelOption;
invalid?: boolean;
}
@@ -27,7 +28,7 @@ export const OptionElement = ({ control, option, register, invalid }: Props) =>
case 'select':
return (
- (
diff --git a/public/app/features/alerting/unified/components/admin/ConfigEditor.tsx b/public/app/features/alerting/unified/components/admin/ConfigEditor.tsx
index aaf9c69a50d..8ea38ad84cd 100644
--- a/public/app/features/alerting/unified/components/admin/ConfigEditor.tsx
+++ b/public/app/features/alerting/unified/components/admin/ConfigEditor.tsx
@@ -1,6 +1,7 @@
import React from 'react';
+import { useForm } from 'react-hook-form';
-import { Button, CodeEditor, ConfirmModal, Field, Form, HorizontalGroup } from '@grafana/ui';
+import { Button, CodeEditor, ConfirmModal, Field, Stack } from '@grafana/ui';
import { GRAFANA_RULES_SOURCE_NAME } from '../../utils/datasource';
@@ -29,77 +30,77 @@ export const ConfigEditor = ({
onConfirmReset,
onDismiss,
}: ConfigEditorProps) => {
+ const {
+ handleSubmit,
+ formState: { errors },
+ setValue,
+ register,
+ } = useForm({ defaultValues });
+
+ register('configJSON', {
+ required: { value: true, message: 'Required' },
+ validate: (value: string) => {
+ try {
+ JSON.parse(value);
+ return true;
+ } catch (e) {
+ return e instanceof Error ? e.message : 'JSON is invalid';
+ }
+ },
+ });
return (
-
+ {Boolean(showConfirmDeleteAMConfig) && onConfirmReset && onDismiss && (
+
+ )}
+
);
};