From 53a16cba11887c6983a2f6676c6ad3d7a6f0cbe1 Mon Sep 17 00:00:00 2001 From: Eduardo Peredo Rivero Date: Wed, 5 Jun 2024 09:59:20 -0500 Subject: [PATCH] get feedback config from json instead ts file --- public/app-config.template.json | 20 ++++++++++++++++++++ src/app-config.template.ts | 1 + src/app-config.ts | 21 --------------------- src/presentation/webapp/WebApp.tsx | 15 ++++++++++----- 4 files changed, 31 insertions(+), 26 deletions(-) create mode 100644 public/app-config.template.json delete mode 100644 src/app-config.ts diff --git a/public/app-config.template.json b/public/app-config.template.json new file mode 100644 index 000000000..e44b110b2 --- /dev/null +++ b/public/app-config.template.json @@ -0,0 +1,20 @@ +{ + "appKey": "metadata-synchronization", + "appearance": { + "showShareButton": false + }, + "feedback": { + "repositories": { + "clickUp": { + "listId": "170646828", + "title": "[User feedback] {title}", + "body": "## dhis2\n\nUsername: {username}\n\n{body}" + } + }, + "layoutOptions": { + "showContact": false, + "descriptionTemplate": "## Summary\n\n## Steps to reproduce\n\n## Actual results\n\n## Expected results\n\n" + } + }, + "encryptionKey": "" +} diff --git a/src/app-config.template.ts b/src/app-config.template.ts index 120a4f45a..05159355f 100644 --- a/src/app-config.template.ts +++ b/src/app-config.template.ts @@ -6,4 +6,5 @@ export interface AppConfig { showShareButton: boolean; }; feedback: FeedbackOptions; + encryptionKey: string; } diff --git a/src/app-config.ts b/src/app-config.ts deleted file mode 100644 index 7bc3f2334..000000000 --- a/src/app-config.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { AppConfig } from "./app-config.template"; - -export const appConfig: AppConfig = { - appKey: "metadata-synchronization", - appearance: { - showShareButton: false, - }, - feedback: { - repositories: { - clickUp: { - listId: "170646828", - title: "[User feedback] {title}", - body: "## dhis2\n\nUsername: {username}\n\n{body}", - }, - }, - layoutOptions: { - showContact: false, - descriptionTemplate: "## Summary\n\n## Steps to reproduce\n\n## Actual results\n\n## Expected results\n\n", - }, - }, -}; diff --git a/src/presentation/webapp/WebApp.tsx b/src/presentation/webapp/WebApp.tsx index f0f16d069..6df030d47 100644 --- a/src/presentation/webapp/WebApp.tsx +++ b/src/presentation/webapp/WebApp.tsx @@ -22,7 +22,8 @@ import { muiTheme } from "../react/core/themes/dhis2.theme"; import Root from "./Root"; import "./WebApp.css"; import { Feedback } from "@eyeseetea/feedback-component"; -import { appConfig } from "../../app-config"; +import { AppConfig } from "../../app-config.template"; +import { Maybe } from "../../types/utils"; const generateClassName = createGenerateClassName({ productionPrefix: "c", @@ -33,13 +34,17 @@ const App = () => { const [appContext, setAppContext] = useState(null); const [username, setUsername] = useState(""); const [showShareButton, setShowShareButton] = useState(false); + const [appConfig, setAppConfig] = useState>(); const migrations = useMigrations(appContext); const appTitle = process.env.REACT_APP_PRESENTATION_TITLE; useEffect(() => { const run = async () => { - const encryptionKey = appConfig?.appKey; + const configFromJson = (await fetch("app-config.json", { + credentials: "same-origin", + }).then(res => res.json())) as AppConfig; + const encryptionKey = configFromJson.encryptionKey; if (!encryptionKey) throw new Error("You need to provide a valid encryption key"); const d2 = await init({ baseUrl: `${baseUrl}/api` }); const api = new D2Api({ baseUrl, backend: "fetch" }); @@ -50,7 +55,6 @@ const App = () => { url: baseUrl, version, }); - const compositionRoot = new CompositionRoot(instance, encryptionKey); await compositionRoot.app.initialize(); const currentUser = await compositionRoot.user.current(); @@ -61,11 +65,12 @@ const App = () => { Object.assign(window, { d2, api }); setShowShareButton(_(appConfig).get("appearance.showShareButton") || false); setUsername(currentUser.username); + setAppConfig(configFromJson); await initializeAppRoles(baseUrl); }; run(); - }, [baseUrl]); + }, [appConfig, baseUrl]); if (migrations.state.type === "pending") { return ( @@ -91,7 +96,7 @@ const App = () => { - + {appConfig && }