diff --git a/README.md b/README.md index 44ba09e..8531df1 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ yarn yarn keycloak # Build the theme one time (some assets will be copied to # public/keycloak_static, they are needed to dev your page outside of Keycloak) yarn start # See the Hello World app -# Uncomment line 15 of src/KcApp/kcContext, reload https://localhost:3000 +# Uncomment line 15 of src/keycloakTheme/kcContext, reload https://localhost:3000 # You can now develop your Login pages. # Think your theme is ready? Run @@ -89,14 +89,15 @@ and remove unnecessary file. ```bash rm -r src/App -rm src/KcApp/index.ts -mv src/KcApp/* src/ +rm src/keycloakTheme/index.ts +mv src/keycloakTheme/* src/ +rm -r src/keycloakTheme cat << EOF > src/index.tsx import { createRoot } from "react-dom/client"; import { StrictMode } from "react"; import { kcContext } from "./kcContext"; -import KcApp from "KcApp"; +import KcApp from "./KcApp"; if( kcContext === undefined ){ throw new Error( diff --git a/package.json b/package.json index bec2cc6..cb9462f 100755 --- a/package.json +++ b/package.json @@ -33,13 +33,16 @@ "@types/react": "18.0.9", "@types/react-dom": "18.0.4", "react-scripts": "5.0.0", - "typescript": "^4.7.3" + "typescript": "^4.9.5" }, "eslintConfig": { "extends": [ "react-app", "react-app/jest" - ] + ], + "rules": { + "react-hooks/exhaustive-deps": "off" + } }, "browserslist": { "production": [ diff --git a/src/KcApp/KcApp.tsx b/src/KcApp/KcApp.tsx deleted file mode 100644 index 0cd7747..0000000 --- a/src/KcApp/KcApp.tsx +++ /dev/null @@ -1,45 +0,0 @@ -import "./KcApp.css"; -import { lazy, Suspense } from "react"; -import type { KcContext } from "./kcContext"; -import KcAppBase, { defaultKcProps } from "keycloakify"; -import { useI18n } from "./i18n"; - -const Register = lazy(() => import("./Register")); -const Terms = lazy(() => import("./Terms")); -const MyExtraPage1 = lazy(() => import("./MyExtraPage1")); -const MyExtraPage2 = lazy(() => import("./MyExtraPage2")); - -export type Props = { - kcContext: KcContext; -}; - -export default function KcApp({ kcContext }: Props) { - const i18n = useI18n({ kcContext }); - - //NOTE: Locales not yet downloaded - if (i18n === null) { - return null; - } - - const props = { - i18n, - ...defaultKcProps, - // NOTE: The classes are defined in ./KcApp.css - "kcHeaderWrapperClass": "my-color my-font", - }; - - return ( - - {(() => { - switch (kcContext.pageId) { - case "register.ftl": return ; - case "terms.ftl": return ; - case "my-extra-page-1.ftl": return ; - case "my-extra-page-2.ftl": return ; - default: return ; - } - })()} - - ); - -} diff --git a/src/KcApp/MyExtraPage1.tsx b/src/KcApp/MyExtraPage1.tsx deleted file mode 100644 index 1650449..0000000 --- a/src/KcApp/MyExtraPage1.tsx +++ /dev/null @@ -1,14 +0,0 @@ -import { memo } from "react"; -import type { KcProps } from "keycloakify"; -import type { KcContext } from "./kcContext"; -import type { I18n } from "./i18n"; - -type KcContext_MyExtraPage1 = Extract; - -const MyExtraPage1 = memo(({ kcContext, i18n, ...props }: { kcContext: KcContext_MyExtraPage1; i18n: I18n; } & KcProps) => { - - return <>It is up to you to implement this page - -}); - -export default MyExtraPage1; \ No newline at end of file diff --git a/src/KcApp/MyExtraPage2.tsx b/src/KcApp/MyExtraPage2.tsx deleted file mode 100644 index ecdd333..0000000 --- a/src/KcApp/MyExtraPage2.tsx +++ /dev/null @@ -1,16 +0,0 @@ -import { memo } from "react"; -import type { KcProps } from "keycloakify"; -import type { KcContext } from "./kcContext"; -import type { I18n } from "./i18n"; - -type KcContext_MyExtraPage2 = Extract; - -const MyExtraPage2 = memo(({ kcContext, i18n, ...props }: { kcContext: KcContext_MyExtraPage2; i18n: I18n; } & KcProps) => { - - console.log(`TODO: Do something with: ${kcContext.someCustomValue}`); - - return <>It is up to you to implement this page - -}); - -export default MyExtraPage2; \ No newline at end of file diff --git a/src/KcApp/Terms.tsx b/src/KcApp/Terms.tsx deleted file mode 100644 index 59ed62c..0000000 --- a/src/KcApp/Terms.tsx +++ /dev/null @@ -1,94 +0,0 @@ -import { memo } from "react"; -import Template from "keycloakify/lib/components/Template"; -import type { KcProps } from "keycloakify"; -import { useDownloadTerms } from "keycloakify"; -import type { KcContext } from "./kcContext"; -import type { I18n } from "./i18n"; -import { evtTermMarkdown } from "keycloakify/lib/components/Terms"; -import { useRerenderOnStateChange } from "evt/hooks"; -import tos_en_url from "./tos_en.md"; -import tos_fr_url from "./tos_fr.md"; -import { clsx } from "keycloakify/lib/tools/clsx"; - -/** - * NOTE: Yo do not need to do all this to put your own Terms and conditions - * this is if you want component level customization. - * If the default works for you you can just use the useDownloadTerms hook - * in the KcApp.tsx - * Example: https://github.com/garronej/keycloakify-starter/blob/a20c21b2aae7c6dc6dbea294f3d321955ddf9355/src/KcApp/KcApp.tsx#L14-L30 - */ - -type KcContext_Terms = Extract; - -const Terms = memo( - ({ - kcContext, - i18n, - ...props - }: { kcContext: KcContext_Terms; i18n: I18n } & KcProps) => { - const { url } = kcContext; - - useDownloadTerms({ - kcContext, - "downloadTermMarkdown": async ({ currentLanguageTag }) => { - - const markdownString = await fetch((() => { - switch (currentLanguageTag) { - case "fr": return tos_fr_url; - default: return tos_en_url; - } - })()).then(response => response.text()); - - return markdownString; - }, - }); - - useRerenderOnStateChange(evtTermMarkdown); - - if (evtTermMarkdown.state === undefined) { - return null; - } - - const { msg, msgStr } = i18n; - - return ( -