Skip to content

Commit

Permalink
fix: remove unnecessary code and put loader
Browse files Browse the repository at this point in the history
  • Loading branch information
mjatin-dev committed Apr 29, 2022
1 parent 34695c3 commit 6d55d8a
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 154 deletions.
12 changes: 0 additions & 12 deletions admin-ui/app/redux/actions/LicenseActions.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import {
CHECK_FOR_VALID_LICENSE,
CHECK_FOR_VALID_LICENSE_RESPONSE,
ACTIVATE_LICENSE,
ACTIVATE_LICENSE_RESPONSE,
ACTIVATE_CHECK_USER_API,
ACTIVATE_CHECK_LICENCE_API_VALID,
ACTIVATE_CHECK_USER_LICENSE_KEY_RESPONSE,
Expand Down Expand Up @@ -35,13 +33,3 @@ export const checkLicensePresentResponse = (isLicenseValid) => ({
type: CHECK_FOR_VALID_LICENSE_RESPONSE,
payload: { isLicenseValid },
})

export const activateLicense = (licenseKey, token) => ({
type: ACTIVATE_LICENSE,
payload: { licenseKey, token },
})

export const activateLicenseResponse = (isLicenseValid) => ({
type: ACTIVATE_LICENSE_RESPONSE,
payload: { isLicenseValid },
})
2 changes: 0 additions & 2 deletions admin-ui/app/redux/actions/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ export const USER_LOGGED_OUT = 'USER_LOGGED_OUT'
export const CHECK_FOR_VALID_LICENSE = 'CHECK_FOR_VALID_LICENSE'
export const CHECK_FOR_VALID_LICENSE_RESPONSE =
'CHECK_FOR_VALID_LICENSE_RESPONSE'
export const ACTIVATE_LICENSE = 'ACTIVATE_LICENSE'
export const ACTIVATE_LICENSE_RESPONSE = 'ACTIVATE_LICENSE_RESPONSE'
export const ACTIVATE_CHECK_USER_API = 'ACTIVATE_CHECK_USER_API'
export const ACTIVATE_CHECK_USER_LICENSE_KEY = 'ACTIVATE_CHECK_USER_LICENSE_KEY'
export const ACTIVATE_CHECK_USER_LICENSE_KEY_RESPONSE =
Expand Down
50 changes: 0 additions & 50 deletions admin-ui/app/redux/api/backend-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import axios_instance from 'axios'
const JansConfigApi = require('jans_config_api')
import { useSelector } from 'react-redux'
// Get OAuth2 Configuration
const licenceApi = new JansConfigApi.AdminUILicenseApi()

export const fetchServerConfiguration = async (token) => {
const headers = { Authorization: `Bearer ${token}` }
Expand Down Expand Up @@ -87,52 +86,3 @@ export const fetchApiTokenWithDefaultScopes = async () => {
return -1
})
}

// Check License present

export const checkLicensePresent = async (token) => {
console.log('checkLicensePresentcheckLicensePresent')
const headers = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers':
'Origin, X-Requested-With, Content-Type, Accept',
'Content-Type': 'application/json',
'Access-Control-Allow-Credentials': true,
// issuer: token,
Authorization: `Bearer ${token}`,
}
console.log('HEADERS', headers)
licenceApi
.isLicenseActive({ headers })
.then((data) => {
console.log('data', data)
})
.catch((err) => {
console.log('err', err)
})
return false
// return axios
// .get('/license/checkLicense', { headers })
// .then((response) => response.data)
// .catch((error) => {
// console.error('Error checking license of admin-ui', error)
// return false
// })
}

// Activate license using key
export const activateLicense = async (licenseKey, token) => {
let data = { licenseKey: licenseKey }
return axios
.post('/license/activateLicense', data, {
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
},
})
.then((response) => response.data)
.catch((e) => {
console.error('Error in activating license of admin-ui', e)
return false
})
}
20 changes: 0 additions & 20 deletions admin-ui/app/redux/reducers/LicenseReducer.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import {
CHECK_FOR_VALID_LICENSE,
CHECK_FOR_VALID_LICENSE_RESPONSE,
ACTIVATE_LICENSE,
ACTIVATE_LICENSE_RESPONSE,
ACTIVATE_CHECK_USER_API,
ACTIVATE_CHECK_LICENCE_API_VALID,
ACTIVATE_CHECK_USER_LICENSE_KEY_RESPONSE,
Expand Down Expand Up @@ -83,24 +81,6 @@ export default function licenseReducer(state = INIT_STATE, action) {
islicenseCheckResultLoaded: true,
}
}
case ACTIVATE_LICENSE:
return {
...state,
isLicenseActivationResultLoaded: false,
}
case ACTIVATE_LICENSE_RESPONSE:
if (action.payload.isLicenseValid) {
return {
...state,
isLicenseValid: action.payload.isLicenseValid,
isLicenseActivationResultLoaded: true,
}
} else {
return {
...state,
isLicenseActivationResultLoaded: true,
}
}

default:
return {
Expand Down
27 changes: 1 addition & 26 deletions admin-ui/app/redux/sagas/LicenseSaga.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@
import { all, call, fork, put, take, takeEvery } from 'redux-saga/effects'
import {
CHECK_FOR_VALID_LICENSE,
ACTIVATE_LICENSE,
ACTIVATE_CHECK_USER_API,
ACTIVATE_CHECK_USER_LICENSE_KEY,
} from '../actions/types'
import {
checkLicensePresentResponse,
activateLicenseResponse,
} from '../actions'
import { checkLicensePresentResponse } from '../actions'

import LicenseApi from '../api/LicenseApi'
import { getClient, getClientWithToken } from '../api/base'
Expand All @@ -33,14 +29,12 @@ function* getApiTokenWithDefaultScopes() {
getClientWithToken(JansConfigApi, response.access_token),
)
return new LicenseApi(api)
// return response.access_token
}

function* checkLicensePresentWorker() {
try {
const licenseApi = yield* getApiTokenWithDefaultScopes()
const response = yield call(licenseApi.getIsActive)
// console.log(response.apiResult)
if (response) {
yield put(checkLicensePresentResponse(response.apiResult))
return
Expand All @@ -52,20 +46,6 @@ function* checkLicensePresentWorker() {
yield put(checkLicensePresentResponse())
}

function* activateLicenseWorker({ payload }) {
try {
const token = yield* getApiTokenWithDefaultScopes()
const response = yield call(activateLicense, payload.licenseKey, token)
if (response) {
yield put(activateLicenseResponse(response))
return
}
} catch (error) {
console.log('Error in activating license.', error)
}
yield put(activateLicenseResponse())
}

function* activateCheckUserApi({ payload }) {
try {
const licenseApi = yield* getApiTokenWithDefaultScopes()
Expand All @@ -91,10 +71,6 @@ export function* checkLicensePresentWatcher() {
yield takeEvery(ACTIVATE_CHECK_USER_LICENSE_KEY, activateCheckUserLicenseKey)
}

export function* activateLicenseWatcher() {
yield takeEvery(ACTIVATE_LICENSE, activateLicenseWorker)
}

export function* activateCheckApiKeyWatcher() {
yield takeEvery(ACTIVATE_CHECK_USER_API, activateCheckUserApi)
}
Expand All @@ -104,7 +80,6 @@ export function* activateCheckApiKeyWatcher() {
export default function* rootSaga() {
yield all([
fork(checkLicensePresentWatcher),
fork(activateLicenseWatcher),
fork(activateCheckApiKeyWatcher),
])
}
40 changes: 0 additions & 40 deletions admin-ui/app/utils/ApiKeyRedirect.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,55 +7,15 @@ import ApiKey from './LicenseScreens/ApiKey'
function ApiKeyRedirect({
backendIsUp,
isLicenseValid,
activateLicense,
redirectUrl,
islicenseCheckResultLoaded,
isLicenseActivationResultLoaded,
}) {
const { t } = useTranslation()
function submitForm(message) {
activateLicense(message.trim())
}

function toggle() {
window.location.href = redirectUrl
}

return (
<React.Fragment>
<Container>
{/* <div
style={{
backgroundColor: 'white',
margin: 'auto',
marginTop: '20%',
}}
>
<img
style={{
display: 'block',
marginLeft: 'auto',
marginTop: 'auto',
marginRight: 'auto',
width: '100%',
height: '100%',
}}
src={require('../images/gif/npe-redirecting.gif')}
alt="loading..."
/>
</div> */}
{!isLicenseValid && islicenseCheckResultLoaded && <ApiKey />}
{/* <GluuCommitDialog
handler={toggle}
modal={!isLicenseValid && islicenseCheckResultLoaded}
onAccept={submitForm}
isLoading={false}
label={t(
'License key required to access Gluu Admin UI. Please enter license key.',
)}
placeholderLabel={t('Enter license key')}
inputType={'text'}
/> */}
{!backendIsUp && (
<GluuNotification
type="error"
Expand Down
4 changes: 0 additions & 4 deletions admin-ui/app/utils/AppAuthProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
getAPIAccessToken,
getUserLocation,
checkLicensePresent,
activateLicense,
} from '../redux/actions'
import SessionTimeout from '../routes/Apps/Gluu/GluuSessionTimeout'

Expand Down Expand Up @@ -101,7 +100,6 @@ class AppAuthProvider extends Component {
}
render() {
const { showContent } = this.state
console.log(showContent)
return (
<React.Fragment>
<SessionTimeout isAuthenticated={showContent} />
Expand All @@ -110,7 +108,6 @@ class AppAuthProvider extends Component {
<ApiKeyRedirect
backendIsUp={this.props.backendIsUp}
isLicenseValid={this.props.isLicenseValid}
activateLicense={this.props.activateLicense}
redirectUrl={this.props.config.redirectUrl}
islicenseCheckResultLoaded={this.props.islicenseCheckResultLoaded}
isLicenseActivationResultLoaded={
Expand Down Expand Up @@ -154,6 +151,5 @@ export default withRouter(
getAPIAccessToken,
getUserLocation,
checkLicensePresent,
activateLicense,
})(AppAuthProvider),
)
8 changes: 8 additions & 0 deletions admin-ui/app/utils/LicenseScreens/ApiKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React, { useEffect, useState } from 'react'
import { checkUserApi, checkUserLicenceKey } from '../../redux/actions'
import logo from './../../images/logos/logo192.png'
import { useDispatch, useSelector } from 'react-redux'
import './style.css'

function ApiKey() {
const dispatch = useDispatch()
const serverError = useSelector((state) => state.licenseReducer.error)
Expand Down Expand Up @@ -76,6 +78,11 @@ function ApiKey() {

return (
<div>
{isLoading && (
<div className="loader-outer">
<div className="loader"></div>
</div>
)}
<div className="container text-dark">
<div className="row">
<div className="col-md-12 text-center my-5">
Expand All @@ -96,6 +103,7 @@ function ApiKey() {
{serverError}
</div>
</div>

{!isLicenceAPIkeyValid ? (
<div className="row">
<div className="col-md-8 mx-auto">
Expand Down
40 changes: 40 additions & 0 deletions admin-ui/app/utils/LicenseScreens/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
.loader-outer {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0.6);
z-index: 999;
justify-content: center;
align-items: center;
display: flex;
}
.loader {
border: 4px solid #f3f3f3;
border-radius: 50%;
border-top: 4px solid #089857;
width: 40px;
height: 40px;
-webkit-animation: spin 2s linear infinite; /* Safari */
animation: spin 2s linear infinite;
}

/* Safari */
@-webkit-keyframes spin {
0% {
-webkit-transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
}
}

@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}

0 comments on commit 6d55d8a

Please sign in to comment.