Skip to content

Commit

Permalink
Upgrade RHF
Browse files Browse the repository at this point in the history
  • Loading branch information
tassoevan committed Dec 22, 2024
1 parent 7620cad commit f791e50
Show file tree
Hide file tree
Showing 16 changed files with 121 additions and 47 deletions.
2 changes: 1 addition & 1 deletion packages/onboarding-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
},
"dependencies": {
"i18next": "~21.6.16",
"react-hook-form": "~7.27.1"
"react-hook-form": "~7.45.4"
},
"peerDependencies": {
"@rocket.chat/fuselage": "*",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { action } from '@storybook/addon-actions';
import { countries } from 'countries-list';
import type { Validate } from 'react-hook-form';

export const logSubmit =
<T extends (...args: any[]) => any>(onSubmit: T) =>
Expand Down Expand Up @@ -40,7 +39,7 @@ export const validateEmail = fetchMock('/email/validate', (email: string) => {
return true;
});

export const validatePassword: Validate<string> = (password: string) => {
export const validatePassword = (password: string) => {
if (password.length < 6) {
return `Password is too short`;
}
Expand Down
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>;
validateEmail: Validate<string>;
validatePassword: Validate<string>;
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>;
validateEmail: Validate<string>;
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>;
validatePassword: Validate<string>;
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>;
validatePasswordConfirmation: Validate<string>;
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>;
validatePassword: Validate<string>;
validateConfirmationPassword: Validate<string>;
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>;
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>;
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>;
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>;
validateEmail: Validate<string>;
validatePassword: Validate<string>;
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>;
validatePassword: Validate<string>;
validateConfirmationPassword: Validate<string>;
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>;
validatePasswordConfirmation: Validate<string>;
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>;
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>;
validateEmail: Validate<
FieldPathValue<ResetPasswordFormPayload, 'email'>,
ResetPasswordFormPayload
>;
onSubmit: SubmitHandler<ResetPasswordFormPayload>;
onLogin: () => void;
};
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4697,7 +4697,7 @@ __metadata:
prettier: "npm:~3.3.3"
react: "npm:~18.3.1"
react-dom: "npm:~18.3.1"
react-hook-form: "npm:~7.27.1"
react-hook-form: "npm:~7.45.4"
react-i18next: "npm:~13.2.2"
rimraf: "npm:^3.0.2"
storybook: "npm:~8.4.7"
Expand Down Expand Up @@ -16403,12 +16403,12 @@ __metadata:
languageName: node
linkType: hard

"react-hook-form@npm:~7.27.1":
version: 7.27.1
resolution: "react-hook-form@npm:7.27.1"
"react-hook-form@npm:~7.45.4":
version: 7.45.4
resolution: "react-hook-form@npm:7.45.4"
peerDependencies:
react: ^16.8.0 || ^17
checksum: 10/fa22f39e7eb157e7fc71ef132a9ffc3680f51d5642529542f5ab9229d6f7064aacbfbcbcd9bcf180a929a58f9a9b85f38b69492b8790407b87dc011bbce5f06e
react: ^16.8.0 || ^17 || ^18
checksum: 10/499d51c758161081fab0d22e7720e33e45d678fc2c8af2ff939434a61fab7043624c35afdfa27fa93fdc17d50a9683deb8b39bf308643f71b32126e561270641
languageName: node
linkType: hard

Expand Down

0 comments on commit f791e50

Please sign in to comment.