diff --git a/src/lib/pages/shared/UserProfileCommons.tsx b/src/lib/pages/shared/UserProfileCommons.tsx index 445f56b6..e1c95f87 100644 --- a/src/lib/pages/shared/UserProfileCommons.tsx +++ b/src/lib/pages/shared/UserProfileCommons.tsx @@ -1,13 +1,24 @@ import React, { useEffect, Fragment } from "react"; import type { KcProps } from "../../KcProps"; -import type { Attribute } from "../../getKcContext/KcContextBase"; import { clsx } from "../../tools/clsx"; -import { useCallbackFactory } from "../../tools/useCallbackFactory"; -import { useFormValidationSlice } from "../../useFormValidationSlice"; import type { I18nBase } from "../../i18n"; +import type { Attribute } from "../../getKcContext"; + +// If you are copy pasting this code in your theme project +// you can delete all the following import and replace them by +// import { useFormValidation } from "keycloakify/lib/pages/shared/UserProfileCommons"; +// you can also delete the useFormValidation hooks and useGetErrors hooks, they shouldn't need +// to be modified. +import "../../tools/Array.prototype.every"; +import { useMemo, useReducer } from "react"; +import type { KcContextBase, Validators } from "../../getKcContext"; +import { useConstCallback } from "../../tools/useConstCallback"; +import { emailRegexp } from "../../tools/emailRegExp"; +import type { MessageKeyBase } from "../../i18n"; +import { id } from "tsafe/id"; export type UserProfileFormFieldsProps = { - kcContext: Parameters[0]["kcContext"]; + kcContext: Parameters[0]["kcContext"]; i18n: I18nBase; } & KcProps & Partial JSX.Element | null>> & { @@ -26,9 +37,9 @@ export function UserProfileFormFields({ const { formValidationState: { fieldStateByAttributeName, isFormSubmittable }, - formValidationReducer, + formValidationDispatch, attributesWithPassword - } = useFormValidationSlice({ + } = useFormValidation({ kcContext, i18n }); @@ -37,29 +48,6 @@ export function UserProfileFormFields({ onIsFormSubmittableValueChange(isFormSubmittable); }, [isFormSubmittable]); - const onChangeFactory = useCallbackFactory( - ( - [name]: [string], - [ - { - target: { value } - } - ]: [React.ChangeEvent] - ) => - formValidationReducer({ - "action": "update value", - name, - "newValue": value - }) - ); - - const onBlurFactory = useCallbackFactory(([name]: [string]) => - formValidationReducer({ - "action": "focus lost", - name - }) - ); - let currentGroup = ""; return ( @@ -108,8 +96,19 @@ export function UserProfileFormFields({