Commit 285f7b07 authored by Andreas Åkre Solberg's avatar Andreas Åkre Solberg

Update to fix redux-action and update hostname

parent d0f83aa1
import { createAction, createActions, handleActions, combineActions } from 'redux-actions' import { createAction, createActions, handleActions, combineActions } from 'redux-actions'
import promiseMiddleware from 'redux-promise'; import promiseMiddleware from 'redux-promise';
export const setHostname = createAction('setHostname') export const discoveryStart = createAction('discoveryStart')
import React from 'react' import React from 'react'
import {Navbar, Nav, NavItem} from 'react-bootstrap'; import {Navbar, Nav, NavItem} from 'react-bootstrap';
import Link from 'redux-first-router-link';
import BreadCrumb from './BreadCrumb' // import BreadCrumb from './BreadCrumb'
import LoginController from '../containers/LoginController'; // import LoginController from '../containers/LoginController';
const uninettLogo = require('../../node_modules/uninett-bootstrap-theme/images/UNINETT_logo.svg') const uninettLogo = require('../../node_modules/uninett-bootstrap-theme/images/UNINETT_logo.svg')
var FontAwesome = require('react-fontawesome') var FontAwesome = require('react-fontawesome')
...@@ -13,18 +12,18 @@ const navStyle = { ...@@ -13,18 +12,18 @@ const navStyle = {
marginTop: "17px" marginTop: "17px"
} }
const checkActive = (currentLocation, check) => { // const checkActive = (currentLocation, check) => {
if (currentLocation === check ) { // if (currentLocation === check ) {
return "active" // return "active"
} // }
return "" // return ""
} // }
const Header = ({locationType, locationPayload}) => ( const Header = ({}) => (
<Navbar > <Navbar >
<Navbar.Header> <Navbar.Header>
<Navbar.Brand> <Navbar.Brand>
<Link to="/"><img alt="UNINETT Logo" src={uninettLogo} /></Link> <img alt="UNINETT Logo" src={uninettLogo} />
</Navbar.Brand> </Navbar.Brand>
</Navbar.Header> </Navbar.Header>
<ul style={navStyle} className="nav nav-pills"> <ul style={navStyle} className="nav nav-pills">
......
import React from 'react' import React, { PureComponent } from 'react'
import {Navbar, Nav, NavItem, NavDropdown, MenuItem, Glyphicon, Jumbotron, Button} from 'react-bootstrap' import {Navbar, Nav, NavItem, NavDropdown, MenuItem, Glyphicon, Jumbotron, Button} from 'react-bootstrap'
import {Row, Col, Collapse, FormControl, FormGroup, ControlLabel, HelpBlock} from 'react-bootstrap' import {Row, Col, Collapse, FormControl, FormGroup, ControlLabel, HelpBlock} from 'react-bootstrap'
import FontAwesome from 'react-fontawesome' import FontAwesome from 'react-fontawesome'
const foo = () => { const foo = () => {
console.log("AYA") console.log("AYA")
} }
const defaultHost = "https://auth.dataporten.no/" const defaultHost = "https://auth.dataporten.no/"
class Component extends PureComponent {
constructor(props) {
super(props)
this.state = {
hostname: defaultHost
}
}
discoveryStart(e) {
console.log("Setting hostname")
this.props.discoveryStart(this.state.hostname)
}
const Component = ({text="Loading..."}) => ( updateHostfield(e) {
<div> console.log("Updating hostname to ", e.target.value)
<FormGroup this.setState({hostname: e.target.value})
className="gutter" }
controlId="formBasicText"
> render() {
<h4>OAuth Server hostname</h4> return (
<FormControl <div>
type="text" <FormGroup
bsSize="large" className="gutter"
value={defaultHost} controlId="formBasicText"
placeholder="https://auth.yourplatform.org/" >
<h4>OAuth Server hostname</h4>
/> <FormControl
<HelpBlock>Fill out the hostname of your OAuth server. Will only work if your OAuth server support OAuth Discovery. If not, please enter configuration manually.</HelpBlock> type="text"
</FormGroup> bsSize="large"
defaultValue={defaultHost}
<div><Button onCLick={foo} bsStyle="primary"><Glyphicon glyph="book" /> Discovery OAuth Provider</Button></div> placeholder="https://auth.yourplatform.org/"
</div> onChange={this.updateHostfield.bind(this)}
) />
<HelpBlock>Fill out the hostname of your OAuth server. Will only work if your OAuth server support OAuth Discovery. If not, please enter configuration manually.</HelpBlock>
</FormGroup>
<div><Button onClick={this.discoveryStart.bind(this)} bsStyle="primary"><Glyphicon glyph="book" /> Discovery OAuth Provider</Button></div>
</div>
)
}
}
export default Component export default Component
import React from 'react' import React from 'react'
import {Navbar, Nav, NavItem, NavDropdown, MenuItem, Glyphicon, Jumbotron, Button} from 'react-bootstrap' import {Navbar, Nav, NavItem, NavDropdown, MenuItem, Glyphicon, Jumbotron, Button} from 'react-bootstrap'
import {Row, Col, Collapse, FormControl, FormGroup, ControlLabel, HelpBlock} from 'react-bootstrap' import {Row, Col, Collapse, FormControl, FormGroup, ControlLabel, HelpBlock} from 'react-bootstrap'
import Link from 'redux-first-router-link';
import HostnameInput from './HostnameInput' import HostnameController from '../containers/HostnameController'
const MainContent = () => ( const MainContent = () => (
<div> <div>
...@@ -13,12 +12,12 @@ const MainContent = () => ( ...@@ -13,12 +12,12 @@ const MainContent = () => (
<p>Learn more about how OAuth 2.0 works, and explore OAuth protected APIs without entering any code.</p> <p>Learn more about how OAuth 2.0 works, and explore OAuth protected APIs without entering any code.</p>
<HostnameInput /> <HostnameController />
<p>Navigate the library of prepared applications, deploy and start using it within few minutes. This application platform is fully automated.</p> <p>Navigate the library of prepared applications, deploy and start using it within few minutes. This application platform is fully automated.</p>
<p> <p>
<Link to="/"><Button bsStyle="primary"><Glyphicon glyph="book" /> Library</Button></Link>&nbsp; <Button bsStyle="primary"><Glyphicon glyph="book" /> Library</Button>
<Link to="/applications"><Button bsStyle="success"><Glyphicon glyph="modal-window" /> My installed applications</Button></Link> <Button bsStyle="success"><Glyphicon glyph="modal-window" /> My installed applications</Button>
</p> </p>
</Jumbotron> </Jumbotron>
......
import React from 'react' import React from 'react'
import { connect } from 'react-redux'
import Footer from '../components/Footer' import Footer from '../components/Footer'
import MainContent from '../components/MainContent' import MainContent from '../components/MainContent'
import Header from '../components/Header' import Header from '../components/Header'
import { connect } from 'react-redux' const App = ({}) => (
const mainContent = {
HOME: <MainContent />,
}
const App = ({locationType, locationPayload}) => (
<div> <div>
<Header locationType={locationType} locationPayload={locationPayload} /> <Header />
{ mainContent[locationType] } <MainContent />
<Footer /> <Footer />
</div> </div>
) )
const mapStateToProps = (state) => ({ const mapStateToProps = (state) => ({
locationType: state.location.type,
locationPayload: state.location.payload
}) })
const mapDispatchToProps = { const mapDispatchToProps = {
......
import { connect } from 'react-redux' import { connect } from 'react-redux'
import HostnameInput from '../components/HostnameInput' import HostnameInput from '../components/HostnameInput'
import { setHostname } from '../actions/' import { discoveryStart } from '../actions/'
const mapStateToProps = (state, ownProps) => (state) const mapStateToProps = (state, ownProps) => (state)
const mapDispatchToProps = { const mapDispatchToProps = {
setHostname discoveryStart
} }
const Controller = connect( const Controller = connect(
......
...@@ -5,14 +5,14 @@ import ReactDOM from 'react-dom' ...@@ -5,14 +5,14 @@ import ReactDOM from 'react-dom'
import { combineReducers, createStore, applyMiddleware, compose } from 'redux' import { combineReducers, createStore, applyMiddleware, compose } from 'redux'
import { Provider } from 'react-redux' import { Provider } from 'react-redux'
import thunkMiddleware from 'redux-thunk' import thunkMiddleware from 'redux-thunk'
import { connectRoutes } from 'redux-first-router' // import { connectRoutes } from 'redux-first-router'
import createHistory from 'history/createBrowserHistory' // import createHistory from 'history/createBrowserHistory'
import reducers from './reducers/' import reducers from './reducers/'
import App from './containers/App' import App from './containers/App'
import logger from './middleware/logger' import logger from './middleware/logger'
import { routesMap, options } from './routesMap' // import { routesMap, options } from './routesMap'
// import { appJso, getUserInfo } from './actions/auth' // import { appJso, getUserInfo } from './actions/auth'
import '../node_modules/bootstrap/dist/css/bootstrap.min.css' import '../node_modules/bootstrap/dist/css/bootstrap.min.css'
...@@ -21,19 +21,17 @@ import './css/style.css' ...@@ -21,19 +21,17 @@ import './css/style.css'
// import {packageInstallStart, packageInstallFailed} from './actions/packages' // import {packageInstallStart, packageInstallFailed} from './actions/packages'
const history = createHistory() // const history = createHistory()
// const routerSetup = connectRoutes(history, routesMap, options)
const routerSetup = connectRoutes(history, routesMap, options)
let store = createStore( let store = createStore(
combineReducers({ reducers,
...reducers,
location: routerSetup.reducer
}),
compose( compose(
routerSetup.enhancer, // routerSetup.enhancer,
applyMiddleware( applyMiddleware(
routerSetup.middleware, // routerSetup.middleware,
thunkMiddleware, thunkMiddleware,
logger logger
) )
......
import auth from './auth' import { handleActions } from 'redux-actions';
import packages from './packages'
import applications from './applications'
import installation from './installation' const reducer = handleActions({
import namespaces from './namespaces' discoveryStart: (state, action) => ({
hostname: action.payload
export default { }),
auth,
applications, DECREMENT: (state, action) => ({
packages, counter: state.counter - action.payload
installation, })
namespaces },
} {
hostname: "https://auth.dataporten"
});
export default reducer
import { getAllPackages, getPackage } from './actions/packages' // import { getAllPackages, getPackage } from './actions/packages'
import { prepareApplication, getAllApplications } from './actions/applications' // import { prepareApplication, getAllApplications } from './actions/applications'
import { login, isAuthenticated, loginAndRedirect } from './actions/auth' // import { login, isAuthenticated, loginAndRedirect } from './actions/auth'
const routesMap = { const routesMap = {
HOME: '/', HOME: '/',
...@@ -19,11 +19,11 @@ const options = { ...@@ -19,11 +19,11 @@ const options = {
} }
const requiresAuth = routesMap[action.type].requiresAuth const requiresAuth = routesMap[action.type].requiresAuth
window.scrollTo(0, 0) window.scrollTo(0, 0)
if (requiresAuth) { // if (requiresAuth) {
if (!isAuthenticated(getState())) { // if (!isAuthenticated(getState())) {
dispatch(loginAndRedirect(action)) // dispatch(loginAndRedirect(action))
} // }
} // }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment