Skip to content

Commit

Permalink
fix: use useConfig in LoginAppWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
tomzemp committed Apr 26, 2024
1 parent 7d0e82a commit 1febb1f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
7 changes: 4 additions & 3 deletions adapter/src/components/LoginAppWrapper.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useConfig } from '@dhis2/app-runtime'
import PropTypes from 'prop-types'
import React from 'react'
import { useSystemDefaultLocale } from '../utils/useLocale.js'
Expand All @@ -6,8 +7,9 @@ import { ErrorBoundary } from './ErrorBoundary.js'
import { LoadingMask } from './LoadingMask.js'
import { styles } from './styles/AppWrapper.style.js'

export const LoginAppWrapper = ({ url, children }) => {
export const LoginAppWrapper = ({ children }) => {
const { loading: localeLoading } = useSystemDefaultLocale()
const { baseUrl } = useConfig()
// cannot check current user for a loginApp (no api/me)

if (localeLoading) {
Expand All @@ -21,7 +23,7 @@ export const LoginAppWrapper = ({ url, children }) => {
<ErrorBoundary
onRetry={() => window.location.reload()}
loginApp={true}
baseURL={url}
baseURL={baseUrl}
>
{children}
</ErrorBoundary>
Expand All @@ -33,5 +35,4 @@ export const LoginAppWrapper = ({ url, children }) => {

LoginAppWrapper.propTypes = {
children: PropTypes.node,
url: PropTypes.string,
}
6 changes: 0 additions & 6 deletions adapter/src/components/ServerVersionProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const ServerVersionProvider = ({
parentAlertsAdd,
showAlertsInPlugin,
loginApp,
setLoginBaseUrl,
children,
}) => {
const offlineInterface = useOfflineInterface()
Expand Down Expand Up @@ -150,10 +149,6 @@ export const ServerVersionProvider = ({
}
}, [appName, baseUrl, loginApp])

useEffect(() => {
setLoginBaseUrl(baseUrl)
}, [setLoginBaseUrl, baseUrl])

useEffect(() => {
if (pwaEnabled) {
offlineInterface.ready.then(() => {
Expand Down Expand Up @@ -215,7 +210,6 @@ ServerVersionProvider.propTypes = {
parentAlertsAdd: PropTypes.func,
plugin: PropTypes.bool,
pwaEnabled: PropTypes.bool,
setLoginBaseUrl: PropTypes.func,
showAlertsInPlugin: PropTypes.bool,
url: PropTypes.string,
}
8 changes: 2 additions & 6 deletions adapter/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { checkForSWUpdateAndReload } from '@dhis2/pwa'
import PropTypes from 'prop-types'
import React, { useState } from 'react'
import React from 'react'
import { AppWrapper } from './components/AppWrapper.js'
import { ErrorBoundary } from './components/ErrorBoundary.js'
import { LoginAppWrapper } from './components/LoginAppWrapper.js'
Expand All @@ -23,7 +23,6 @@ const AppAdapter = ({
loginApp,
children,
}) => {
const [loginBaseUrl, setLoginBaseUrl] = useState(url)
if (loginApp) {
return (
<ErrorBoundary
Expand All @@ -43,11 +42,8 @@ const AppAdapter = ({
pwaEnabled={pwaEnabled}
loginApp={loginApp}
plugin={false}
setLoginBaseUrl={setLoginBaseUrl}
>
<LoginAppWrapper url={loginBaseUrl}>
{children}
</LoginAppWrapper>
<LoginAppWrapper>{children}</LoginAppWrapper>
</ServerVersionProvider>
</ErrorBoundary>
)
Expand Down

0 comments on commit 1febb1f

Please sign in to comment.