From 2be3f4e1a08acc8c055876e85b31a34b63f42d71 Mon Sep 17 00:00:00 2001 From: Thomas Zemp Date: Tue, 21 Feb 2023 13:17:11 +0100 Subject: [PATCH 1/5] chore: example updates for login_app type --- adapter/src/components/AppWrapper.js | 30 +++++++++++- .../src/components/ServerVersionProvider.js | 43 +++++++++++------ adapter/src/index.js | 48 +++++++++++++++---- adapter/src/utils/useLocale.js | 7 +++ cli/src/commands/build.js | 9 ++-- cli/src/commands/start.js | 3 +- cli/src/lib/compiler/compile.js | 3 +- cli/src/lib/compiler/entrypoints.js | 3 +- cli/src/lib/parseConfig.js | 8 +++- cli/src/lib/pwa/getPWAEnvVars.js | 4 +- cli/src/lib/shell/index.js | 1 + shell/src/App.js | 1 + 12 files changed, 125 insertions(+), 35 deletions(-) diff --git a/adapter/src/components/AppWrapper.js b/adapter/src/components/AppWrapper.js index bbc9c799a..0c94ffe9a 100644 --- a/adapter/src/components/AppWrapper.js +++ b/adapter/src/components/AppWrapper.js @@ -1,6 +1,9 @@ import PropTypes from 'prop-types' import React from 'react' -import { useCurrentUserLocale } from '../utils/useLocale.js' +import { + useCurrentUserLocale, + useSystemDefaultLocale, +} from '../utils/useLocale.js' import { useVerifyLatestUser } from '../utils/useVerifyLatestUser.js' import { Alerts } from './Alerts.js' import { ConnectedHeaderBar } from './ConnectedHeaderBar.js' @@ -34,3 +37,28 @@ AppWrapper.propTypes = { children: PropTypes.node, plugin: PropTypes.bool, } + +export const LoginAppWrapper = ({ children }) => { + const { loading: localeLoading } = useSystemDefaultLocale() + // cannot check current user for a loginApp (no api/me) + + if (localeLoading) { + return + } + + return ( +
+ +
+ window.location.reload()}> + {children} + +
+ +
+ ) +} + +LoginAppWrapper.propTypes = { + children: PropTypes.node, +} diff --git a/adapter/src/components/ServerVersionProvider.js b/adapter/src/components/ServerVersionProvider.js index 6a76f86cc..c54a7b4f4 100644 --- a/adapter/src/components/ServerVersionProvider.js +++ b/adapter/src/components/ServerVersionProvider.js @@ -13,6 +13,7 @@ export const ServerVersionProvider = ({ url, apiVersion, pwaEnabled, + loginApp, children, }) => { const offlineInterface = useOfflineInterface() @@ -27,28 +28,39 @@ export const ServerVersionProvider = ({ } setState((state) => (state.loading ? state : { loading: true })) - const request = get(`${url}/api/system/info`) - request - .then((systemInfo) => { - setState({ loading: false, systemInfo }) - }) - .catch((e) => { - // Todo: If this is a network error, the app cannot load -- handle that gracefully here - // if (e === 'Network error') { ... } - setState({ loading: false, error: e }) - }) - return () => { - request.abort() + // in reality we probably want a request to get api version + if (loginApp) { + const fakeSystemInfo = { version: '2.40-SNAPSHOT' } + setState({ loading: false, systemInfo: fakeSystemInfo }) + } else { + const request = get(`${url}/api/system/info`) + request + .then((systemInfo) => { + setState({ loading: false, systemInfo }) + }) + .catch((e) => { + // Todo: If this is a network error, the app cannot load -- handle that gracefully here + // if (e === 'Network error') { ... } + setState({ loading: false, error: e }) + }) + + return () => { + request.abort() + } } - }, [url]) + }, [url, loginApp]) if (loading) { return } if (error) { - return + return !loginApp ? ( + + ) : ( +

Specify DHIS2_BASE_URL environment variable

+ ) } const serverVersion = parseDHIS2ServerVersion(systemInfo.version) @@ -65,7 +77,7 @@ export const ServerVersionProvider = ({ systemInfo, pwaEnabled, }} - offlineInterface={offlineInterface} + offlineInterface={loginApp ? null : offlineInterface} > {children} @@ -77,6 +89,7 @@ ServerVersionProvider.propTypes = { appVersion: PropTypes.string.isRequired, apiVersion: PropTypes.number, children: PropTypes.element, + loginApp: PropTypes.bool, pwaEnabled: PropTypes.bool, url: PropTypes.string, } diff --git a/adapter/src/index.js b/adapter/src/index.js index c78084be6..e1b05b5eb 100644 --- a/adapter/src/index.js +++ b/adapter/src/index.js @@ -1,7 +1,7 @@ import { checkForSWUpdateAndReload } from '@dhis2/pwa' import PropTypes from 'prop-types' import React from 'react' -import { AppWrapper } from './components/AppWrapper.js' +import { LoginAppWrapper, AppWrapper } from './components/AppWrapper.js' import { ErrorBoundary } from './components/ErrorBoundary.js' import { OfflineInterfaceProvider } from './components/OfflineInterfaceContext.js' import { PWALoadingBoundary } from './components/PWALoadingBoundary.js' @@ -14,30 +14,58 @@ const AppAdapter = ({ apiVersion, pwaEnabled, plugin, + loginApp, children, -}) => ( - - - +}) => { + if (loginApp) { + return ( + { + window.location.reload() + }} + > - {children} + {children} - - - -) + + ) + } + return ( + + + + + + {children} + + + + + + ) +} AppAdapter.propTypes = { appName: PropTypes.string.isRequired, appVersion: PropTypes.string.isRequired, apiVersion: PropTypes.number, children: PropTypes.element, + loginApp: PropTypes.bool, plugin: PropTypes.bool, pwaEnabled: PropTypes.bool, url: PropTypes.string, diff --git a/adapter/src/utils/useLocale.js b/adapter/src/utils/useLocale.js index 2c34bc94f..b4c47bfb7 100644 --- a/adapter/src/utils/useLocale.js +++ b/adapter/src/utils/useLocale.js @@ -60,3 +60,10 @@ export const useCurrentUserLocale = () => { return { loading: loading || !locale, locale } } + +export const useSystemDefaultLocale = () => { + // TO-DO: system language query (not currently available) + const defaultLocale = window.navigator.language + const locale = useLocale(defaultLocale) + return { loading: !locale, locale } +} diff --git a/cli/src/commands/build.js b/cli/src/commands/build.js index 226b103bd..313d881b5 100644 --- a/cli/src/commands/build.js +++ b/cli/src/commands/build.js @@ -7,6 +7,7 @@ const generateManifests = require('../lib/generateManifests') const i18n = require('../lib/i18n') const loadEnvFiles = require('../lib/loadEnvFiles') const parseConfig = require('../lib/parseConfig') +const { appTypes } = require('../lib/parseConfig') const makePaths = require('../lib/paths') const makePlugin = require('../lib/plugin') const { injectPrecacheManifest } = require('../lib/pwa') @@ -70,7 +71,7 @@ const handler = async ({ const shell = makeShell({ config, paths }) const plugin = makePlugin({ config, paths }) - if (config.type === 'app') { + if (appTypes.includes(config.type)) { setAppParameters(standalone, config) } @@ -105,7 +106,7 @@ const handler = async ({ paths, }) - if (config.type === 'app') { + if (appTypes.includes(config.type)) { reporter.info('Bootstrapping local appShell...') await shell.bootstrap({ shell: shellSource, force }) } @@ -114,7 +115,7 @@ const handler = async ({ `Building ${config.type} ${chalk.bold(config.name)}...` ) - if (config.type === 'app') { + if (appTypes.includes(config.type)) { await compile({ config, paths, @@ -167,7 +168,7 @@ const handler = async ({ } ) - if (config.type === 'app') { + if (appTypes.includes(config.type)) { if (!fs.pathExistsSync(paths.shellBuildOutput)) { reporter.error('No build output found') process.exit(1) diff --git a/cli/src/commands/start.js b/cli/src/commands/start.js index b66ea0433..501309498 100644 --- a/cli/src/commands/start.js +++ b/cli/src/commands/start.js @@ -6,6 +6,7 @@ const generateManifests = require('../lib/generateManifests') const i18n = require('../lib/i18n') const loadEnvFiles = require('../lib/loadEnvFiles') const parseConfig = require('../lib/parseConfig') +const { appTypes } = require('../lib/parseConfig') const makePaths = require('../lib/paths') const makePlugin = require('../lib/plugin') const createProxyServer = require('../lib/proxy') @@ -32,7 +33,7 @@ const handler = async ({ const shell = makeShell({ config, paths }) const plugin = makePlugin({ config, paths }) - if (config.type !== 'app') { + if (!appTypes.includes(config.type)) { reporter.error( `The command ${chalk.bold( 'd2-app-scripts start' diff --git a/cli/src/lib/compiler/compile.js b/cli/src/lib/compiler/compile.js index 775ef8836..213a47358 100644 --- a/cli/src/lib/compiler/compile.js +++ b/cli/src/lib/compiler/compile.js @@ -4,6 +4,7 @@ const { reporter, prettyPrint } = require('@dhis2/cli-helpers-engine') const chokidar = require('chokidar') const fs = require('fs-extra') const makeBabelConfig = require('../../../config/makeBabelConfig.js') +const { appTypes } = require('../parseConfig') const { verifyEntrypoints, createAppEntrypointWrapper, @@ -67,7 +68,7 @@ const compile = async ({ mode = 'development', watch = false, }) => { - const isApp = config.type === 'app' + const isApp = appTypes.includes(config.type) verifyEntrypoints({ config, paths }) if (isApp) { diff --git a/cli/src/lib/compiler/entrypoints.js b/cli/src/lib/compiler/entrypoints.js index bfa801db1..e0d9377d9 100644 --- a/cli/src/lib/compiler/entrypoints.js +++ b/cli/src/lib/compiler/entrypoints.js @@ -1,6 +1,7 @@ const path = require('path') const { reporter, chalk } = require('@dhis2/cli-helpers-engine') const fs = require('fs-extra') +const { appTypes } = require('../parseConfig') const { normalizeExtension } = require('./extensionHelpers.js') const verifyEntrypoint = ({ entrypoint, basePath, resolveModule }) => { @@ -26,7 +27,7 @@ exports.verifyEntrypoints = ({ paths, resolveModule = require.resolve, }) => { - if (config.type === 'app') { + if (appTypes.includes(config.type)) { if ( !config.entryPoints || (!config.entryPoints.app && !config.entryPoints.plugin) diff --git a/cli/src/lib/parseConfig.js b/cli/src/lib/parseConfig.js index 9d5f7c5cf..cb93b01e7 100644 --- a/cli/src/lib/parseConfig.js +++ b/cli/src/lib/parseConfig.js @@ -5,9 +5,12 @@ const parseAuthorString = require('parse-author') const requiredConfigFields = { app: ['name', 'version', 'title', 'entryPoints.app'], + login_app: ['name', 'version', 'title', 'entryPoints.app'], lib: ['name', 'version', 'entryPoints.lib'], } +const appTypes = ['app', 'login_app'] + const parseAuthor = (author) => { if (isPlainObject(author)) { return { @@ -58,7 +61,7 @@ const parseConfigObjects = ( config = defaultsDeep(config, defaults) // Add PWA defaults to apps - if (type === 'app') { + if (appTypes.includes(type)) { config = defaultsDeep(config, defaultsPWA) } @@ -109,3 +112,6 @@ const parseConfig = (paths) => { module.exports = parseConfig module.exports.parseConfigObjects = parseConfigObjects + +module.exports.parseConfigObjects = parseConfigObjects +module.exports.appTypes = appTypes diff --git a/cli/src/lib/pwa/getPWAEnvVars.js b/cli/src/lib/pwa/getPWAEnvVars.js index 6b88710bd..f7577c601 100644 --- a/cli/src/lib/pwa/getPWAEnvVars.js +++ b/cli/src/lib/pwa/getPWAEnvVars.js @@ -1,3 +1,5 @@ +const { appTypes } = require('../parseConfig') + /** Preps string literals for regex conversion by escaping special chars */ function escapeForRegex(string) { return string.replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&') @@ -31,7 +33,7 @@ function stringifyPatterns(patternsList) { * @param {Object} config */ function getPWAEnvVars(config) { - if (config.type !== 'app' || !config.pwa.enabled) { + if (!appTypes.includes(config.type) || !config.pwa.enabled) { return null } return { diff --git a/cli/src/lib/shell/index.js b/cli/src/lib/shell/index.js index e2c737427..6beef5b42 100644 --- a/cli/src/lib/shell/index.js +++ b/cli/src/lib/shell/index.js @@ -7,6 +7,7 @@ module.exports = ({ config, paths }) => { const baseEnvVars = { name: config.title, version: config.version, + loginApp: config.type === 'login_app', } return { diff --git a/shell/src/App.js b/shell/src/App.js index a606488e2..3636319ff 100644 --- a/shell/src/App.js +++ b/shell/src/App.js @@ -15,6 +15,7 @@ const appConfig = { apiVersion: parseInt(process.env.REACT_APP_DHIS2_API_VERSION), pwaEnabled: process.env.REACT_APP_DHIS2_APP_PWA_ENABLED === 'true', plugin: process.env.REACT_APP_DHIS2_APP_PLUGIN === 'true', + loginApp: process.env.REACT_APP_DHIS2_APP_LOGINAPP === 'true', } const App = () => ( From f6abdd0016cddb685b6edb2a2d88ecd63637210b Mon Sep 17 00:00:00 2001 From: Thomas Zemp Date: Thu, 13 Jul 2023 13:50:13 +0200 Subject: [PATCH 2/5] feat: identify loginApp in app-runtime provider --- adapter/src/components/ServerVersionProvider.js | 1 + yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/adapter/src/components/ServerVersionProvider.js b/adapter/src/components/ServerVersionProvider.js index c54a7b4f4..fbc115c42 100644 --- a/adapter/src/components/ServerVersionProvider.js +++ b/adapter/src/components/ServerVersionProvider.js @@ -78,6 +78,7 @@ export const ServerVersionProvider = ({ pwaEnabled, }} offlineInterface={loginApp ? null : offlineInterface} + loginApp={loginApp} > {children} diff --git a/yarn.lock b/yarn.lock index 7e5763d52..a2e4e15e2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2225,10 +2225,10 @@ react-docgen "^6.0.0-alpha.0" url-join "^4.0.1" -"@dhis2/d2-i18n@^1.1.0": - version "1.1.0" - resolved "https://registry.yarnpkg.com/@dhis2/d2-i18n/-/d2-i18n-1.1.0.tgz#ec777c5091f747e4c5aa4f9801c62ba4d1ef3d16" - integrity sha512-x3u58goDQsMfBzy50koxNrJjofJTtjRZOfz6f6Py/wMMJfp/T6vZjWMQgcfWH0JrV6d04K1RTt6bI05wqsVQvg== +"@dhis2/d2-i18n@^1.1.1": + version "1.1.1" + resolved "https://registry.yarnpkg.com/@dhis2/d2-i18n/-/d2-i18n-1.1.1.tgz#acaca32cd00b60fd6b6f1dee571f2817a50e243c" + integrity sha512-X0jOCIKPaYv/2z0/sdkEvcbRiYu5o1FrOwvitiS6aKFxSL/GJ872I+UdHwpWJtL+yM7Z8E1epljazW0LnHUz0Q== dependencies: i18next "^10.3" moment "^2.24.0" From 0df2188d6c0dce80fba9237690eb7249f5cbd485 Mon Sep 17 00:00:00 2001 From: Thomas Zemp Date: Tue, 12 Sep 2023 14:17:48 +0200 Subject: [PATCH 3/5] fix: use isApp function --- cli/src/commands/build.js | 10 +++++----- cli/src/commands/start.js | 4 ++-- cli/src/lib/compiler/compile.js | 12 ++++++------ cli/src/lib/compiler/entrypoints.js | 4 ++-- cli/src/lib/parseConfig.js | 6 ++++-- cli/src/lib/pwa/getPWAEnvVars.js | 4 ++-- 6 files changed, 21 insertions(+), 19 deletions(-) diff --git a/cli/src/commands/build.js b/cli/src/commands/build.js index 313d881b5..609140076 100644 --- a/cli/src/commands/build.js +++ b/cli/src/commands/build.js @@ -7,7 +7,7 @@ const generateManifests = require('../lib/generateManifests') const i18n = require('../lib/i18n') const loadEnvFiles = require('../lib/loadEnvFiles') const parseConfig = require('../lib/parseConfig') -const { appTypes } = require('../lib/parseConfig') +const { isApp } = require('../lib/parseConfig') const makePaths = require('../lib/paths') const makePlugin = require('../lib/plugin') const { injectPrecacheManifest } = require('../lib/pwa') @@ -71,7 +71,7 @@ const handler = async ({ const shell = makeShell({ config, paths }) const plugin = makePlugin({ config, paths }) - if (appTypes.includes(config.type)) { + if (isApp(config.type)) { setAppParameters(standalone, config) } @@ -106,7 +106,7 @@ const handler = async ({ paths, }) - if (appTypes.includes(config.type)) { + if (isApp(config.type)) { reporter.info('Bootstrapping local appShell...') await shell.bootstrap({ shell: shellSource, force }) } @@ -115,7 +115,7 @@ const handler = async ({ `Building ${config.type} ${chalk.bold(config.name)}...` ) - if (appTypes.includes(config.type)) { + if (isApp(config.type)) { await compile({ config, paths, @@ -168,7 +168,7 @@ const handler = async ({ } ) - if (appTypes.includes(config.type)) { + if (isApp(config.type)) { if (!fs.pathExistsSync(paths.shellBuildOutput)) { reporter.error('No build output found') process.exit(1) diff --git a/cli/src/commands/start.js b/cli/src/commands/start.js index 501309498..c08cd3440 100644 --- a/cli/src/commands/start.js +++ b/cli/src/commands/start.js @@ -6,7 +6,7 @@ const generateManifests = require('../lib/generateManifests') const i18n = require('../lib/i18n') const loadEnvFiles = require('../lib/loadEnvFiles') const parseConfig = require('../lib/parseConfig') -const { appTypes } = require('../lib/parseConfig') +const { isApp } = require('../lib/parseConfig') const makePaths = require('../lib/paths') const makePlugin = require('../lib/plugin') const createProxyServer = require('../lib/proxy') @@ -33,7 +33,7 @@ const handler = async ({ const shell = makeShell({ config, paths }) const plugin = makePlugin({ config, paths }) - if (!appTypes.includes(config.type)) { + if (!isApp(config.type)) { reporter.error( `The command ${chalk.bold( 'd2-app-scripts start' diff --git a/cli/src/lib/compiler/compile.js b/cli/src/lib/compiler/compile.js index 213a47358..94842eae1 100644 --- a/cli/src/lib/compiler/compile.js +++ b/cli/src/lib/compiler/compile.js @@ -4,7 +4,7 @@ const { reporter, prettyPrint } = require('@dhis2/cli-helpers-engine') const chokidar = require('chokidar') const fs = require('fs-extra') const makeBabelConfig = require('../../../config/makeBabelConfig.js') -const { appTypes } = require('../parseConfig') +const { isApp } = require('../parseConfig') const { verifyEntrypoints, createAppEntrypointWrapper, @@ -68,10 +68,10 @@ const compile = async ({ mode = 'development', watch = false, }) => { - const isApp = appTypes.includes(config.type) + const isAppType = isApp(config.type) verifyEntrypoints({ config, paths }) - if (isApp) { + if (isAppType) { await createAppEntrypointWrapper({ entrypoint: config.entryPoints.app, paths, @@ -84,13 +84,13 @@ const compile = async ({ } } - const outDir = isApp + const outDir = isAppType ? paths.shellApp : path.join(paths.buildOutput, moduleType) fs.removeSync(outDir) fs.ensureDirSync(outDir) - if (isApp) { + if (isAppType) { fs.removeSync(paths.shellPublic) fs.copySync(paths.shellSourcePublic, paths.shellPublic) } @@ -128,7 +128,7 @@ const compile = async ({ processFileCallback: compileFile, watch, }), - isApp && + isAppType && watchFiles({ inputDir: paths.public, outputDir: paths.shellPublic, diff --git a/cli/src/lib/compiler/entrypoints.js b/cli/src/lib/compiler/entrypoints.js index e0d9377d9..943d548b0 100644 --- a/cli/src/lib/compiler/entrypoints.js +++ b/cli/src/lib/compiler/entrypoints.js @@ -1,7 +1,7 @@ const path = require('path') const { reporter, chalk } = require('@dhis2/cli-helpers-engine') const fs = require('fs-extra') -const { appTypes } = require('../parseConfig') +const { isApp } = require('../parseConfig') const { normalizeExtension } = require('./extensionHelpers.js') const verifyEntrypoint = ({ entrypoint, basePath, resolveModule }) => { @@ -27,7 +27,7 @@ exports.verifyEntrypoints = ({ paths, resolveModule = require.resolve, }) => { - if (appTypes.includes(config.type)) { + if (isApp(config.type)) { if ( !config.entryPoints || (!config.entryPoints.app && !config.entryPoints.plugin) diff --git a/cli/src/lib/parseConfig.js b/cli/src/lib/parseConfig.js index cb93b01e7..a154554b9 100644 --- a/cli/src/lib/parseConfig.js +++ b/cli/src/lib/parseConfig.js @@ -11,6 +11,8 @@ const requiredConfigFields = { const appTypes = ['app', 'login_app'] +const isApp = (type) => appTypes.includes(type) + const parseAuthor = (author) => { if (isPlainObject(author)) { return { @@ -61,7 +63,7 @@ const parseConfigObjects = ( config = defaultsDeep(config, defaults) // Add PWA defaults to apps - if (appTypes.includes(type)) { + if (isApp(type)) { config = defaultsDeep(config, defaultsPWA) } @@ -114,4 +116,4 @@ module.exports = parseConfig module.exports.parseConfigObjects = parseConfigObjects module.exports.parseConfigObjects = parseConfigObjects -module.exports.appTypes = appTypes +module.exports.isApp = isApp diff --git a/cli/src/lib/pwa/getPWAEnvVars.js b/cli/src/lib/pwa/getPWAEnvVars.js index f7577c601..eb6e39a03 100644 --- a/cli/src/lib/pwa/getPWAEnvVars.js +++ b/cli/src/lib/pwa/getPWAEnvVars.js @@ -1,4 +1,4 @@ -const { appTypes } = require('../parseConfig') +const { isApp } = require('../parseConfig') /** Preps string literals for regex conversion by escaping special chars */ function escapeForRegex(string) { @@ -33,7 +33,7 @@ function stringifyPatterns(patternsList) { * @param {Object} config */ function getPWAEnvVars(config) { - if (!appTypes.includes(config.type) || !config.pwa.enabled) { + if (!isApp(config.type) || !config.pwa.enabled) { return null } return { From 151357d2f807769ad45ee605adf5837169b6b90e Mon Sep 17 00:00:00 2001 From: Thomas Zemp Date: Tue, 12 Sep 2023 14:23:35 +0200 Subject: [PATCH 4/5] fix: code format updates --- .../src/components/ServerVersionProvider.js | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/adapter/src/components/ServerVersionProvider.js b/adapter/src/components/ServerVersionProvider.js index fbc115c42..fc09426fd 100644 --- a/adapter/src/components/ServerVersionProvider.js +++ b/adapter/src/components/ServerVersionProvider.js @@ -33,21 +33,21 @@ export const ServerVersionProvider = ({ if (loginApp) { const fakeSystemInfo = { version: '2.40-SNAPSHOT' } setState({ loading: false, systemInfo: fakeSystemInfo }) - } else { - const request = get(`${url}/api/system/info`) - request - .then((systemInfo) => { - setState({ loading: false, systemInfo }) - }) - .catch((e) => { - // Todo: If this is a network error, the app cannot load -- handle that gracefully here - // if (e === 'Network error') { ... } - setState({ loading: false, error: e }) - }) + return + } + const request = get(`${url}/api/system/info`) + request + .then((systemInfo) => { + setState({ loading: false, systemInfo }) + }) + .catch((e) => { + // Todo: If this is a network error, the app cannot load -- handle that gracefully here + // if (e === 'Network error') { ... } + setState({ loading: false, error: e }) + }) - return () => { - request.abort() - } + return () => { + request.abort() } }, [url, loginApp]) From fdcd8a32398ef61f70c61eeb351186ad59d02d5c Mon Sep 17 00:00:00 2001 From: Thomas Zemp Date: Tue, 12 Sep 2023 14:28:26 +0200 Subject: [PATCH 5/5] fix: put LoginAppWrapper in separate file --- adapter/src/components/AppWrapper.js | 30 +-------------------- adapter/src/components/LoginAppWrapper.js | 32 +++++++++++++++++++++++ adapter/src/index.js | 3 ++- 3 files changed, 35 insertions(+), 30 deletions(-) create mode 100644 adapter/src/components/LoginAppWrapper.js diff --git a/adapter/src/components/AppWrapper.js b/adapter/src/components/AppWrapper.js index 0c94ffe9a..bbc9c799a 100644 --- a/adapter/src/components/AppWrapper.js +++ b/adapter/src/components/AppWrapper.js @@ -1,9 +1,6 @@ import PropTypes from 'prop-types' import React from 'react' -import { - useCurrentUserLocale, - useSystemDefaultLocale, -} from '../utils/useLocale.js' +import { useCurrentUserLocale } from '../utils/useLocale.js' import { useVerifyLatestUser } from '../utils/useVerifyLatestUser.js' import { Alerts } from './Alerts.js' import { ConnectedHeaderBar } from './ConnectedHeaderBar.js' @@ -37,28 +34,3 @@ AppWrapper.propTypes = { children: PropTypes.node, plugin: PropTypes.bool, } - -export const LoginAppWrapper = ({ children }) => { - const { loading: localeLoading } = useSystemDefaultLocale() - // cannot check current user for a loginApp (no api/me) - - if (localeLoading) { - return - } - - return ( -
- -
- window.location.reload()}> - {children} - -
- -
- ) -} - -LoginAppWrapper.propTypes = { - children: PropTypes.node, -} diff --git a/adapter/src/components/LoginAppWrapper.js b/adapter/src/components/LoginAppWrapper.js new file mode 100644 index 000000000..7ad42d5af --- /dev/null +++ b/adapter/src/components/LoginAppWrapper.js @@ -0,0 +1,32 @@ +import PropTypes from 'prop-types' +import React from 'react' +import { useSystemDefaultLocale } from '../utils/useLocale.js' +import { Alerts } from './Alerts.js' +import { ErrorBoundary } from './ErrorBoundary.js' +import { LoadingMask } from './LoadingMask.js' +import { styles } from './styles/AppWrapper.style.js' + +export const LoginAppWrapper = ({ children }) => { + const { loading: localeLoading } = useSystemDefaultLocale() + // cannot check current user for a loginApp (no api/me) + + if (localeLoading) { + return + } + + return ( +
+ +
+ window.location.reload()}> + {children} + +
+ +
+ ) +} + +LoginAppWrapper.propTypes = { + children: PropTypes.node, +} diff --git a/adapter/src/index.js b/adapter/src/index.js index e1b05b5eb..d31250d2e 100644 --- a/adapter/src/index.js +++ b/adapter/src/index.js @@ -1,8 +1,9 @@ import { checkForSWUpdateAndReload } from '@dhis2/pwa' import PropTypes from 'prop-types' import React from 'react' -import { LoginAppWrapper, AppWrapper } from './components/AppWrapper.js' +import { AppWrapper } from './components/AppWrapper.js' import { ErrorBoundary } from './components/ErrorBoundary.js' +import { LoginAppWrapper } from './components/LoginAppWrapper.js' import { OfflineInterfaceProvider } from './components/OfflineInterfaceContext.js' import { PWALoadingBoundary } from './components/PWALoadingBoundary.js' import { ServerVersionProvider } from './components/ServerVersionProvider.js'