From f5594adb1cddc72e291e8af5874b3bc3abc315f9 Mon Sep 17 00:00:00 2001 From: Tasso Date: Sun, 22 Dec 2024 03:47:40 -0300 Subject: [PATCH] Upgrade RHF --- .../src/forms/AdminInfoForm/AdminInfoForm.tsx | 17 +++++++++++++---- .../CreateCloudWorkspaceForm.tsx | 12 +++++++++--- .../CreateFirstMemberForm.tsx | 12 +++++++++--- .../CreateNewPassword/CreateNewPassword.tsx | 12 +++++++++--- .../src/forms/NewAccountForm/NewAccountForm.tsx | 17 +++++++++++++---- .../RegisterServerForm/RegisterServerForm.tsx | 7 +++++-- .../forms/RequestTrialForm/RequestTrialForm.tsx | 7 +++++-- .../ResetPasswordForm/ResetPasswordForm.tsx | 7 +++++-- .../src/pages/AdminInfoPage/AdminInfoPage.tsx | 17 +++++++++++++---- .../CreateNewAccountPage.tsx | 17 +++++++++++++---- .../CreateNewPasswordPage.tsx | 12 +++++++++--- .../RegisterServerPage/RegisterServerPage.tsx | 7 +++++-- .../ResetPasswordPage/ResetPasswordPage.tsx | 7 +++++-- 13 files changed, 113 insertions(+), 38 deletions(-) diff --git a/packages/onboarding-ui/src/forms/AdminInfoForm/AdminInfoForm.tsx b/packages/onboarding-ui/src/forms/AdminInfoForm/AdminInfoForm.tsx index b48aa3f7f9..be8ffe9427 100644 --- a/packages/onboarding-ui/src/forms/AdminInfoForm/AdminInfoForm.tsx +++ b/packages/onboarding-ui/src/forms/AdminInfoForm/AdminInfoForm.tsx @@ -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'; @@ -35,9 +35,18 @@ type AdminInfoFormProps = { passwordRulesHint: string; keepPosted?: boolean; initialValues?: Omit; - validateUsername: Validate; - validateEmail: Validate; - validatePassword: Validate; + validateUsername: Validate< + FieldPathValue, + AdminInfoPayload + >; + validateEmail: Validate< + FieldPathValue, + AdminInfoPayload + >; + validatePassword: Validate< + FieldPathValue, + AdminInfoPayload + >; onSubmit: SubmitHandler; }; diff --git a/packages/onboarding-ui/src/forms/CreateCloudWorkspaceForm/CreateCloudWorkspaceForm.tsx b/packages/onboarding-ui/src/forms/CreateCloudWorkspaceForm/CreateCloudWorkspaceForm.tsx index 967bec17eb..f01fc53889 100644 --- a/packages/onboarding-ui/src/forms/CreateCloudWorkspaceForm/CreateCloudWorkspaceForm.tsx +++ b/packages/onboarding-ui/src/forms/CreateCloudWorkspaceForm/CreateCloudWorkspaceForm.tsx @@ -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'; @@ -42,8 +42,14 @@ type CreateCloudWorkspaceFormProps = { languageOptions: SelectOption[]; domain: string; onBackButtonClick?: () => void; - validateUrl: Validate; - validateEmail: Validate; + validateUrl: Validate< + FieldPathValue, + CreateCloudWorkspaceFormPayload + >; + validateEmail: Validate< + FieldPathValue, + CreateCloudWorkspaceFormPayload + >; }; const CreateCloudWorkspaceForm = ({ diff --git a/packages/onboarding-ui/src/forms/CreateFirstMemberForm/CreateFirstMemberForm.tsx b/packages/onboarding-ui/src/forms/CreateFirstMemberForm/CreateFirstMemberForm.tsx index a4a8790237..c0c7d25084 100644 --- a/packages/onboarding-ui/src/forms/CreateFirstMemberForm/CreateFirstMemberForm.tsx +++ b/packages/onboarding-ui/src/forms/CreateFirstMemberForm/CreateFirstMemberForm.tsx @@ -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'; @@ -29,8 +29,14 @@ type CreateFirstMemberFormProps = { organizationName: string; onSubmit: SubmitHandler; onBackButtonClick: () => void; - validateUsername: Validate; - validatePassword: Validate; + validateUsername: Validate< + FieldPathValue, + CreateFirstMemberFormPayload + >; + validatePassword: Validate< + FieldPathValue, + CreateFirstMemberFormPayload + >; }; const CreateFirstMemberForm = ({ diff --git a/packages/onboarding-ui/src/forms/CreateNewPassword/CreateNewPassword.tsx b/packages/onboarding-ui/src/forms/CreateNewPassword/CreateNewPassword.tsx index 5f8bf22009..6e7c64b73f 100644 --- a/packages/onboarding-ui/src/forms/CreateNewPassword/CreateNewPassword.tsx +++ b/packages/onboarding-ui/src/forms/CreateNewPassword/CreateNewPassword.tsx @@ -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'; @@ -21,8 +21,14 @@ export type CreateNewPasswordPayload = { type CreateNewPasswordProps = { initialValues?: CreateNewPasswordPayload; - validatePassword: Validate; - validatePasswordConfirmation: Validate; + validatePassword: Validate< + FieldPathValue, + CreateNewPasswordPayload + >; + validatePasswordConfirmation: Validate< + FieldPathValue, + CreateNewPasswordPayload + >; onSubmit: SubmitHandler; }; diff --git a/packages/onboarding-ui/src/forms/NewAccountForm/NewAccountForm.tsx b/packages/onboarding-ui/src/forms/NewAccountForm/NewAccountForm.tsx index de94bcc06c..bd0a7ec44b 100644 --- a/packages/onboarding-ui/src/forms/NewAccountForm/NewAccountForm.tsx +++ b/packages/onboarding-ui/src/forms/NewAccountForm/NewAccountForm.tsx @@ -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'; @@ -29,9 +29,18 @@ export type NewAccountPayload = { type NewAccountFormProps = { initialValues?: Omit; - validateEmail: Validate; - validatePassword: Validate; - validateConfirmationPassword: Validate; + validateEmail: Validate< + FieldPathValue, + NewAccountPayload + >; + validatePassword: Validate< + FieldPathValue, + NewAccountPayload + >; + validateConfirmationPassword: Validate< + FieldPathValue, + NewAccountPayload + >; onSubmit: SubmitHandler; }; diff --git a/packages/onboarding-ui/src/forms/RegisterServerForm/RegisterServerForm.tsx b/packages/onboarding-ui/src/forms/RegisterServerForm/RegisterServerForm.tsx index 6172fb0591..b679fd5ef3 100644 --- a/packages/onboarding-ui/src/forms/RegisterServerForm/RegisterServerForm.tsx +++ b/packages/onboarding-ui/src/forms/RegisterServerForm/RegisterServerForm.tsx @@ -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'; @@ -29,7 +29,10 @@ type RegisterServerFormProps = { currentStep: number; stepCount: number; initialValues?: Partial; - validateEmail?: Validate; + validateEmail?: Validate< + FieldPathValue, + RegisterServerPayload + >; onSubmit: SubmitHandler; onClickRegisterOffline: () => void; termsHref?: string; diff --git a/packages/onboarding-ui/src/forms/RequestTrialForm/RequestTrialForm.tsx b/packages/onboarding-ui/src/forms/RequestTrialForm/RequestTrialForm.tsx index d476cb89b3..debf0be782 100644 --- a/packages/onboarding-ui/src/forms/RequestTrialForm/RequestTrialForm.tsx +++ b/packages/onboarding-ui/src/forms/RequestTrialForm/RequestTrialForm.tsx @@ -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'; @@ -35,7 +35,10 @@ type RequestTrialFormProps = { countryOptions: SelectOption[]; onSubmit: SubmitHandler; onManageWorkspaceClick: () => void; - validateEmail: Validate; + validateEmail: Validate< + FieldPathValue, + RequestTrialPayload + >; termsHref?: string; policyHref?: string; }; diff --git a/packages/onboarding-ui/src/forms/ResetPasswordForm/ResetPasswordForm.tsx b/packages/onboarding-ui/src/forms/ResetPasswordForm/ResetPasswordForm.tsx index 9fc0557b9a..3c6fc15b7f 100644 --- a/packages/onboarding-ui/src/forms/ResetPasswordForm/ResetPasswordForm.tsx +++ b/packages/onboarding-ui/src/forms/ResetPasswordForm/ResetPasswordForm.tsx @@ -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'; @@ -21,7 +21,10 @@ export type ResetPasswordFormPayload = { type ResetPasswordFormProps = { initialValues?: ResetPasswordFormPayload; - validateEmail: Validate; + validateEmail: Validate< + FieldPathValue, + ResetPasswordFormPayload + >; onSubmit: SubmitHandler; }; diff --git a/packages/onboarding-ui/src/pages/AdminInfoPage/AdminInfoPage.tsx b/packages/onboarding-ui/src/pages/AdminInfoPage/AdminInfoPage.tsx index 97a0da6fb2..a8d58c8241 100644 --- a/packages/onboarding-ui/src/pages/AdminInfoPage/AdminInfoPage.tsx +++ b/packages/onboarding-ui/src/pages/AdminInfoPage/AdminInfoPage.tsx @@ -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'; @@ -15,9 +15,18 @@ type AdminInfoPageProps = { passwordRulesHint: string; keepPosted?: boolean; initialValues?: Omit; - validateUsername: Validate; - validateEmail: Validate; - validatePassword: Validate; + validateUsername: Validate< + FieldPathValue, + AdminInfoPayload + >; + validateEmail: Validate< + FieldPathValue, + AdminInfoPayload + >; + validatePassword: Validate< + FieldPathValue, + AdminInfoPayload + >; onSubmit: SubmitHandler; }; diff --git a/packages/onboarding-ui/src/pages/CreateNewAccountPage/CreateNewAccountPage.tsx b/packages/onboarding-ui/src/pages/CreateNewAccountPage/CreateNewAccountPage.tsx index b78c35dc67..4d556b610d 100644 --- a/packages/onboarding-ui/src/pages/CreateNewAccountPage/CreateNewAccountPage.tsx +++ b/packages/onboarding-ui/src/pages/CreateNewAccountPage/CreateNewAccountPage.tsx @@ -6,7 +6,7 @@ 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'; @@ -14,9 +14,18 @@ import type { NewAccountPayload } from '../../forms/NewAccountForm/NewAccountFor type CreateNewAccountPageProps = { initialValues?: Omit; - validateEmail: Validate; - validatePassword: Validate; - validateConfirmationPassword: Validate; + validateEmail: Validate< + FieldPathValue, + NewAccountPayload + >; + validatePassword: Validate< + FieldPathValue, + NewAccountPayload + >; + validateConfirmationPassword: Validate< + FieldPathValue, + NewAccountPayload + >; onSubmit: SubmitHandler; onLogin: () => void; }; diff --git a/packages/onboarding-ui/src/pages/CreateNewPasswordPage/CreateNewPasswordPage.tsx b/packages/onboarding-ui/src/pages/CreateNewPasswordPage/CreateNewPasswordPage.tsx index b9b4255fa9..f953d7553e 100644 --- a/packages/onboarding-ui/src/pages/CreateNewPasswordPage/CreateNewPasswordPage.tsx +++ b/packages/onboarding-ui/src/pages/CreateNewPasswordPage/CreateNewPasswordPage.tsx @@ -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'; @@ -11,8 +11,14 @@ import type { CreateNewPasswordPayload } from '../../forms/CreateNewPassword/Cre type CreateNewPasswordPageProps = { initialValues?: CreateNewPasswordPayload; - validatePassword: Validate; - validatePasswordConfirmation: Validate; + validatePassword: Validate< + FieldPathValue, + CreateNewPasswordPayload + >; + validatePasswordConfirmation: Validate< + FieldPathValue, + CreateNewPasswordPayload + >; onSubmit: SubmitHandler; onLogin: () => void; }; diff --git a/packages/onboarding-ui/src/pages/RegisterServerPage/RegisterServerPage.tsx b/packages/onboarding-ui/src/pages/RegisterServerPage/RegisterServerPage.tsx index dd4b25eeb2..97c5d9b4f7 100644 --- a/packages/onboarding-ui/src/pages/RegisterServerPage/RegisterServerPage.tsx +++ b/packages/onboarding-ui/src/pages/RegisterServerPage/RegisterServerPage.tsx @@ -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'; @@ -14,7 +14,10 @@ type RegisterServerPageProps = { onSubmit: SubmitHandler; onClickRegisterOffline: () => void; offline?: boolean; - validateEmail?: Validate; + validateEmail?: Validate< + FieldPathValue, + RegisterServerPayload + >; termsHref?: string; policyHref?: string; }; diff --git a/packages/onboarding-ui/src/pages/ResetPasswordPage/ResetPasswordPage.tsx b/packages/onboarding-ui/src/pages/ResetPasswordPage/ResetPasswordPage.tsx index 099b77a8d3..cf1073b968 100644 --- a/packages/onboarding-ui/src/pages/ResetPasswordPage/ResetPasswordPage.tsx +++ b/packages/onboarding-ui/src/pages/ResetPasswordPage/ResetPasswordPage.tsx @@ -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'; @@ -11,7 +11,10 @@ import type { ResetPasswordFormPayload } from '../../forms/ResetPasswordForm/Res type ResetPasswordPageProps = { initialValues?: ResetPasswordFormPayload; - validateEmail: Validate; + validateEmail: Validate< + FieldPathValue, + ResetPasswordFormPayload + >; onSubmit: SubmitHandler; onLogin: () => void; };