Skip to content

Commit

Permalink
Upgrade RHF
Browse files Browse the repository at this point in the history
  • Loading branch information
tassoevan committed Dec 27, 2024
1 parent 61a9ddf commit f5594ad
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 38 deletions.
17 changes: 13 additions & 4 deletions packages/onboarding-ui/src/forms/AdminInfoForm/AdminInfoForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { useUniqueId } from '@rocket.chat/fuselage-hooks';
import { Form } from '@rocket.chat/layout';
import type { ReactElement } from 'react';
import { useRef, useEffect } from 'react';
import type { SubmitHandler, Validate } from 'react-hook-form';
import type { FieldPathValue, SubmitHandler, Validate } from 'react-hook-form';
import { useForm, Controller } from 'react-hook-form';
import { useTranslation } from 'react-i18next';

Expand All @@ -35,9 +35,18 @@ type AdminInfoFormProps = {
passwordRulesHint: string;
keepPosted?: boolean;
initialValues?: Omit<AdminInfoPayload, 'password'>;
validateUsername: Validate<string, AdminInfoPayload>;
validateEmail: Validate<string, AdminInfoPayload>;
validatePassword: Validate<string, AdminInfoPayload>;
validateUsername: Validate<
FieldPathValue<AdminInfoPayload, 'username'>,
AdminInfoPayload
>;
validateEmail: Validate<
FieldPathValue<AdminInfoPayload, 'email'>,
AdminInfoPayload
>;
validatePassword: Validate<
FieldPathValue<AdminInfoPayload, 'password'>,
AdminInfoPayload
>;
onSubmit: SubmitHandler<AdminInfoPayload>;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from '@rocket.chat/fuselage';
import { Form } from '@rocket.chat/layout';
import type { ReactElement, FocusEvent } from 'react';
import type { SubmitHandler, Validate } from 'react-hook-form';
import type { FieldPathValue, SubmitHandler, Validate } from 'react-hook-form';
import { useForm, Controller } from 'react-hook-form';
import { useTranslation, Trans } from 'react-i18next';

Expand All @@ -42,8 +42,14 @@ type CreateCloudWorkspaceFormProps = {
languageOptions: SelectOption[];
domain: string;
onBackButtonClick?: () => void;
validateUrl: Validate<string, CreateCloudWorkspaceFormPayload>;
validateEmail: Validate<string, CreateCloudWorkspaceFormPayload>;
validateUrl: Validate<
FieldPathValue<CreateCloudWorkspaceFormPayload, 'workspaceURL'>,
CreateCloudWorkspaceFormPayload
>;
validateEmail: Validate<
FieldPathValue<CreateCloudWorkspaceFormPayload, 'organizationEmail'>,
CreateCloudWorkspaceFormPayload
>;
};

const CreateCloudWorkspaceForm = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from '@rocket.chat/fuselage';
import { Form } from '@rocket.chat/layout';
import type { ReactElement } from 'react';
import type { SubmitHandler, Validate } from 'react-hook-form';
import type { FieldPathValue, SubmitHandler, Validate } from 'react-hook-form';
import { useForm } from 'react-hook-form';
import { useTranslation } from 'react-i18next';

Expand All @@ -29,8 +29,14 @@ type CreateFirstMemberFormProps = {
organizationName: string;
onSubmit: SubmitHandler<CreateFirstMemberFormPayload>;
onBackButtonClick: () => void;
validateUsername: Validate<string, CreateFirstMemberFormPayload>;
validatePassword: Validate<string, CreateFirstMemberFormPayload>;
validateUsername: Validate<
FieldPathValue<CreateFirstMemberFormPayload, 'username'>,
CreateFirstMemberFormPayload
>;
validatePassword: Validate<
FieldPathValue<CreateFirstMemberFormPayload, 'password'>,
CreateFirstMemberFormPayload
>;
};

const CreateFirstMemberForm = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from '@rocket.chat/fuselage';
import { Form } from '@rocket.chat/layout';
import type { ReactElement } from 'react';
import type { SubmitHandler, Validate } from 'react-hook-form';
import type { FieldPathValue, SubmitHandler, Validate } from 'react-hook-form';
import { useForm } from 'react-hook-form';
import { useTranslation } from 'react-i18next';

Expand All @@ -21,8 +21,14 @@ export type CreateNewPasswordPayload = {

type CreateNewPasswordProps = {
initialValues?: CreateNewPasswordPayload;
validatePassword: Validate<string, CreateNewPasswordPayload>;
validatePasswordConfirmation: Validate<string, CreateNewPasswordPayload>;
validatePassword: Validate<
FieldPathValue<CreateNewPasswordPayload, 'password'>,
CreateNewPasswordPayload
>;
validatePasswordConfirmation: Validate<
FieldPathValue<CreateNewPasswordPayload, 'passwordConfirmation'>,
CreateNewPasswordPayload
>;
onSubmit: SubmitHandler<CreateNewPasswordPayload>;
};

Expand Down
17 changes: 13 additions & 4 deletions packages/onboarding-ui/src/forms/NewAccountForm/NewAccountForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { Form } from '@rocket.chat/layout';
import type { ReactElement } from 'react';
import { useEffect } from 'react';
import type { SubmitHandler, Validate } from 'react-hook-form';
import type { FieldPathValue, SubmitHandler, Validate } from 'react-hook-form';
import { useForm } from 'react-hook-form';
import { Trans, useTranslation } from 'react-i18next';

Expand All @@ -29,9 +29,18 @@ export type NewAccountPayload = {

type NewAccountFormProps = {
initialValues?: Omit<NewAccountPayload, 'password'>;
validateEmail: Validate<string, NewAccountPayload>;
validatePassword: Validate<string, NewAccountPayload>;
validateConfirmationPassword: Validate<string, NewAccountPayload>;
validateEmail: Validate<
FieldPathValue<NewAccountPayload, 'email'>,
NewAccountPayload
>;
validatePassword: Validate<
FieldPathValue<NewAccountPayload, 'password'>,
NewAccountPayload
>;
validateConfirmationPassword: Validate<
FieldPathValue<NewAccountPayload, 'confirmPassword'>,
NewAccountPayload
>;
onSubmit: SubmitHandler<NewAccountPayload>;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useUniqueId, useBreakpoints } from '@rocket.chat/fuselage-hooks';
import { Form } from '@rocket.chat/layout';
import type { ReactElement } from 'react';
import { useEffect, useRef } from 'react';
import type { SubmitHandler, Validate } from 'react-hook-form';
import type { FieldPathValue, SubmitHandler, Validate } from 'react-hook-form';
import { Controller, useForm, FormProvider } from 'react-hook-form';
import { useTranslation, Trans } from 'react-i18next';

Expand All @@ -29,7 +29,10 @@ type RegisterServerFormProps = {
currentStep: number;
stepCount: number;
initialValues?: Partial<RegisterServerPayload>;
validateEmail?: Validate<string, RegisterServerPayload>;
validateEmail?: Validate<
FieldPathValue<RegisterServerPayload, 'email'>,
RegisterServerPayload
>;
onSubmit: SubmitHandler<RegisterServerPayload>;
onClickRegisterOffline: () => void;
termsHref?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '@rocket.chat/fuselage';
import { Form } from '@rocket.chat/layout';
import type { ReactElement } from 'react';
import type { SubmitHandler, Validate } from 'react-hook-form';
import type { FieldPathValue, SubmitHandler, Validate } from 'react-hook-form';
import { useForm, Controller } from 'react-hook-form';
import { useTranslation, Trans } from 'react-i18next';

Expand All @@ -35,7 +35,10 @@ type RequestTrialFormProps = {
countryOptions: SelectOption[];
onSubmit: SubmitHandler<RequestTrialPayload>;
onManageWorkspaceClick: () => void;
validateEmail: Validate<string, RequestTrialPayload>;
validateEmail: Validate<
FieldPathValue<RequestTrialPayload, 'email'>,
RequestTrialPayload
>;
termsHref?: string;
policyHref?: string;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from '@rocket.chat/fuselage';
import { Form } from '@rocket.chat/layout';
import type { ReactElement } from 'react';
import type { SubmitHandler, Validate } from 'react-hook-form';
import type { FieldPathValue, SubmitHandler, Validate } from 'react-hook-form';
import { useForm } from 'react-hook-form';
import { useTranslation } from 'react-i18next';

Expand All @@ -21,7 +21,10 @@ export type ResetPasswordFormPayload = {

type ResetPasswordFormProps = {
initialValues?: ResetPasswordFormPayload;
validateEmail: Validate<string, ResetPasswordFormPayload>;
validateEmail: Validate<
FieldPathValue<ResetPasswordFormPayload, 'email'>,
ResetPasswordFormPayload
>;
onSubmit: SubmitHandler<ResetPasswordFormPayload>;
};

Expand Down
17 changes: 13 additions & 4 deletions packages/onboarding-ui/src/pages/AdminInfoPage/AdminInfoPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BackgroundLayer } from '@rocket.chat/layout';
import type { ReactElement, ReactNode } from 'react';
import type { SubmitHandler, Validate } from 'react-hook-form';
import type { FieldPathValue, SubmitHandler, Validate } from 'react-hook-form';

import type { FormPageLayoutStyleProps } from '../../Types';
import FormPageLayout from '../../common/FormPageLayout';
Expand All @@ -15,9 +15,18 @@ type AdminInfoPageProps = {
passwordRulesHint: string;
keepPosted?: boolean;
initialValues?: Omit<AdminInfoPayload, 'password'>;
validateUsername: Validate<string, AdminInfoPayload>;
validateEmail: Validate<string, AdminInfoPayload>;
validatePassword: Validate<string, AdminInfoPayload>;
validateUsername: Validate<
FieldPathValue<AdminInfoPayload, 'username'>,
AdminInfoPayload
>;
validateEmail: Validate<
FieldPathValue<AdminInfoPayload, 'email'>,
AdminInfoPayload
>;
validatePassword: Validate<
FieldPathValue<AdminInfoPayload, 'password'>,
AdminInfoPayload
>;
onSubmit: SubmitHandler<AdminInfoPayload>;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,26 @@ import {
VerticalWizardLayoutTitle,
} from '@rocket.chat/layout';
import type { ReactElement } from 'react';
import type { SubmitHandler, Validate } from 'react-hook-form';
import type { FieldPathValue, SubmitHandler, Validate } from 'react-hook-form';
import { Trans, useTranslation } from 'react-i18next';

import NewAccountForm from '../../forms/NewAccountForm';
import type { NewAccountPayload } from '../../forms/NewAccountForm/NewAccountForm';

type CreateNewAccountPageProps = {
initialValues?: Omit<NewAccountPayload, 'password'>;
validateEmail: Validate<string, NewAccountPayload>;
validatePassword: Validate<string, NewAccountPayload>;
validateConfirmationPassword: Validate<string, NewAccountPayload>;
validateEmail: Validate<
FieldPathValue<NewAccountPayload, 'email'>,
NewAccountPayload
>;
validatePassword: Validate<
FieldPathValue<NewAccountPayload, 'password'>,
NewAccountPayload
>;
validateConfirmationPassword: Validate<
FieldPathValue<NewAccountPayload, 'confirmPassword'>,
NewAccountPayload
>;
onSubmit: SubmitHandler<NewAccountPayload>;
onLogin: () => void;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Box } from '@rocket.chat/fuselage';
import { ActionLink } from '@rocket.chat/layout';
import type { ReactElement } from 'react';
import type { SubmitHandler, Validate } from 'react-hook-form';
import type { FieldPathValue, SubmitHandler, Validate } from 'react-hook-form';
import { Trans, useTranslation } from 'react-i18next';

import type { FormPageLayoutStyleProps } from '../../Types';
Expand All @@ -11,8 +11,14 @@ import type { CreateNewPasswordPayload } from '../../forms/CreateNewPassword/Cre

type CreateNewPasswordPageProps = {
initialValues?: CreateNewPasswordPayload;
validatePassword: Validate<string, CreateNewPasswordPayload>;
validatePasswordConfirmation: Validate<string, CreateNewPasswordPayload>;
validatePassword: Validate<
FieldPathValue<CreateNewPasswordPayload, 'password'>,
CreateNewPasswordPayload
>;
validatePasswordConfirmation: Validate<
FieldPathValue<CreateNewPasswordPayload, 'passwordConfirmation'>,
CreateNewPasswordPayload
>;
onSubmit: SubmitHandler<CreateNewPasswordPayload>;
onLogin: () => void;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BackgroundLayer } from '@rocket.chat/layout';
import type { ReactElement } from 'react';
import type { SubmitHandler, Validate } from 'react-hook-form';
import type { FieldPathValue, SubmitHandler, Validate } from 'react-hook-form';

import type { FormPageLayoutStyleProps } from '../../Types';
import FormPageLayout from '../../common/FormPageLayout';
Expand All @@ -14,7 +14,10 @@ type RegisterServerPageProps = {
onSubmit: SubmitHandler<RegisterServerPayload>;
onClickRegisterOffline: () => void;
offline?: boolean;
validateEmail?: Validate<string, RegisterServerPayload>;
validateEmail?: Validate<
FieldPathValue<RegisterServerPayload, 'email'>,
RegisterServerPayload
>;
termsHref?: string;
policyHref?: string;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Box } from '@rocket.chat/fuselage';
import { ActionLink, BackgroundLayer } from '@rocket.chat/layout';
import type { ReactElement } from 'react';
import type { SubmitHandler, Validate } from 'react-hook-form';
import type { FieldPathValue, SubmitHandler, Validate } from 'react-hook-form';
import { Trans, useTranslation } from 'react-i18next';

import type { FormPageLayoutStyleProps } from '../../Types';
Expand All @@ -11,7 +11,10 @@ import type { ResetPasswordFormPayload } from '../../forms/ResetPasswordForm/Res

type ResetPasswordPageProps = {
initialValues?: ResetPasswordFormPayload;
validateEmail: Validate<string, ResetPasswordFormPayload>;
validateEmail: Validate<
FieldPathValue<ResetPasswordFormPayload, 'email'>,
ResetPasswordFormPayload
>;
onSubmit: SubmitHandler<ResetPasswordFormPayload>;
onLogin: () => void;
};
Expand Down

0 comments on commit f5594ad

Please sign in to comment.