Skip to content

Commit

Permalink
fix: replace useAutoFocus
Browse files Browse the repository at this point in the history
  • Loading branch information
dougfabris committed Nov 3, 2021
1 parent c72d3cf commit 34e406e
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 14 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 7 additions & 4 deletions packages/onboarding-ui/src/forms/AdminInfoForm/AdminInfoForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
Box,
CheckBox,
} from '@rocket.chat/fuselage';
import { useUniqueId, useAutoFocus } from '@rocket.chat/fuselage-hooks';
import type { ReactElement } from 'react';
import { useUniqueId } from '@rocket.chat/fuselage-hooks';
import { ReactElement, useEffect } from 'react';
import { useForm, SubmitHandler, Validate } from 'react-hook-form';
import { useTranslation } from 'react-i18next';

Expand Down Expand Up @@ -48,7 +48,6 @@ const AdminInfoForm = ({
onSubmit,
}: AdminInfoFormProps): ReactElement => {
const { t } = useTranslation();
const autofocus = useAutoFocus();

const fullnameField = useUniqueId();
const usernameField = useUniqueId(); // lgtm [js/insecure-randomness]
Expand All @@ -59,13 +58,18 @@ const AdminInfoForm = ({
register,
handleSubmit,
formState: { isValidating, isSubmitting, errors },
setFocus,
} = useForm<AdminInfoPayload>({
defaultValues: {
...initialValues,
password: '',
},
});

useEffect(() => {
setFocus('fullname');
}, [setFocus]);

return (
<Form onSubmit={handleSubmit(onSubmit)}>
<Form.Steps currentStep={currentStep} stepCount={stepCount} />
Expand All @@ -86,7 +90,6 @@ const AdminInfoForm = ({
'form.adminInfoForm.fields.fullName.placeholder'
)}
id={fullnameField}
ref={autofocus}
/>
</Field.Row>
{errors.fullname && (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ButtonGroup, Button, EmailInput, Field } from '@rocket.chat/fuselage';
import { useUniqueId } from '@rocket.chat/fuselage-hooks';
import type { ReactElement } from 'react';
import { ReactElement, useEffect } from 'react';
import { useForm, SubmitHandler, Validate } from 'react-hook-form';
import { useTranslation } from 'react-i18next';

Expand Down Expand Up @@ -34,13 +34,18 @@ const CloudAccountEmailForm = ({
register,
handleSubmit,
formState: { isValidating, isSubmitting, errors },
setFocus,
} = useForm<CloudAccountEmailPayload>({
defaultValues: {
email: '',
...initialValues,
},
});

useEffect(() => {
setFocus('email');
}, [setFocus]);

return (
<Form onSubmit={handleSubmit(onSubmit)}>
<Form.Steps currentStep={currentStep} stepCount={stepCount} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@ import {
SelectOptions,
Box,
} from '@rocket.chat/fuselage';
import {
useBreakpoints,
useUniqueId,
useAutoFocus,
} from '@rocket.chat/fuselage-hooks';
import type { ReactElement, ReactNode } from 'react';
import { useBreakpoints, useUniqueId } from '@rocket.chat/fuselage-hooks';
import { ReactElement, ReactNode, useEffect } from 'react';
import { useForm, SubmitHandler, Controller } from 'react-hook-form';
import { useTranslation } from 'react-i18next';

Expand Down Expand Up @@ -65,17 +61,20 @@ const OrganizationInfoForm = ({
const organizationSizeField = useUniqueId();
const countryField = useUniqueId();

const autofocus = useAutoFocus();

const {
register,
control,
handleSubmit,
formState: { isValidating, isSubmitting, errors },
setFocus,
} = useForm<OrganizationInfoPayload>({
defaultValues: initialValues,
});

useEffect(() => {
setFocus('organizationName');
}, [setFocus]);

return (
<Form onSubmit={handleSubmit(onSubmit)}>
<Form.Steps currentStep={currentStep} stepCount={stepCount} />
Expand All @@ -94,7 +93,6 @@ const OrganizationInfoForm = ({
'form.organizationInfoForm.fields.organizationName.placeholder'
)}
id={organizationNameField}
ref={autofocus}
/>
</Field.Row>
{errors.organizationName && (
Expand Down

0 comments on commit 34e406e

Please sign in to comment.