diff --git a/public/app/core/components/ForgottenPassword/ChangePassword.tsx b/public/app/core/components/ForgottenPassword/ChangePassword.tsx index 989ab9f81b2..9f5a958d97d 100644 --- a/public/app/core/components/ForgottenPassword/ChangePassword.tsx +++ b/public/app/core/components/ForgottenPassword/ChangePassword.tsx @@ -1,7 +1,8 @@ import React, { SyntheticEvent } from 'react'; +import { useForm } from 'react-hook-form'; import { selectors } from '@grafana/e2e-selectors'; -import { Tooltip, Form, Field, VerticalGroup, Button, Alert, useStyles2 } from '@grafana/ui'; +import { Tooltip, Field, VerticalGroup, Button, Alert, useStyles2 } from '@grafana/ui'; import { getStyles } from '../Login/LoginForm'; import { PasswordField } from '../PasswordField/PasswordField'; @@ -18,52 +19,59 @@ interface PasswordDTO { export const ChangePassword = ({ onSubmit, onSkip, showDefaultPasswordWarning }: Props) => { const styles = useStyles2(getStyles); + const { + handleSubmit, + register, + getValues, + formState: { errors }, + } = useForm({ + defaultValues: { + newPassword: '', + confirmNew: '', + }, + }); const submit = (passwords: PasswordDTO) => { onSubmit(passwords.newPassword); }; return ( -
- {({ errors, register, getValues }) => ( - <> - {showDefaultPasswordWarning && ( - - )} - - - - - v === getValues().newPassword || 'Passwords must match!', - })} - id="confirm-new-password" - autoComplete="new-password" - /> - - - - - {onSkip && ( - - - - )} - - + + {showDefaultPasswordWarning && ( + )} - + + + + + v === getValues().newPassword || 'Passwords must match!', + })} + id="confirm-new-password" + autoComplete="new-password" + /> + + + + + {onSkip && ( + + + + )} + + ); }; diff --git a/public/app/core/components/ForgottenPassword/ForgottenPassword.tsx b/public/app/core/components/ForgottenPassword/ForgottenPassword.tsx index c15c4fe6e13..c4ab8a1b183 100644 --- a/public/app/core/components/ForgottenPassword/ForgottenPassword.tsx +++ b/public/app/core/components/ForgottenPassword/ForgottenPassword.tsx @@ -1,9 +1,10 @@ import { css } from '@emotion/css'; import React, { useState } from 'react'; +import { useForm } from 'react-hook-form'; import { GrafanaTheme2 } from '@grafana/data'; import { getBackendSrv } from '@grafana/runtime'; -import { Form, Field, Input, Button, Legend, Container, useStyles2, HorizontalGroup, LinkButton } from '@grafana/ui'; +import { Field, Input, Button, Legend, Container, useStyles2, HorizontalGroup, LinkButton } from '@grafana/ui'; import config from 'app/core/config'; interface EmailDTO { @@ -23,6 +24,11 @@ export const ForgottenPassword = () => { const [emailSent, setEmailSent] = useState(false); const styles = useStyles2(paragraphStyles); const loginHref = `${config.appSubUrl}/login`; + const { + handleSubmit, + register, + formState: { errors }, + } = useForm(); const sendEmail = async (formModel: EmailDTO) => { const res = await getBackendSrv().post('/api/user/password/send-reset-email', formModel); @@ -43,32 +49,28 @@ export const ForgottenPassword = () => { ); } return ( -
- {({ register, errors }) => ( - <> - Reset password - - - - - - - Back to login - - + + Reset password + + + + + + + Back to login + + -

Did you forget your username or email? Contact your Grafana administrator.

- - )} -
+

Did you forget your username or email? Contact your Grafana administrator.

+ ); };