157 lines
7.3 KiB
TypeScript
Raw Normal View History

2021-03-04 18:15:48 +01:00
import { useState, memo } from "react";
import { Template } from "./Template";
import type { KcPagesProperties } from "./KcProperties";
import { defaultKcPagesProperties } from "./KcProperties";
2021-03-04 21:14:54 +01:00
import { assert } from "../tools/assert";
2021-03-04 18:15:48 +01:00
import { kcContext } from "../kcContext";
import { useKcTranslation } from "../i18n/useKcTranslation";
import { cx } from "tss-react";
export type RegisterPageProps = {
kcProperties?: KcPagesProperties;
};
export const Register = memo((props: RegisterPageProps) => {
const { kcProperties = {} } = props;
const { t, tStr } = useKcTranslation();
Object.assign(kcProperties, defaultKcPagesProperties);
const [{
url,
messagesPerField,
register,
realm,
passwordRequired,
recaptchaRequired,
recaptchaSiteKey
2021-03-04 21:14:54 +01:00
}] = useState(() => {
2021-03-04 18:15:48 +01:00
assert(
2021-03-04 21:14:54 +01:00
kcContext !== undefined &&
kcContext.pageBasename === "register.ftl"
);
return kcContext;
});
2021-03-04 18:15:48 +01:00
return (
<Template
kcProperties={kcProperties}
headerNode={t("registerTitle")}
formNode={
<form id="kc-register-form" className={cx(kcProperties.kcFormClass)} action={url.registrationAction} method="post">
<div className={cx(kcProperties.kcFormGroupClass, messagesPerField.printIfExists('firstName', kcProperties.kcFormGroupErrorClass))}>
<div className={cx(kcProperties.kcLabelWrapperClass)}>
<label htmlFor="firstName" className={cx(kcProperties.kcLabelClass)}>{t("firstName")}</label>
</div>
<div className={cx(kcProperties.kcInputWrapperClass)}>
<input type="text" id="firstName" className={cx(kcProperties.kcInputClass)} name="firstName"
2021-03-05 00:44:27 +01:00
defaultValue={register.formData.firstName ?? ""}
2021-03-04 18:15:48 +01:00
/>
</div>
</div>
<div className={cx(kcProperties.kcFormGroupClass, messagesPerField.printIfExists("lastName", kcProperties.kcFormGroupErrorClass))}>
<div className={cx(kcProperties.kcLabelWrapperClass)}>
<label htmlFor="lastName" className={cx(kcProperties.kcLabelClass)}>{t("lastName")}</label>
</div>
<div className={cx(kcProperties.kcInputWrapperClass)}>
<input type="text" id="lastName" className={cx(kcProperties.kcInputClass)} name="lastName"
2021-03-05 00:44:27 +01:00
defaultValue={register.formData.lastName ?? ""}
2021-03-04 18:15:48 +01:00
/>
</div>
</div>
<div className={cx(kcProperties.kcFormGroupClass, messagesPerField.printIfExists('email', kcProperties.kcFormGroupErrorClass))}>
<div className={cx(kcProperties.kcLabelWrapperClass)}>
<label htmlFor="email" className={cx(kcProperties.kcLabelClass)}>{t("email")}</label>
</div>
<div className={cx(kcProperties.kcInputWrapperClass)}>
<input type="text" id="email" className={cx(kcProperties.kcInputClass)} name="email"
2021-03-05 00:44:27 +01:00
defaultValue={register.formData.email ?? ""} autoComplete="email"
2021-03-04 18:15:48 +01:00
/>
</div>
</div>
{
!realm.registrationEmailAsUsername &&
<div className={cx(kcProperties.kcFormGroupClass, messagesPerField.printIfExists('username', kcProperties.kcFormGroupErrorClass))}>
<div className={cx(kcProperties.kcLabelWrapperClass)}>
<label htmlFor="username" className={cx(kcProperties.kcLabelClass)}>{t("username")}</label>
</div>
<div className={cx(kcProperties.kcInputWrapperClass)}>
<input type="text" id="username" className={cx(kcProperties.kcInputClass)} name="username"
2021-03-05 00:44:27 +01:00
defaultValue={register.formData.username ?? ""} autoComplete="username" />
2021-03-04 18:15:48 +01:00
</div>
</div >
}
{
passwordRequired &&
<>
<div className={cx(kcProperties.kcFormGroupClass, messagesPerField.printIfExists("password", kcProperties.kcFormGroupErrorClass))}>
<div className={cx(kcProperties.kcLabelWrapperClass)}>
<label htmlFor="password" className={cx(kcProperties.kcLabelClass)}>{t("password")}</label>
</div>
<div className={cx(kcProperties.kcInputWrapperClass)}>
<input type="password" id="password" className={cx(kcProperties.kcInputClass)} name="password" autoComplete="new-password" />
</div>
</div>
<div className={cx(kcProperties.kcFormGroupClass, messagesPerField.printIfExists("password-confirm", kcProperties.kcFormGroupErrorClass))}>
<div className={cx(kcProperties.kcLabelWrapperClass)}>
<label htmlFor="password-confirm" className={cx(kcProperties.kcLabelClass)}>{t("passwordConfirm")}</label>
</div>
<div className={cx(kcProperties.kcInputWrapperClass)}>
<input type="password" id="password-confirm" className={cx(kcProperties.kcInputClass)} name="password-confirm" />
</div>
</div>
</>
}
{
recaptchaRequired &&
<div className="form-group">
<div className={cx(kcProperties.kcInputWrapperClass)}>
<div className="g-recaptcha" data-size="compact" data-sitekey={recaptchaSiteKey}></div>
</div>
</div>
}
<div className={cx(kcProperties.kcFormGroupClass)}>
<div id="kc-form-options" className={cx(kcProperties.kcFormOptionsClass)}>
<div className={cx(kcProperties.kcFormOptionsWrapperClass)}>
<span><a href={url.loginUrl}>{t("backToLogin")}</a></span>
</div>
</div>
<div id="kc-form-buttons" className={cx(kcProperties.kcFormButtonsClass)}>
<input className={cx(kcProperties.kcButtonClass, kcProperties.kcButtonPrimaryClass, kcProperties.kcButtonBlockClass, kcProperties.kcButtonLargeClass)} type="submit"
2021-03-05 00:44:27 +01:00
defaultValue={tStr("doRegister")} />
2021-03-04 18:15:48 +01:00
</div>
</div>
</form >
}
/>
);
});
2021-03-05 00:44:27 +01:00
// JSX.IntrinsicElements.input: React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>