2024-05-08 19:24:18 +02:00
|
|
|
import { useState } from "react";
|
2023-03-27 13:02:44 +03:00
|
|
|
import { clsx } from "keycloakify/tools/clsx";
|
2024-05-08 19:24:18 +02:00
|
|
|
import type { LazyOrNot } from "keycloakify/tools/LazyOrNot";
|
|
|
|
import type { UserProfileFormFieldsProps } from "keycloakify/login/UserProfileFormFields";
|
2023-03-27 13:02:44 +03:00
|
|
|
import type { PageProps } from "keycloakify/login/pages/PageProps";
|
|
|
|
import { useGetClassName } from "keycloakify/login/lib/useGetClassName";
|
|
|
|
import type { KcContext } from "../kcContext";
|
|
|
|
import type { I18n } from "../i18n";
|
|
|
|
|
2024-05-08 19:24:18 +02:00
|
|
|
type UpdateEmailProps = PageProps<Extract<KcContext, { pageId: "update-email.ftl" }>, I18n> & {
|
|
|
|
UserProfileFormFields: LazyOrNot<(props: UserProfileFormFieldsProps) => JSX.Element>;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default function UpdateEmail(props: UpdateEmailProps) {
|
|
|
|
const { kcContext, i18n, doUseDefaultCss, Template, classes, UserProfileFormFields } = props;
|
2023-03-27 13:02:44 +03:00
|
|
|
|
|
|
|
const { getClassName } = useGetClassName({
|
|
|
|
doUseDefaultCss,
|
|
|
|
classes
|
|
|
|
});
|
|
|
|
|
|
|
|
const { msg, msgStr } = i18n;
|
|
|
|
|
2024-05-08 19:24:18 +02:00
|
|
|
const [isFormSubmittable, setIsFormSubmittable] = useState(false);
|
|
|
|
|
|
|
|
const { url, messagesPerField, isAppInitiatedAction } = kcContext;
|
2023-03-27 13:02:44 +03:00
|
|
|
|
|
|
|
return (
|
2024-05-08 19:24:18 +02:00
|
|
|
<Template
|
|
|
|
{...{ kcContext, i18n, doUseDefaultCss, classes }}
|
|
|
|
displayMessage={messagesPerField.exists("global")}
|
|
|
|
displayRequiredFields={true}
|
|
|
|
headerNode={msg("updateEmailTitle")}
|
|
|
|
>
|
2023-03-27 13:02:44 +03:00
|
|
|
<form id="kc-update-email-form" className={getClassName("kcFormClass")} action={url.loginAction} method="post">
|
2024-05-08 19:24:18 +02:00
|
|
|
<UserProfileFormFields
|
|
|
|
{...{
|
|
|
|
kcContext,
|
|
|
|
i18n,
|
|
|
|
getClassName,
|
|
|
|
messagesPerField
|
|
|
|
}}
|
|
|
|
onIsFormSubmittableValueChange={setIsFormSubmittable}
|
|
|
|
/>
|
2023-03-27 13:02:44 +03:00
|
|
|
|
|
|
|
<div className={getClassName("kcFormGroupClass")}>
|
|
|
|
<div id="kc-form-options" className={getClassName("kcFormOptionsClass")}>
|
2024-05-08 19:24:18 +02:00
|
|
|
<div className={getClassName("kcFormOptionsWrapperClass")} />
|
2023-03-27 13:02:44 +03:00
|
|
|
</div>
|
2024-05-08 19:24:18 +02:00
|
|
|
|
|
|
|
<LogoutOtherSessions {...{ getClassName, i18n }} />
|
|
|
|
|
2023-03-27 13:02:44 +03:00
|
|
|
<div id="kc-form-buttons" className={getClassName("kcFormButtonsClass")}>
|
2024-05-08 19:24:18 +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-27 13:02:44 +03:00
|
|
|
className={clsx(
|
|
|
|
getClassName("kcButtonClass"),
|
2024-05-08 19:24:18 +02:00
|
|
|
getClassName("kcButtonDefaultClass"),
|
2023-03-27 13:02:44 +03:00
|
|
|
getClassName("kcButtonLargeClass")
|
|
|
|
)}
|
|
|
|
type="submit"
|
2024-05-08 19:24:18 +02:00
|
|
|
name="cancel-aia"
|
|
|
|
value="true"
|
|
|
|
>
|
|
|
|
{msg("doCancel")}
|
|
|
|
</button>
|
2023-03-27 13:02:44 +03:00
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</Template>
|
|
|
|
);
|
|
|
|
}
|
2024-05-08 19:24:18 +02:00
|
|
|
|
|
|
|
function LogoutOtherSessions(props: { getClassName: ReturnType<typeof useGetClassName>["getClassName"]; i18n: I18n }) {
|
|
|
|
const { getClassName, i18n } = props;
|
|
|
|
|
|
|
|
const { msg } = i18n;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div id="kc-form-options" className={getClassName("kcFormOptionsClass")}>
|
|
|
|
<div className={getClassName("kcFormOptionsWrapperClass")}>
|
|
|
|
<div className="checkbox">
|
|
|
|
<label>
|
|
|
|
<input type="checkbox" id="logout-sessions" name="logout-sessions" value="on" defaultChecked={true} />
|
|
|
|
{msg("logoutOtherSessions")}
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|