Consolidate UI configuration in one place, allowing it to be overridden from the server
This commit is contained in:
@@ -1,11 +1,12 @@
|
|||||||
import jwtDecode from 'jwt-decode'
|
import jwtDecode from 'jwt-decode'
|
||||||
import md5 from 'md5-hex'
|
import md5 from 'md5-hex'
|
||||||
import baseUrl from './utils/baseUrl'
|
import baseUrl from './utils/baseUrl'
|
||||||
|
import config from './config'
|
||||||
|
|
||||||
const authProvider = {
|
const authProvider = {
|
||||||
login: ({ username, password }) => {
|
login: ({ username, password }) => {
|
||||||
let url = baseUrl('/app/login')
|
let url = baseUrl('/app/login')
|
||||||
if (localStorage.getItem('initialAccountCreation')) {
|
if (config.firstTime) {
|
||||||
url = baseUrl('/app/createAdmin')
|
url = baseUrl('/app/createAdmin')
|
||||||
}
|
}
|
||||||
const request = new Request(url, {
|
const request = new Request(url, {
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
const defaultConfig = {
|
||||||
|
firstTime: false,
|
||||||
|
baseURL: '',
|
||||||
|
loginBackgroundURL: 'https://source.unsplash.com/random/1600x900?music'
|
||||||
|
}
|
||||||
|
|
||||||
|
let config
|
||||||
|
|
||||||
|
try {
|
||||||
|
const appConfig = JSON.parse(window.__APP_CONFIG__)
|
||||||
|
|
||||||
|
config = {
|
||||||
|
...defaultConfig,
|
||||||
|
...appConfig
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
config = defaultConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
export default config
|
||||||
@@ -15,6 +15,7 @@ import LockIcon from '@material-ui/icons/Lock'
|
|||||||
import { Notification, useLogin, useNotify, useTranslate } from 'react-admin'
|
import { Notification, useLogin, useNotify, useTranslate } from 'react-admin'
|
||||||
|
|
||||||
import LightTheme from '../themes/light'
|
import LightTheme from '../themes/light'
|
||||||
|
import config from '../config'
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const useStyles = makeStyles((theme) => ({
|
||||||
main: {
|
main: {
|
||||||
@@ -23,7 +24,7 @@ const useStyles = makeStyles((theme) => ({
|
|||||||
minHeight: '100vh',
|
minHeight: '100vh',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
justifyContent: 'flex-start',
|
justifyContent: 'flex-start',
|
||||||
background: 'url(https://source.unsplash.com/random/1600x900?music)',
|
background: `url(${config.loginBackgroundURL})`,
|
||||||
backgroundRepeat: 'no-repeat',
|
backgroundRepeat: 'no-repeat',
|
||||||
backgroundSize: 'cover',
|
backgroundSize: 'cover',
|
||||||
backgroundPosition: 'center'
|
backgroundPosition: 'center'
|
||||||
@@ -253,7 +254,7 @@ const Login = ({ location }) => {
|
|||||||
return errors
|
return errors
|
||||||
}
|
}
|
||||||
|
|
||||||
if (localStorage.getItem('initialAccountCreation') === 'true') {
|
if (config.firstTime) {
|
||||||
return (
|
return (
|
||||||
<FormSignUp
|
<FormSignUp
|
||||||
handleSubmit={handleSubmit}
|
handleSubmit={handleSubmit}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
import config from '../config'
|
||||||
|
|
||||||
const baseUrl = (path) => {
|
const baseUrl = (path) => {
|
||||||
const base = localStorage.getItem('baseURL') || ''
|
const base = config.baseURL || ''
|
||||||
const parts = [base]
|
const parts = [base]
|
||||||
parts.push(path.replace(/^\//, ''))
|
parts.push(path.replace(/^\//, ''))
|
||||||
return parts.join('/')
|
return parts.join('/')
|
||||||
|
|||||||
Reference in New Issue
Block a user