0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-03-24 22:41:28 -05:00

fix(console): provide default values for fields in sign up and sign in forms (#2279)

This commit is contained in:
Xiao Yijun 2022-10-31 12:17:57 +08:00 committed by GitHub
parent bf73837839
commit b18d22e1f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 5 deletions

View file

@ -1,4 +1,5 @@
import { Controller, useFormContext } from 'react-hook-form';
import { SignUpIdentifier } from '@logto/schemas';
import { Controller, useFormContext, useWatch } from 'react-hook-form';
import { useTranslation } from 'react-i18next';
import FormField from '@/components/FormField';
@ -11,10 +12,18 @@ import * as styles from './index.module.scss';
const SignInForm = () => {
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
const { control, watch } = useFormContext<SignInExperienceForm>();
const signUpIdentifier = watch('signUp.identifier');
const requirePassword = watch('signUp.password');
const requireVerificationCode = watch('signUp.verify');
const { control } = useFormContext<SignInExperienceForm>();
/**
* Note: `watch` may not return the default value, use `useWatch` instead.
* Reference: https://github.com/react-hook-form/react-hook-form/issues/1332
*/
const signUpIdentifier = useWatch({
control,
name: 'signUp.identifier',
defaultValue: SignUpIdentifier.Username,
});
const requirePassword = useWatch({ control, name: 'signUp.password', defaultValue: false });
const requireVerificationCode = useWatch({ control, name: 'signUp.verify', defaultValue: false });
return (
<>
@ -26,6 +35,7 @@ const SignInForm = () => {
<Controller
control={control}
name="signIn.methods"
defaultValue={[]}
render={({ field: { value, onChange } }) => {
return (
<SignInMethodEditBox

View file

@ -23,6 +23,7 @@ const SocialSignInForm = () => {
</div>
<Controller
control={control}
defaultValue={[]}
name="socialSignInConnectorTargets"
render={({ field: { value, onChange } }) => {
return <SocialConnectorEditBox value={value} onChange={onChange} />;