import { useForm } from 'react-hook-form'; import { Button, Input, Field, Modal } from '@grafana/ui'; import { Trans } from '../../../core/internationalization'; import { ServerDiscoveryFormData } from '../types'; import { isUrlValid } from '../utils/url'; interface Props { isOpen: boolean | undefined; onClose: () => void; onSuccess: (data: ServerDiscoveryFormData) => void; isLoading: boolean; } export const ServerDiscoveryModal = ({ isOpen, onClose, onSuccess, isLoading }: Props) => { const { handleSubmit, register, formState: { errors }, } = useForm({ mode: 'onBlur', defaultValues: { url: '', }, }); const validateUrl = (value?: string) => { if (value === '') { return 'Please enter the .well-known/openid-configuration endpoint for your IdP'; } if (!isUrlValid(value)) { return 'Please enter a valid URL'; } return true; }; return (
{ e.stopPropagation(); return handleSubmit(onSuccess)(e); }} >
); };