2024-05-08 19:24:18 +02:00
|
|
|
import { useState } from "react";
|
|
|
|
import type { LazyOrNot } from "keycloakify/tools/LazyOrNot";
|
2024-06-09 08:27:07 +02:00
|
|
|
import { getKcClsx, type KcClsx } from "keycloakify/login/lib/kcClsx";
|
2024-06-11 20:40:00 +02:00
|
|
|
import type { UserProfileFormFieldsProps } from "keycloakify/login/UserProfileFormFieldsProps";
|
2023-03-27 13:02:44 +03:00
|
|
|
import type { PageProps } from "keycloakify/login/pages/PageProps";
|
2024-06-05 21:13:58 +02:00
|
|
|
import type { KcContext } from "../KcContext";
|
2024-06-09 11:20:45 +02:00
|
|
|
import type { I18n } from "../i18n";
|
2023-03-27 13:02:44 +03:00
|
|
|
|
2024-06-09 11:20:45 +02:00
|
|
|
type UpdateEmailProps = PageProps<Extract<KcContext, { pageId: "update-email.ftl" }>, I18n> & {
|
2024-06-11 20:40:00 +02:00
|
|
|
UserProfileFormFields: LazyOrNot<(props: UserProfileFormFieldsProps<KcContext, I18n>) => JSX.Element>;
|
2024-06-09 09:34:39 +02:00
|
|
|
doMakeUserConfirmPassword: boolean;
|
2024-05-08 19:24:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export default function UpdateEmail(props: UpdateEmailProps) {
|
2024-06-09 11:20:45 +02:00
|
|
|
const { kcContext, i18n, doUseDefaultCss, Template, classes, UserProfileFormFields, doMakeUserConfirmPassword } = props;
|
2023-03-27 13:02:44 +03:00
|
|
|
|
2024-06-09 08:27:07 +02:00
|
|
|
const { kcClsx } = getKcClsx({
|
2023-03-27 13:02:44 +03:00
|
|
|
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
|
2024-06-09 08:27:07 +02:00
|
|
|
kcContext={kcContext}
|
2024-06-09 11:20:45 +02:00
|
|
|
i18n={i18n}
|
2024-06-09 08:27:07 +02:00
|
|
|
doUseDefaultCss={doUseDefaultCss}
|
|
|
|
classes={classes}
|
2024-05-08 19:24:18 +02:00
|
|
|
displayMessage={messagesPerField.exists("global")}
|
2024-05-14 02:37:55 +02:00
|
|
|
displayRequiredFields
|
2024-05-08 19:24:18 +02:00
|
|
|
headerNode={msg("updateEmailTitle")}
|
|
|
|
>
|
2024-06-09 08:27:07 +02:00
|
|
|
<form id="kc-update-email-form" className={kcClsx("kcFormClass")} action={url.loginAction} method="post">
|
2024-06-09 09:34:39 +02:00
|
|
|
<UserProfileFormFields
|
|
|
|
kcContext={kcContext}
|
2024-06-09 11:20:45 +02:00
|
|
|
i18n={i18n}
|
2024-06-09 09:34:39 +02:00
|
|
|
kcClsx={kcClsx}
|
|
|
|
onIsFormSubmittableValueChange={setIsFormSubmittable}
|
|
|
|
doMakeUserConfirmPassword={doMakeUserConfirmPassword}
|
|
|
|
/>
|
2023-03-27 13:02:44 +03:00
|
|
|
|
2024-06-09 08:27:07 +02:00
|
|
|
<div className={kcClsx("kcFormGroupClass")}>
|
|
|
|
<div id="kc-form-options" className={kcClsx("kcFormOptionsClass")}>
|
|
|
|
<div className={kcClsx("kcFormOptionsWrapperClass")} />
|
2023-03-27 13:02:44 +03:00
|
|
|
</div>
|
2024-05-08 19:24:18 +02:00
|
|
|
|
2024-06-09 08:27:07 +02:00
|
|
|
<LogoutOtherSessions kcClsx={kcClsx} i18n={i18n} />
|
2024-05-08 19:24:18 +02:00
|
|
|
|
2024-06-09 08:27:07 +02:00
|
|
|
<div id="kc-form-buttons" className={kcClsx("kcFormButtonsClass")}>
|
2024-05-08 19:24:18 +02:00
|
|
|
<input
|
|
|
|
disabled={!isFormSubmittable}
|
2024-06-09 08:27:07 +02:00
|
|
|
className={kcClsx(
|
|
|
|
"kcButtonClass",
|
|
|
|
"kcButtonPrimaryClass",
|
|
|
|
isAppInitiatedAction && "kcButtonBlockClass",
|
|
|
|
"kcButtonLargeClass"
|
2024-05-08 19:24:18 +02:00
|
|
|
)}
|
|
|
|
type="submit"
|
|
|
|
value={msgStr("doSubmit")}
|
|
|
|
/>
|
|
|
|
{isAppInitiatedAction && (
|
|
|
|
<button
|
2024-06-09 08:27:07 +02:00
|
|
|
className={kcClsx("kcButtonClass", "kcButtonDefaultClass", "kcButtonLargeClass")}
|
2023-03-27 13:02:44 +03:00
|
|
|
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
|
|
|
|
2024-06-09 08:27:07 +02:00
|
|
|
function LogoutOtherSessions(props: { kcClsx: KcClsx; i18n: I18n }) {
|
|
|
|
const { kcClsx, i18n } = props;
|
2024-05-08 19:24:18 +02:00
|
|
|
|
|
|
|
const { msg } = i18n;
|
|
|
|
|
|
|
|
return (
|
2024-06-09 08:27:07 +02:00
|
|
|
<div id="kc-form-options" className={kcClsx("kcFormOptionsClass")}>
|
|
|
|
<div className={kcClsx("kcFormOptionsWrapperClass")}>
|
2024-05-08 19:24:18 +02:00
|
|
|
<div className="checkbox">
|
|
|
|
<label>
|
|
|
|
<input type="checkbox" id="logout-sessions" name="logout-sessions" value="on" defaultChecked={true} />
|
|
|
|
{msg("logoutOtherSessions")}
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|