Skip to content

Commit

Permalink
fix: code review cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tomzemp committed Apr 26, 2024
1 parent 1febb1f commit 98b9f55
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
11 changes: 7 additions & 4 deletions adapter/src/components/LoginModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ import { styles } from './styles/LoginModal.style.js'
// Check if base URL is set statically as an env var (typical in production)
const staticUrl = process.env.REACT_APP_DHIS2_BASE_URL

const getUseNewLoginAPI = async (server) => {
const getIsNewLoginAPIAvailable = async (server) => {
try {
// if loginConfig is available, the instance can use new endpoints
await get(`${server}/api/loginConfig`)
return true
} catch (e) {
// if loginConfig is not available, the instance must use old endpoints
console.error(e)
return false
}
}
Expand Down Expand Up @@ -99,9 +100,11 @@ export const LoginModal = ({ appName, baseUrl, loginApp = false }) => {
}
}

const useNewLoginAPI = await getUseNewLoginAPI(server)
const isNewLoginAPIAvailable = await getIsNewLoginAPIAvailable(
server
)

if (useNewLoginAPI) {
if (isNewLoginAPIAvailable) {
loginWithNewEndpoints({
server,
username,
Expand Down Expand Up @@ -129,7 +132,7 @@ export const LoginModal = ({ appName, baseUrl, loginApp = false }) => {
{error && (
<div className="errorNotification">
<NoticeBox error title={i18n.t('Could not log in')}>
{error?.message || error?.details?.message}
{error?.message}
</NoticeBox>
</div>
)}
Expand Down
1 change: 0 additions & 1 deletion adapter/src/components/ServerVersionProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ export const ServerVersionProvider = ({
plugin={plugin}
parentAlertsAdd={parentAlertsAdd}
showAlertsInPlugin={showAlertsInPlugin}
skipApiVersion={loginApp ? true : false}
>
{children}
</Provider>
Expand Down
1 change: 0 additions & 1 deletion adapter/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ const AppAdapter = ({
plugin={plugin}
parentAlertsAdd={parentAlertsAdd}
showAlertsInPlugin={showAlertsInPlugin}
setLoginBaseUrl={() => {}}
>
<AppWrapper
plugin={plugin}
Expand Down
9 changes: 8 additions & 1 deletion adapter/src/utils/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ const request = (url, options) => {
})
.then((response) => {
if (response.status !== 200) {
reject('Request failed ' + response.statusText)
response
.json()
.then((json) => {
reject(json)
})
.catch(() => {
reject('Request failed ' + response.statusText)
})
return
}
try {
Expand Down

0 comments on commit 98b9f55

Please sign in to comment.