This commit is contained in:
Joseph Garrone 2024-06-09 12:32:25 +02:00
parent b6159180ea
commit ca3f963f0b
7 changed files with 31 additions and 23 deletions

View File

@ -18,7 +18,7 @@
"license": "MIT", "license": "MIT",
"keywords": [], "keywords": [],
"dependencies": { "dependencies": {
"keycloakify": "10.0.0-rc.40", "keycloakify": "10.0.0-rc.42",
"react": "^18.2.0", "react": "^18.2.0",
"react-dom": "^18.2.0" "react-dom": "^18.2.0"
}, },

View File

@ -1,20 +1,24 @@
import { Suspense } from "react"; import { Suspense } from "react";
import type { ClassKey } from "keycloakify/account"; import type { ClassKey } from "keycloakify/account";
import type { KcContext } from "./KcContext"; import type { KcContext } from "./KcContext";
import Fallback from "keycloakify/account/Fallback"; import { useI18n } from "./i18n";
import DefaultPage from "keycloakify/account/DefaultPage";
import Template from "keycloakify/account/Template"; import Template from "keycloakify/account/Template";
export default function KcApp(props: { kcContext: KcContext }) { export default function KcApp(props: { kcContext: KcContext }) {
const { kcContext } = props; const { kcContext } = props;
const { i18n } = useI18n({ kcContext });
return ( return (
<Suspense> <Suspense>
{(() => { {(() => {
switch (kcContext.pageId) { switch (kcContext.pageId) {
default: default:
return ( return (
<Fallback <DefaultPage
kcContext={kcContext} kcContext={kcContext}
i18n={i18n}
classes={classes} classes={classes}
Template={Template} Template={Template}
doUseDefaultCss={true} doUseDefaultCss={true}

View File

@ -5,7 +5,7 @@ import type {
KcContextExtension, KcContextExtension,
KcContextExtensionPerPage KcContextExtensionPerPage
} from "./KcContext"; } from "./KcContext";
import KcApp from "./KcApp"; import KcPage from "./KcPage";
import { themeNames, kcEnvDefaults } from "../kc.gen"; import { themeNames, kcEnvDefaults } from "../kc.gen";
const kcContextExtension: KcContextExtension = { const kcContextExtension: KcContextExtension = {
@ -23,12 +23,12 @@ export const { getKcContextMock } = createGetKcContextMock({
overridesPerPage: {} overridesPerPage: {}
}); });
export function createPageStory<PageId extends KcContext["pageId"]>(params: { export function createKcPageStory<PageId extends KcContext["pageId"]>(params: {
pageId: PageId; pageId: PageId;
}) { }) {
const { pageId } = params; const { pageId } = params;
function PageStory(props: { function KcPageStory(props: {
kcContext?: DeepPartial<Extract<KcContext, { pageId: PageId }>>; kcContext?: DeepPartial<Extract<KcContext, { pageId: PageId }>>;
}) { }) {
const { kcContext: overrides } = props; const { kcContext: overrides } = props;
@ -38,8 +38,8 @@ export function createPageStory<PageId extends KcContext["pageId"]>(params: {
overrides overrides
}); });
return <KcApp kcContext={kcContextMock} />; return <KcPage kcContext={kcContextMock} />;
} }
return { PageStory }; return { KcPageStory };
} }

View File

@ -2,7 +2,8 @@ import { Suspense, lazy } from "react";
import type { ClassKey } from "keycloakify/login"; import type { ClassKey } from "keycloakify/login";
import type { KcContext } from "./KcContext"; import type { KcContext } from "./KcContext";
import { useDownloadTerms } from "keycloakify/login"; import { useDownloadTerms } from "keycloakify/login";
import Fallback from "keycloakify/login/Fallback"; import { useI18n } from "./i18n";
import DefaultPage from "keycloakify/login/DefaultPage";
import Template from "keycloakify/login/Template"; import Template from "keycloakify/login/Template";
const UserProfileFormFields = lazy(() => import("keycloakify/login/UserProfileFormFields")); const UserProfileFormFields = lazy(() => import("keycloakify/login/UserProfileFormFields"));
@ -36,14 +37,17 @@ export default function KcApp(props: { kcContext: KcContext }) {
} }
}); });
const { i18n } = useI18n({ kcContext });
return ( return (
<Suspense> <Suspense>
{(() => { {(() => {
switch (kcContext.pageId) { switch (kcContext.pageId) {
default: default:
return ( return (
<Fallback <DefaultPage
kcContext={kcContext} kcContext={kcContext}
i18n={i18n}
classes={classes} classes={classes}
Template={Template} Template={Template}
doUseDefaultCss={true} doUseDefaultCss={true}

View File

@ -1,6 +1,6 @@
import type { DeepPartial } from "keycloakify/tools/DeepPartial"; import type { DeepPartial } from "keycloakify/tools/DeepPartial";
import type { KcContext } from "./KcContext"; import type { KcContext } from "./KcContext";
import KcApp from "./KcApp"; import KcPage from "./KcPage";
import { createGetKcContextMock } from "keycloakify/login/KcContext"; import { createGetKcContextMock } from "keycloakify/login/KcContext";
import type { import type {
KcContextExtension, KcContextExtension,
@ -23,12 +23,12 @@ export const { getKcContextMock } = createGetKcContextMock({
overridesPerPage: {} overridesPerPage: {}
}); });
export function createPageStory<PageId extends KcContext["pageId"]>(params: { export function createKcPageStory<PageId extends KcContext["pageId"]>(params: {
pageId: PageId; pageId: PageId;
}) { }) {
const { pageId } = params; const { pageId } = params;
function PageStory(props: { function KcPageStory(props: {
kcContext?: DeepPartial<Extract<KcContext, { pageId: PageId }>>; kcContext?: DeepPartial<Extract<KcContext, { pageId: PageId }>>;
}) { }) {
const { kcContext: overrides } = props; const { kcContext: overrides } = props;
@ -38,8 +38,8 @@ export function createPageStory<PageId extends KcContext["pageId"]>(params: {
overrides overrides
}); });
return <KcApp kcContext={kcContextMock} />; return <KcPage kcContext={kcContextMock} />;
} }
return { PageStory }; return { KcPageStory };
} }

View File

@ -15,8 +15,8 @@ if (import.meta.env.DEV) {
} }
*/ */
const KcLoginThemeApp = lazy(() => import("./login/KcApp")); const KcLoginThemePage = lazy(() => import("./login/KcPage"));
const KcAccountThemeApp = lazy(() => import("./account/KcApp")); const KcAccountThemePage = lazy(() => import("./account/KcPage"));
createRoot(document.getElementById("root")!).render( createRoot(document.getElementById("root")!).render(
<StrictMode> <StrictMode>
@ -24,9 +24,9 @@ createRoot(document.getElementById("root")!).render(
{(() => { {(() => {
switch (window.kcContext?.themeType) { switch (window.kcContext?.themeType) {
case "login": case "login":
return <KcLoginThemeApp kcContext={window.kcContext} />; return <KcLoginThemePage kcContext={window.kcContext} />;
case "account": case "account":
return <KcAccountThemeApp kcContext={window.kcContext} />; return <KcAccountThemePage kcContext={window.kcContext} />;
} }
return <h1>No Keycloak Context</h1>; return <h1>No Keycloak Context</h1>;
})()} })()}

View File

@ -5011,10 +5011,10 @@ jsonfile@^6.0.1:
optionalDependencies: optionalDependencies:
graceful-fs "^4.1.6" graceful-fs "^4.1.6"
keycloakify@10.0.0-rc.40: keycloakify@10.0.0-rc.42:
version "10.0.0-rc.40" version "10.0.0-rc.42"
resolved "https://registry.yarnpkg.com/keycloakify/-/keycloakify-10.0.0-rc.40.tgz#f383e72b4981da1973d09c6211103fdbd2efa818" resolved "https://registry.yarnpkg.com/keycloakify/-/keycloakify-10.0.0-rc.42.tgz#66bb6f49553e5e14b115d601e85bdde61432e154"
integrity sha512-JL3UJAAunCfZSw0JOMv/B9BD75jnOiLjxIIbbs/Gj+Djg9Db+w2kg5N11Q5/EIxkQRRCdFSVIII3NgZ7EQevcw== integrity sha512-nSIU/3t+Jwz2alJpf5Z3JiY0/pC/tzNcSIhkno/a8XMs7r2fEH/KC8dqBTh4E0ZhbTvZp7j3wy80atdIqzeKDA==
dependencies: dependencies:
react-markdown "^5.0.3" react-markdown "^5.0.3"
tsafe "^1.6.6" tsafe "^1.6.6"