keycloak_theme/src/login/pages/LoginUpdateProfile.tsx

77 lines
3.4 KiB
TypeScript
Raw Normal View History

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";
import type { I18n } from "../i18n";
import type { LazyOrNot } from "keycloakify/tools/LazyOrNot";
import type { UserProfileFormFieldsProps } from "keycloakify/login/UserProfileFormFields";
2021-06-14 19:06:31 +02:00
type LoginUpdateProfileProps = PageProps<Extract<KcContext, { pageId: "login-update-profile.ftl" }>, I18n> & {
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
const { url, messagesPerField, isAppInitiatedAction } = kcContext;
const { msg, msgStr } = i18n;
const [isFormSubmittable, setIsFormSubmittable] = useState(false);
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">
<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")}>
<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"),
getClassName("kcButtonDefaultClass"),
2023-03-21 02:36:13 +01:00
getClassName("kcButtonLargeClass")
)}
type="submit"
name="cancel-aia"
value="true"
formNoValidate
>
{msg("doCancel")}
</button>
2023-03-21 02:36:13 +01:00
)}
</div>
2023-03-21 02:36:13 +01:00
</div>
</form>
</Template>
);
}