diff --git a/src/lib/KcApp.tsx b/src/lib/KcApp.tsx index fd4b7bf3..813d5354 100644 --- a/src/lib/KcApp.tsx +++ b/src/lib/KcApp.tsx @@ -1,6 +1,6 @@ import React, { lazy, Suspense } from "react"; import { __unsafe_useI18n as useI18n } from "./i18n"; -import DefaultTemplate from "./pages/Template"; +import DefaultTemplate from "./Template"; import type { KcContextBase } from "./getKcContext/KcContextBase"; import type { PageProps } from "./KcProps"; import type { I18nBase } from "./i18n"; diff --git a/src/lib/Template.tsx b/src/lib/Template.tsx index 8dfea143..3527800e 100644 --- a/src/lib/Template.tsx +++ b/src/lib/Template.tsx @@ -1,6 +1,4 @@ import React, { useReducer, useEffect } from "react"; -import { useCallbackFactory } from "./tools/useCallbackFactory"; -import { useConstCallback } from "./tools/useConstCallback"; import { assert } from "./tools/assert"; import { headInsert } from "./tools/headInsert"; import { pathJoin } from "../bin/tools/pathJoin"; @@ -27,10 +25,6 @@ export default function Template(props: TemplateProps changeLocale(kcLanguageTag)); - - const onTryAnotherWayClick = useConstCallback(() => (document.forms["kc-select-try-another-way-form" as never].submit(), false)); - const { realm, locale, auth, url, message, isAppInitiatedAction } = kcContext; const [isExtraCssLoaded, setExtraCssLoaded] = useReducer(() => true, false); @@ -117,7 +111,7 @@ export default function Template(props: TemplateProps (
  • {/* eslint-disable-next-line jsx-a11y/anchor-is-valid */} - + changeLocale(languageTag)}> {labelBySupportedLanguageTag[languageTag]}
  • @@ -211,7 +205,14 @@ export default function Template(props: TemplateProps {/* eslint-disable-next-line jsx-a11y/anchor-is-valid */} - + { + document.forms["kc-select-try-another-way-form" as never].submit(); + return false; + }} + > {msg("doTryAnotherWay")} diff --git a/src/lib/pages/Template.tsx b/src/lib/pages/Template.tsx deleted file mode 100644 index 4469a88b..00000000 --- a/src/lib/pages/Template.tsx +++ /dev/null @@ -1,230 +0,0 @@ -import React, { useReducer, useEffect } from "react"; -import type { KcContextBase } from "../getKcContext"; -import { assert } from "../tools/assert"; -import { useCallbackFactory } from "../tools/useCallbackFactory"; -import { headInsert } from "../tools/headInsert"; -import { pathJoin } from "../../bin/tools/pathJoin"; -import { useConstCallback } from "../tools/useConstCallback"; -import type { TemplateProps } from "../KcProps"; -import { clsx } from "../tools/clsx"; -import type { I18nBase } from "../i18n"; - -export default function Template(props: TemplateProps) { - const { - displayInfo = false, - displayMessage = true, - displayRequiredFields = false, - displayWide = false, - showAnotherWayIfPresent = true, - headerNode, - showUsernameNode = null, - formNode, - infoNode = null, - kcContext, - i18n, - doFetchDefaultThemeResources - } = props; - - const { msg, changeLocale, labelBySupportedLanguageTag, currentLanguageTag } = i18n; - - const onChangeLanguageClickFactory = useCallbackFactory(([kcLanguageTag]: [string]) => changeLocale(kcLanguageTag)); - - const onTryAnotherWayClick = useConstCallback(() => (document.forms["kc-select-try-another-way-form" as never].submit(), false)); - - const { realm, locale, auth, url, message, isAppInitiatedAction } = kcContext; - - const [isExtraCssLoaded, setExtraCssLoaded] = useReducer(() => true, false); - - useEffect(() => { - if (!doFetchDefaultThemeResources) { - setExtraCssLoaded(); - return; - } - - let isUnmounted = false; - const cleanups: (() => void)[] = []; - - const toArr = (x: string | readonly string[] | undefined) => (typeof x === "string" ? x.split(" ") : x ?? []); - - Promise.all( - [ - ...toArr(props.stylesCommon).map(relativePath => pathJoin(url.resourcesCommonPath, relativePath)), - ...toArr(props.styles).map(relativePath => pathJoin(url.resourcesPath, relativePath)) - ] - .reverse() - .map(href => - headInsert({ - "type": "css", - href, - "position": "prepend" - }) - ) - ).then(() => { - if (isUnmounted) { - return; - } - - setExtraCssLoaded(); - }); - - toArr(props.scripts).forEach(relativePath => - headInsert({ - "type": "javascript", - "src": pathJoin(url.resourcesPath, relativePath) - }) - ); - - if (props.kcHtmlClass !== undefined) { - const htmlClassList = document.getElementsByTagName("html")[0].classList; - - const tokens = clsx(props.kcHtmlClass).split(" "); - - htmlClassList.add(...tokens); - - cleanups.push(() => htmlClassList.remove(...tokens)); - } - - return () => { - isUnmounted = true; - - cleanups.forEach(f => f()); - }; - }, [props.kcHtmlClass]); - - if (!isExtraCssLoaded) { - return null; - } - - return ( -
    -
    -
    - {msg("loginTitleHtml", realm.displayNameHtml)} -
    -
    - -
    -
    - {realm.internationalizationEnabled && (assert(locale !== undefined), true) && locale.supported.length > 1 && ( -
    -
    - -
    -
    - )} - {!(auth !== undefined && auth.showUsername && !auth.showResetCredentials) ? ( - displayRequiredFields ? ( -
    -
    - - * - {msg("requiredFields")} - -
    -
    -

    {headerNode}

    -
    -
    - ) : ( -

    {headerNode}

    - ) - ) : displayRequiredFields ? ( -
    -
    - - * {msg("requiredFields")} - -
    -
    - {showUsernameNode} -
    -
    - - -
    - - {msg("restartLoginTooltip")} -
    -
    -
    -
    -
    -
    - ) : ( - <> - {showUsernameNode} -
    -
    - - -
    - - {msg("restartLoginTooltip")} -
    -
    -
    -
    - - )} -
    -
    -
    - {/* App-initiated actions should not see warning messages about the need to complete the action during login. */} - {displayMessage && message !== undefined && (message.type !== "warning" || !isAppInitiatedAction) && ( -
    - {message.type === "success" && } - {message.type === "warning" && } - {message.type === "error" && } - {message.type === "info" && } - -
    - )} - {formNode} - {auth !== undefined && auth.showTryAnotherWayLink && showAnotherWayIfPresent && ( -
    - -
    - )} - {displayInfo && ( -
    -
    - {infoNode} -
    -
    - )} -
    -
    -
    -
    - ); -}