Skip to content

Commit

Permalink
Merge pull request #956 from EyeSeeTea/fix/encription-key
Browse files Browse the repository at this point in the history
get feedback config from app-config.json file
  • Loading branch information
MiquelAdell authored Jun 6, 2024
2 parents f477899 + 53a16cb commit 3958996
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 26 deletions.
20 changes: 20 additions & 0 deletions public/app-config.template.json
Original file line number Diff line number Diff line change
@@ -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": ""
}
1 change: 1 addition & 0 deletions src/app-config.template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export interface AppConfig {
showShareButton: boolean;
};
feedback: FeedbackOptions;
encryptionKey: string;
}
21 changes: 0 additions & 21 deletions src/app-config.ts

This file was deleted.

15 changes: 10 additions & 5 deletions src/presentation/webapp/WebApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -33,13 +34,17 @@ const App = () => {
const [appContext, setAppContext] = useState<AppContextState | null>(null);
const [username, setUsername] = useState("");
const [showShareButton, setShowShareButton] = useState(false);
const [appConfig, setAppConfig] = useState<Maybe<AppConfig>>();
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" });
Expand All @@ -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();
Expand All @@ -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 (
Expand All @@ -91,7 +96,7 @@ const App = () => {
</div>

<Share visible={showShareButton} />
<Feedback options={appConfig?.feedback} username={username} />
{appConfig && <Feedback options={appConfig.feedback} username={username} />}
</SnackbarProvider>
</LoadingProvider>
</OldMuiThemeProvider>
Expand Down

0 comments on commit 3958996

Please sign in to comment.