diff --git a/src/lib/pages/shared/UserProfileCommons.tsx b/src/lib/pages/shared/UserProfileCommons.tsx index 445f56b6..dfb22500 100644 --- a/src/lib/pages/shared/UserProfileCommons.tsx +++ b/src/lib/pages/shared/UserProfileCommons.tsx @@ -1,13 +1,15 @@ -import React, { useEffect, Fragment } from "react"; +import "../../tools/Array.prototype.every"; +import React, { useEffect, useMemo, useReducer, Fragment } from "react"; import type { KcProps } from "../../KcProps"; -import type { Attribute } from "../../getKcContext/KcContextBase"; +import type { KcContextBase, Validators, Attribute } from "../../getKcContext"; import { clsx } from "../../tools/clsx"; -import { useCallbackFactory } from "../../tools/useCallbackFactory"; -import { useFormValidationSlice } from "../../useFormValidationSlice"; -import type { I18nBase } from "../../i18n"; +import { useConstCallback } from "../../tools/useConstCallback"; +import { emailRegexp } from "../../tools/emailRegExp"; +import type { I18nBase, 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 +28,9 @@ export function UserProfileFormFields({ const { formValidationState: { fieldStateByAttributeName, isFormSubmittable }, - formValidationReducer, + formValidationDispatch, attributesWithPassword - } = useFormValidationSlice({ + } = useFormValidation({ kcContext, i18n }); @@ -37,29 +39,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 +87,19 @@ export function UserProfileFormFields({