2024-05-08 16:10:03 +02:00
|
|
|
import { useState } from "react";
|
2023-03-18 06:14:05 +01:00
|
|
|
import { clsx } from "keycloakify/tools/clsx";
|
2023-03-21 05:27:31 +01:00
|
|
|
import type { PageProps } from "keycloakify/login/pages/PageProps";
|
|
|
|
import { useGetClassName } from "keycloakify/login/lib/useGetClassName";
|
2023-03-18 18:27:50 +01:00
|
|
|
import type { KcContext } from "../kcContext";
|
2023-03-18 18:54:33 +01:00
|
|
|
import type { I18n } from "../i18n";
|
2024-05-08 16:10:03 +02:00
|
|
|
import type { LazyOrNot } from "keycloakify/tools/LazyOrNot";
|
|
|
|
import type { UserProfileFormFieldsProps } from "keycloakify/login/UserProfileFormFields";
|
2021-06-14 19:06:31 +02:00
|
|
|
|
2024-05-13 03:35:24 +02:00
|
|
|
type LoginUpdateProfileProps = PageProps<Extract<KcContext, { pageId: "login-update-profile.ftl" }>, I18n> & {
|
2024-05-08 16:10:03 +02:00
|
|
|
UserProfileFormFields: LazyOrNot<(props: UserProfileFormFieldsProps) => JSX.Element>;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default function LoginUpdateProfile(props: LoginUpdateProfileProps) {
|
|
|
|
const { kcContext, i18n, doUseDefaultCss, Template, classes, UserProfileFormFields } = props;
|
2023-03-18 06:14:05 +01:00
|
|
|
|
|
|
|
const { getClassName } = useGetClassName({
|
2023-03-21 05:27:31 +01:00
|
|
|
doUseDefaultCss,
|
2023-03-18 06:14:05 +01:00
|
|
|
classes
|
|
|
|
});
|
2021-08-20 17:03:50 +02:00
|
|
|
|
2024-05-08 16:10:03 +02:00
|
|
|
const { url, messagesPerField, isAppInitiatedAction } = kcContext;
|
|
|
|
|
2022-10-13 11:58:31 +02:00
|
|
|
const { msg, msgStr } = i18n;
|
2022-09-27 21:30:33 +02:00
|
|
|
|
2024-05-08 16:10:03 +02:00
|
|
|
const [isFormSubmittable, setIsFormSubmittable] = useState(false);
|
2022-09-27 21:30:33 +02:00
|
|
|
|
2022-10-13 11:58:31 +02:00
|
|
|
return (
|
2023-03-21 02:36:13 +01:00
|
|
|
<Template {...{ kcContext, i18n, doUseDefaultCss, classes }} headerNode={msg("loginProfileTitle")}>
|
|
|
|
<form id="kc-update-profile-form" className={getClassName("kcFormClass")} action={url.loginAction} method="post">
|
2024-05-08 16:10:03 +02:00
|
|
|
<UserProfileFormFields
|
|
|
|
{...{
|
|
|
|
kcContext,
|
|
|
|
i18n,
|
|
|
|
getClassName,
|
|
|
|
messagesPerField
|
|
|
|
}}
|
|
|
|
onIsFormSubmittableValueChange={setIsFormSubmittable}
|
|
|
|
/>
|
2023-03-21 02:36:13 +01:00
|
|
|
<div className={getClassName("kcFormGroupClass")}>
|
|
|
|
<div id="kc-form-options" className={getClassName("kcFormOptionsClass")}>
|
|
|
|
<div className={getClassName("kcFormOptionsWrapperClass")} />
|
|
|
|
</div>
|
|
|
|
<div id="kc-form-buttons" className={getClassName("kcFormButtonsClass")}>
|
2024-05-08 16:10:03 +02:00
|
|
|
<input
|
|
|
|
disabled={!isFormSubmittable}
|
|
|
|
className={clsx(
|
|
|
|
getClassName("kcButtonClass"),
|
|
|
|
getClassName("kcButtonPrimaryClass"),
|
|
|
|
!isAppInitiatedAction && getClassName("kcButtonBlockClass"),
|
|
|
|
getClassName("kcButtonLargeClass")
|
|
|
|
)}
|
|
|
|
type="submit"
|
|
|
|
value={msgStr("doSubmit")}
|
|
|
|
/>
|
|
|
|
{isAppInitiatedAction && (
|
|
|
|
<button
|
2023-03-21 02:36:13 +01:00
|
|
|
className={clsx(
|
|
|
|
getClassName("kcButtonClass"),
|
2024-05-08 16:10:03 +02:00
|
|
|
getClassName("kcButtonDefaultClass"),
|
2023-03-21 02:36:13 +01:00
|
|
|
getClassName("kcButtonLargeClass")
|
|
|
|
)}
|
|
|
|
type="submit"
|
2024-05-08 16:10:03 +02:00
|
|
|
name="cancel-aia"
|
|
|
|
value="true"
|
|
|
|
formNoValidate
|
|
|
|
>
|
|
|
|
{msg("doCancel")}
|
|
|
|
</button>
|
2023-03-21 02:36:13 +01:00
|
|
|
)}
|
2022-10-13 11:58:31 +02:00
|
|
|
</div>
|
2023-03-21 02:36:13 +01:00
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</Template>
|
2022-10-13 11:58:31 +02:00
|
|
|
);
|
2023-02-25 18:11:23 +01:00
|
|
|
}
|