} size="large" className={styles.logo} />
diff --git a/hooks/useApi.js b/hooks/useApi.js
index b2e74998..63e88a46 100644
--- a/hooks/useApi.js
+++ b/hooks/useApi.js
@@ -6,7 +6,7 @@ import useStore from 'store/app';
const selector = state => state.shareToken;
-function parseHeaders(headers = {}, { authToken, shareToken }) {
+function parseHeaders(headers, { authToken, shareToken }) {
if (authToken) {
headers.authorization = `Bearer ${authToken}`;
}
@@ -25,7 +25,7 @@ export default function useApi() {
return {
get: useCallback(
- async (url, params, headers) => {
+ async (url, params = {}, headers = {}) => {
return get(
`${basePath}/api${url}`,
params,
@@ -36,7 +36,7 @@ export default function useApi() {
),
post: useCallback(
- async (url, params, headers) => {
+ async (url, params = {}, headers = {}) => {
return post(
`${basePath}/api${url}`,
params,
@@ -47,7 +47,7 @@ export default function useApi() {
),
put: useCallback(
- async (url, params, headers) => {
+ async (url, params = {}, headers = {}) => {
return put(
`${basePath}/api${url}`,
params,
@@ -58,7 +58,7 @@ export default function useApi() {
),
del: useCallback(
- async (url, params, headers) => {
+ async (url, params = {}, headers = {}) => {
return del(
`${basePath}/api${url}`,
params,
diff --git a/hooks/useConfig.js b/hooks/useConfig.js
new file mode 100644
index 00000000..8adedcaf
--- /dev/null
+++ b/hooks/useConfig.js
@@ -0,0 +1,24 @@
+import { useEffect } from 'react';
+import useStore, { setConfig } from 'store/app';
+import useApi from 'hooks/useApi';
+
+let fetched = false;
+
+export default function useConfig() {
+ const { config } = useStore();
+ const { get } = useApi();
+
+ async function loadConfig() {
+ const { data } = await get('/config');
+ setConfig(data);
+ }
+
+ useEffect(() => {
+ if (!config && !fetched) {
+ fetched = true;
+ loadConfig();
+ }
+ }, []);
+
+ return config || {};
+}
diff --git a/pages/_app.js b/pages/_app.js
index 5c83c264..b8653113 100644
--- a/pages/_app.js
+++ b/pages/_app.js
@@ -1,4 +1,3 @@
-import React from 'react';
import Head from 'next/head';
import { useRouter } from 'next/router';
import { IntlProvider } from 'react-intl';
diff --git a/pages/api/config.js b/pages/api/config.js
new file mode 100644
index 00000000..a72eb0ba
--- /dev/null
+++ b/pages/api/config.js
@@ -0,0 +1,14 @@
+import { ok, methodNotAllowed } from 'lib/response';
+
+export default async (req, res) => {
+ if (req.method === 'GET') {
+ return ok(res, {
+ basePath: process.env.BASE_PATH || '',
+ trackerScriptName: process.env.TRACKER_SCRIPT_NAME,
+ updatesDisabled: !!process.env.DISABLE_UPDATES,
+ telemetryDisabled: !!process.env.DISABLE_TELEMETRY,
+ });
+ }
+
+ return methodNotAllowed(res);
+};
diff --git a/store/app.js b/store/app.js
index 65295fd0..ff4a91a4 100644
--- a/store/app.js
+++ b/store/app.js
@@ -20,6 +20,7 @@ const initialState = {
dashboard: getItem(DASHBOARD_CONFIG) || defaultDashboardConfig,
shareToken: null,
user: null,
+ config: null,
};
const store = create(() => ({ ...initialState }));
@@ -45,4 +46,8 @@ export function setDashboard(dashboard) {
setItem(DASHBOARD_CONFIG, dashboard);
}
+export function setConfig(config) {
+ store.setState({ config });
+}
+
export default store;